diff --git a/swarms/structs/agent.py b/swarms/structs/agent.py index 54642f3b..1dc5d876 100644 --- a/swarms/structs/agent.py +++ b/swarms/structs/agent.py @@ -1188,9 +1188,15 @@ class Agent: f"[Structured Output] [Time: {time.strftime('%H:%M:%S')}] \n\n {json.dumps(response, indent=4)}", loop_count, ) - elif self.streaming_on: - pass - else: + elif self.streaming_on and isinstance(response, dict) and response.get("choices"): + # Handle streaming tool calls structured output + tool_calls = response.get("choices", [{}])[0].get("message", {}).get("tool_calls", []) + if tool_calls: + self.pretty_print( + f"[Structured Output] [Time: {time.strftime('%H:%M:%S')}] \n\n {json.dumps(tool_calls, indent=4)}", + loop_count, + ) + elif not self.streaming_on: self.pretty_print( response, loop_count ) diff --git a/swarms/tools/base_tool.py b/swarms/tools/base_tool.py index d5d34779..cd0fae38 100644 --- a/swarms/tools/base_tool.py +++ b/swarms/tools/base_tool.py @@ -3109,6 +3109,7 @@ class BaseTool(BaseModel): "id": tc.get("id") }) + return {"choices": [{"message": {"tool_calls": formatted_calls}}]} if formatted_calls else text_response return text_response