Skip to content

Fix. #936 #937 enhance tool-call and streaming behavior in Agent class - #938

Open
harshalmore31 wants to merge 41 commits into
kyegomez:masterfrom
harshalmore31:Fix/stream-issues
Open

Fix. #936 #937 enhance tool-call and streaming behavior in Agent class#938
harshalmore31 wants to merge 41 commits into
kyegomez:masterfrom
harshalmore31:Fix/stream-issues

Conversation

@harshalmore31

@harshalmore31 harshalmore31 commented Jul 4, 2025

Copy link
Copy Markdown
Contributor

This pull request introduces comprehensive support for real-time streaming of agent reasoning and tool execution results, both in the codebase and documentation. The changes enable agents to provide immediate feedback during tool calls, improve usability for streaming workflows, and centralize streaming logic for easier maintenance and extensibility.

Streaming with Tools Support

  • Added a new example (examples/streaming_with_tools.py) and detailed documentation in docs/examples/agent_stream.md demonstrating how to use streaming with tool execution, including best practices and key features. [1] [2]

Agent Streaming Logic Enhancements

  • Refactored the agent's _run, call_llm, mcp_tool_handling, and execute_tools methods to centralize and streamline logic for handling streaming responses with tools, including proper memory management and pretty-printing of streamed tool outputs. [1] [2] [3] [4] [5] [6] [7]

Tool Streaming Integration

  • Added handle_streaming_with_tools to the BaseTool class, allowing unified handling and formatting of streaming tool outputs and tool call parsing, with robust error handling and support for both advanced and fallback streaming.

Streaming Utilities and Wrapper Improvements

  • Updated the litellm_wrapper utility to support new streaming workflows and callbacks, improving flexibility for downstream streaming integrations. [1] [2]

Minor Improvements

  • Minor logging improvements and bug fixes for better debugging and error visibility during streaming operations.

These changes make it much easier to build interactive, tool-using agents that provide real-time feedback to users, and set the foundation for richer streaming and debugging experiences.

…k reference management; enhance logging for API response parsing in base tool
@github-actions github-actions Bot added the tools label Jul 4, 2025
… conversation history; add callback for real-time chunk logging
…ck for concurrent Live panel management and improve error handling
@github-actions github-actions Bot added the utils label Jul 4, 2025
@harshalmore31 harshalmore31 changed the title Fix. #936 enhance tool-call and streaming behavior in Agent class Fix. #936 #937 enhance tool-call and streaming behavior in Agent class Jul 5, 2025
@harshalmore31
harshalmore31 marked this pull request as ready for review July 5, 2025 03:25
Comment thread swarms/structs/agent.py Fixed
Comment thread swarms/structs/agent.py Fixed
Comment thread swarms/structs/agent.py Fixed
Comment thread swarms/structs/agent.py Fixed
Comment thread swarms/structs/agent.py Fixed
Comment thread swarms/structs/agent.py Fixed
Comment thread swarms/structs/agent.py Fixed
Comment thread swarms/utils/litellm_wrapper.py Fixed
Comment thread swarms/utils/litellm_wrapper.py Fixed
Comment thread swarms/utils/litellm_wrapper.py Fixed
Comment thread swarms/tools/base_tool.py
)
from swarms.tools.tool_parse_exec import parse_and_execute_json
from swarms.utils.loguru_logger import initialize_logger
from loguru import logger as loguru_logger

Check failure

Code scanning / Pyre

Undefined import Error

Undefined import [21]: Could not find a module corresponding to import loguru.
@kyegomez

Copy link
Copy Markdown
Owner

@harshalmore31 add some tests here and some documentation,

and also send a video please

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Aug 15, 2025
Comment thread swarms/structs/agent.py
Comment on lines -1187 to -1201
elif self.streaming_on:
pass

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this, now we are parsing the streaming with tools in realtime !

Comment thread swarms/structs/agent.py
print(token, end=" ", flush=True)
time.sleep(delay)
print() # Ensure a newline after streaming
# Use centralized string streaming from wrapper

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created an centralized streaming wrapper !

Comment thread swarms/structs/agent.py
del kwargs["is_last"]

try:
# Set streaming parameter in LLM if streaming is enabled

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need of managing streaming in the agent.py, we are now handling the streaming in litellm_wrapper.py itself

@harshalmore31

Copy link
Copy Markdown
Contributor Author

@kyegomez here is link to the video of comprehensive test of streaming across various agents and multi-agent tests :

https://drive.google.com/file/d/1yOzrpSLmaekihfqx37dj1s-TnLQihAR3/view?usp=sharing

@harshalmore31

Copy link
Copy Markdown
Contributor Author

@kyegomez the PR is ready, updated the docs and included and streaming_with_tools.py example !

Comment thread swarms/structs/agent.py
f"[Structured Output] [Time: {time.strftime('%H:%M:%S')}] \n\n {json.dumps(tool_calls, indent=4)}",
loop_count,
)
elif not self.streaming_on:

Check failure

Code scanning / Pyre

Undefined attribute Error

Undefined attribute [16]: str has no attribute model_dump.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation structs tools utils

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [Agent Tool Usage No Work with Streaming Enabled] [BUG] [ConcurrentWorkflow does not work with streaming

3 participants