Trying to use a complex BaseModel as a tool argument with GPT 5:
import asyncio
from pydantic import BaseModel, Field
from aviary.core import Environment, Message, Tool, ToolSelector
class ComplexArg(BaseModel):
arg: int = Field(description="Some integer argument.")
def some_tool(arg: ComplexArg) -> None:
"""Do something.
Args:
arg: Some complex argument.
"""
async def main() -> None:
selector = ToolSelector("gpt-5-mini-2025-08-07")
tool_request_message = await selector(
messages=[Message(content="Will this work?")],
tools=[Tool.from_function(some_tool)],
)
(tool_call,) = tool_request_message.tool_calls
assert isinstance(tool_call.function.arguments, dict)
assert isinstance(tool_call.function.arguments.get("arg"), ComplexArg)
if __name__ == "__main__":
asyncio.run(main())
It won't work as of fhaviary==0.24.3 because:
- GPT 5 will propose the tool request's arguments as a
str
ToolCallFunction deserializes the arguments to dict here
Environment.exec_tool_calls doesn't auto-cast to the BaseModel
We should either:
- Find a way to store the desired
BaseModel in the ToolRequestMessage (perhaps in the info field)
- Deserialize per the tool's JSON schema in
Environment.exec_tool_calls
Trying to use a complex
BaseModelas a tool argument with GPT 5:It won't work as of
fhaviary==0.24.3because:strToolCallFunctiondeserializes the arguments todicthereEnvironment.exec_tool_callsdoesn't auto-cast to theBaseModelWe should either:
BaseModelin theToolRequestMessage(perhaps in theinfofield)Environment.exec_tool_calls