Introduction
CrewAI provides the ability to stream real-time output during crew execution, allowing you to display results as they’re generated rather than waiting for the entire process to complete. This feature is particularly useful for building interactive applications, providing user feedback, and monitoring long-running processes.How Streaming Works
When streaming is enabled, CrewAI captures LLM responses and tool calls as they happen, packaging them into structured chunks that include context about which task and agent is executing. You can iterate over these chunks in real-time and access the final result once execution completes.Enabling Streaming
To enable streaming, set thestream parameter to True when creating your crew:
Code
Synchronous Streaming
When you callkickoff() on a crew with streaming enabled, it returns a CrewStreamingOutput object that you can iterate over to receive chunks as they arrive:
Code
Stream Chunk Information
Each chunk provides rich context about the execution:Code
Accessing Streaming Results
TheCrewStreamingOutput object provides several useful properties:
Code
Asynchronous Streaming
For async applications, usekickoff_async() with async iteration:
Code
Streaming with kickoff_for_each
When executing a crew for multiple inputs withkickoff_for_each(), streaming works differently depending on whether you use sync or async:
Synchronous kickoff_for_each
With synchronouskickoff_for_each(), you get a list of CrewStreamingOutput objects, one for each input:
Code
Asynchronous kickoff_for_each_async
With asynckickoff_for_each_async(), you get a single CrewStreamingOutput that yields chunks from all crews as they arrive concurrently:
Code
Stream Chunk Types
Chunks can be of different types, indicated by thechunk_type field:
TEXT Chunks
Standard text content from LLM responses:Code
TOOL_CALL Chunks
Information about tool calls being made:Code
Practical Example: Building a UI with Streaming
Here’s a complete example showing how to build an interactive application with streaming:Code
Use Cases
Streaming is particularly valuable for:- Interactive Applications: Provide real-time feedback to users as agents work
- Long-Running Tasks: Show progress for research, analysis, or content generation
- Debugging and Monitoring: Observe agent behavior and decision-making in real-time
- User Experience: Reduce perceived latency by showing incremental results
- Live Dashboards: Build monitoring interfaces that display crew execution status
Important Notes
- Streaming automatically enables LLM streaming for all agents in the crew
- You must iterate through all chunks before accessing the
.resultproperty - For
kickoff_for_each_async()with streaming, use.results(plural) to get all outputs - Streaming adds minimal overhead and can actually improve perceived performance
- Each chunk includes full context (task, agent, chunk type) for rich UIs
Error Handling
Handle errors during streaming execution:Code
