Skip to content

Commit 6b48d20

Browse files
authored
Tool name whitespace bugfix (#9557)
1 parent 08851e6 commit 6b48d20

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎python/packages/core/agent_framework/_harness/_tool_approval.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,9 @@ def __init__(
130130
server_label: Optional hosted-tool server boundary. Hosted approvals
131131
only match future approvals from the same server label.
132132
"""
133-
normalized_name = tool_name.strip()
134-
if not normalized_name:
133+
if not tool_name.strip():
135134
raise ValueError("Tool approval rule tool_name must be a non-empty string.")
136-
self.tool_name = normalized_name
135+
self.tool_name = tool_name
137136
self.arguments = dict(arguments) if arguments is not None else None
138137
self.server_label = server_label
139138

‎python/packages/core/tests/core/test_harness_tool_approval.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
SessionContext,
3838
SupportsAgentRun,
3939
ToolApprovalMiddleware,
40+
ToolApprovalRule,
4041
ToolApprovalState,
4142
create_always_approve_tool_response,
4243
create_always_approve_tool_with_arguments_response,
@@ -66,6 +67,14 @@ def _function_call(request: Content) -> Content:
6667
return request.function_call
6768

6869

70+
def test_tool_approval_rule_preserves_tool_name_whitespace() -> None:
71+
"""Tool approval rules must preserve the exact approved tool identity."""
72+
rule = ToolApprovalRule("run_shell ")
73+
74+
assert rule.tool_name == "run_shell "
75+
assert ToolApprovalRule.from_dict(rule.to_dict()).tool_name == "run_shell "
76+
77+
6978
class _MarkUntrusted(FunctionMiddleware):
7079
async def process(
7180
self,

0 commit comments

Comments
 (0)