return_direct=True
-- that tool would have to have a tool name+description that signals to the LLM it should invoke this to return a final response (probably also need a system prompt to help here)answer
and justifcation
field:def finalize_response(answer: str, justification: str) -> str: """Used to finalize a response to the user. Should be called last once you have any kind of answer for the user.""" return {"answer": answer, "justification": justification} final_tool = FunctionTool.from_defaults(fn=finalize_response, return_direct=True) agent = FunctionCallingAgent.from_tools([..., final_tool], system_prompt="Always use the finalize_response tool, and always use it last.")
resp = agent.chat(...) try: structured_resp = json.loads(str(resp)) except: structured_resp = {"answer": str(resp), "justification": None}