Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/agents/models/chatcmpl_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand All @@ -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,
},
}
14 changes: 12 additions & 2 deletions tests/test_tool_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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

Expand Down