From 8568feb6042b939c07d9ff4090b6c2304f00c425 Mon Sep 17 00:00:00 2001 From: Kazuhiro Sera Date: Mon, 15 Dec 2025 17:22:40 +0900 Subject: [PATCH] fix #2181 FunctionTool.strict_json_schema is missing when using Chat Completions API --- src/agents/models/chatcmpl_converter.py | 2 ++ tests/test_tool_converter.py | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/agents/models/chatcmpl_converter.py b/src/agents/models/chatcmpl_converter.py index bc0304be0..abdfa3047 100644 --- a/src/agents/models/chatcmpl_converter.py +++ b/src/agents/models/chatcmpl_converter.py @@ -598,6 +598,7 @@ def tool_to_openai(cls, tool: Tool) -> ChatCompletionToolParam: "name": tool.name, "description": tool.description or "", "parameters": tool.params_json_schema, + "strict": tool.strict_json_schema, }, } @@ -614,5 +615,6 @@ def convert_handoff_tool(cls, handoff: Handoff[Any, Any]) -> ChatCompletionToolP "name": handoff.tool_name, "description": handoff.tool_description, "parameters": handoff.input_json_schema, + "strict": handoff.strict_json_schema, }, } diff --git a/tests/test_tool_converter.py b/tests/test_tool_converter.py index 918de0153..6e76a13ba 100644 --- a/tests/test_tool_converter.py +++ b/tests/test_tool_converter.py @@ -18,14 +18,23 @@ def test_to_openai_with_function_tool(): result = Converter.tool_to_openai(tool) assert result["type"] == "function" - assert result["function"]["name"] == "some_function" - params = result.get("function", {}).get("parameters") + function_def = result["function"] + assert function_def["name"] == "some_function" + assert function_def["strict"] is True + params = function_def.get("parameters") assert params is not None properties = params.get("properties", {}) assert isinstance(properties, dict) assert properties.keys() == {"a", "b"} +def test_to_openai_respects_non_strict_function_tool(): + tool = function_tool(some_function, strict_mode=False) + result = Converter.tool_to_openai(tool) + + assert result["function"]["strict"] is False + + class Foo(BaseModel): a: str b: list[int] @@ -39,6 +48,7 @@ def test_convert_handoff_tool(): assert result["type"] == "function" assert result["function"]["name"] == Handoff.default_tool_name(agent) assert result["function"].get("description") == Handoff.default_tool_description(agent) + assert result["function"].get("strict") is True params = result.get("function", {}).get("parameters") assert params is not None