@ -283,78 +283,70 @@ The `run` method now includes enhanced logging to track the sequential awareness
The SequentialWorkflow with sequential awareness represents a significant advancement in multi-agent coordination, enabling more sophisticated and professional workflows that closely mirror human team collaboration patterns.
The SequentialWorkflow now includes a powerful **streaming callback** feature that allows you to receive and process tokens in real-time as the workflow executes. This enables real-time streaming of agent responses, making it ideal for interactive applications and live monitoring of workflow progress.
### What the Streaming Callback Does
- **Real-time Token Streaming**: Receive individual tokens as they are generated by agents
- **Live Progress Monitoring**: Track workflow execution progress in real-time
- **Interactive Applications**: Enable streaming responses in chat applications or live demos
Integrates streaming callback functionality into the SequentialWorkflow for real-time token processing.
The SequentialWorkflow now includes a powerful **streaming callback** feature that allows you to receive and process tokens in real-time as the workflow executes, helping you monitor execution progress from agents and create interactive chat applications/live demos. This enables real-time streaming of agent responses, making it ideal for interactive applications and live monitoring of workflow progress.
###Parameters:
- `streaming_callback` (`Optional[Callable[[str], None]]`): A callback function that receives streaming tokens in real-time. The function should accept a single string parameter (the token) and return None. Defaults to `None`.
As each agent in the workflow generates responses, tokens are immediately passed to your callback function:
```python
# Tokens flow like this:
# Agent1: "Research" -> callback("Research")
# Agent1: " shows" -> callback(" shows")
# Agent1: " that" -> callback(" that")
# Agent2: "Analysis" -> callback("Analysis")
# ...and so on
```
### 2. **Non-Blocking Execution**
The streaming callback operates asynchronously and doesn't block the workflow execution. Your callback function receives tokens as soon as they're available.
### 3. **Memory Efficient**
Tokens are processed individually, making it memory-efficient for long-running workflows.
## **Benefits of Streaming Callback**
1. **Real-Time User Experience**: Users see responses as they're generated, improving perceived performance
2. **Live Monitoring**: Track workflow progress and agent outputs in real-time
3. **Interactive Applications**: Perfect for chat interfaces, dashboards, and live demos
4. **Debugging**: Monitor agent outputs token-by-token for debugging purposes
5. **Custom Integration**: Easily integrate with logging systems, progress bars, or custom UI components
The streaming callback feature transforms the SequentialWorkflow into a powerful tool for real-time AI applications, enabling seamless integration with modern streaming interfaces and live monitoring systems.
## **Notes:**
@ -450,41 +397,3 @@ The streaming callback feature transforms the SequentialWorkflow into a powerful
"""Stream tokens to database for real-time analytics."""
# Buffer tokens and batch insert to database
token_buffer.append(token)
if len(token_buffer) >= 100:
# Batch insert to database
db.insert_tokens(token_buffer.copy())
token_buffer.clear()
workflow = SequentialWorkflow(
agents=[agent1, agent2, agent3],
streaming_callback=database_callback
)
```
Using a streaming callback in SequentialWorkflow enables real-time visibility into agent outputs, making it ideal for interactive applications and live monitoring. This feature enhances user experience and debugging by allowing immediate feedback and seamless integration with modern interfaces.