The community member is discussing how to get an agent to return a structured output. They suggest using FunctionTool.from_defaults(fn={fn}, return_direct=True), but note that the output needs to be a string to avoid issues with the AgentChatResponse output class. Another approach mentioned is to use a Pydantic base model, store the key-value pairs in a dictionary, JSON dump the dictionary, and add postprocessing code to handle the return. The community member also suggests writing a custom agent using Workflow as an alternative approach.
In the comments, another community member agrees with the summary and states that they would personally take the Workflow approach, as it provides more control and allows for better debugging compared to the pre-built agents.
For now I think only LLMs can return structured outputs. If I wanted to get an agent to return a structured output, my only way of doing so would be to use tool = FunctionTool.from_defaults(fn={fn}, return_direct=True) right?
Except that I need to be mindful to ensure that my tool output is a string so that I won't mess up the AgentChatResponse output class. So if I specify a pydantic base model as my desired return, I would have to store the key value pairs of the response model as a dictionary then json dumps that dictionary as my return, and then add postprocessing code to handle the return.
Of course the other way would be to write a custom agent using Workflow and handle the ToolOutput there.
Personally I would take the workflow approach. There is always going to be more that you want control over or need to debug, and the prebuilt agents are little too black box imo