Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/agents/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,9 @@ def __post_init__(self):
if callable(bind_to_function_tool):
self.on_invoke_tool = bind_to_function_tool(self)
if self.strict_json_schema:
self.params_json_schema = ensure_strict_json_schema(self.params_json_schema)
self.params_json_schema = ensure_strict_json_schema(
copy.deepcopy(self.params_json_schema)
)
_validate_function_tool_timeout_config(self)

def __copy__(self) -> FunctionTool:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_function_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,27 @@ def echo(value: str) -> str:
)


def test_function_tool_does_not_mutate_params_json_schema() -> None:
async def noop(ctx: ToolContext[Any], input: str) -> str:
return ""

schema = {"type": "object", "properties": {"x": {"type": "string"}}}
schema_snapshot = copy.deepcopy(schema)

tool = FunctionTool(
name="t",
description="d",
params_json_schema=schema,
on_invoke_tool=noop,
strict_json_schema=True,
)

assert schema == schema_snapshot
assert tool.params_json_schema is not schema
assert tool.params_json_schema["additionalProperties"] is False
assert tool.params_json_schema["required"] == ["x"]


@pytest.mark.asyncio
async def test_default_failure_error_function_survives_deepcopy() -> None:
def boom() -> None:
Expand Down
Loading