-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
Milestone
Description
Please read this first
- Have you read the docs?Agents SDK docs → yes
- Have you searched for related issues? Others may have faced similar issues. → yes
Describe the bug
FunctionTool.strict_json_schema is not passed to the ChatCompletion API, because it is not converted in chatcmpl_converter.py::Converter.tool_to_openai()
@classmethod
def tool_to_openai(cls, tool: Tool) -> ChatCompletionToolParam:
if isinstance(tool, FunctionTool):
return {
"type": "function",
"function": {
"name": tool.name,
"description": tool.description or "",
"parameters": tool.params_json_schema,
},
}
raise UserError(
f"Hosted tools are not supported with the ChatCompletions API. Got tool type: "
f"{type(tool)}, tool: {tool}"
)Due to this, the tool JSON schema returned by the API does not consistently follow the format specified in the request.
Debug information
- Agents SDK version: v0.6.3
- Python version: Python 3.12
Repro steps
import json
from agents import function_tool
from agents.models.chatcmpl_converter import Converter
@function_tool(strict_mode=True)
def dummy_tool(x: int) -> int:
"""Return x unchanged for testing strict_mode propagation."""
return x
# Convert the tool as the OpenAIChatCompletionsModel does
openai_tool = Converter.tool_to_openai(dummy_tool)
print("Tool as sent to ChatCompletion (from OpenAIChatCompletionsModel):")
print(json.dumps(openai_tool, indent=2))Expected behavior
Since strict_mode=True is set on dummy_tool, the printed function schema should include:
"strict": trueActual behavior
{
"type": "function",
"function": {
"name": "dummy_tool",
"description": "Return x unchanged for testing strict_mode propagation.",
"parameters": {
"properties": {
"x": {
"title": "X",
"type": "integer"
}
},
"required": [
"x"
],
"title": "dummy_tool_args",
"type": "object",
"additionalProperties": false
}
}
}Suggested Fix
Add "strict": tool.strict_json_schema to the function object, similar to how it is handled in openai_responses.py
I’m happy to open a PR with this change. Just filing the issue first to avoid duplicate work.