Closed as duplicate of#117
Description
Please read this first
- Have you read the docs?Agents SDK docs - Yes
- Have you searched for related issues? Others may have had similar requests - Yes
Describe the feature
Unless I've missed something, any agent tool output from final_output or new_item is forced to a string. I have a use case where it would be nice to be able to directly return an object from a function tool. For example, I am using Tavily search as a tool, which returns a dict, which I am converting to a Pydantic model. I know this can be done using an Agent as a tool and setting the output_type, but I'd prefer to just use the tool itself, if possible.
My workaround is as follows:
if new_item.type == 'tool_call_output_item':
tav_json = eval(new_item.output)
tav_response = PydanticModel.model_validate(tav_json)
But it would be nice to be able to convert the output directly in the function tool and return that:
@function_tool
def tav_search(query: str):
"""Search the web for information.
Args:
query: The user's query.
"""
search_response = TavilyClient.search(
query=query,
max_results=3,
include_answer="advanced",
)
result = PydanticModel.model_validate(search_response)
return result
Or possibly even set an output_type on the function tool itself.