Fix. #936 #937 enhance tool-call and streaming behavior in Agent class - #938
Fix. #936 #937 enhance tool-call and streaming behavior in Agent class#938harshalmore31 wants to merge 41 commits into
Conversation
…k reference management; enhance logging for API response parsing in base tool
… conversation history; add callback for real-time chunk logging
… for improved readability
…ck for concurrent Live panel management and improve error handling
…ssary streaming coordination flags
…rt for partial JSON and tool call detection
| ) | ||
| 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
|
@harshalmore31 add some tests here and some documentation, and also send a video please |
| elif self.streaming_on: | ||
| pass |
There was a problem hiding this comment.
Fixed this, now we are parsing the streaming with tools in realtime !
| print(token, end=" ", flush=True) | ||
| time.sleep(delay) | ||
| print() # Ensure a newline after streaming | ||
| # Use centralized string streaming from wrapper |
There was a problem hiding this comment.
created an centralized streaming wrapper !
| del kwargs["is_last"] | ||
|
|
||
| try: | ||
| # Set streaming parameter in LLM if streaming is enabled |
There was a problem hiding this comment.
No need of managing streaming in the agent.py, we are now handling the streaming in litellm_wrapper.py itself
|
@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 |
|
@kyegomez the PR is ready, updated the docs and included and streaming_with_tools.py example ! |
| 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
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
examples/streaming_with_tools.py) and detailed documentation indocs/examples/agent_stream.mddemonstrating how to use streaming with tool execution, including best practices and key features. [1] [2]Agent Streaming Logic Enhancements
_run,call_llm,mcp_tool_handling, andexecute_toolsmethods 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
handle_streaming_with_toolsto theBaseToolclass, 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
litellm_wrapperutility to support new streaming workflows and callbacks, improving flexibility for downstream streaming integrations. [1] [2]Minor Improvements
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.