Skip to main content

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 the stream parameter to True when creating your crew:
Code

Synchronous Streaming

When you call kickoff() 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

The CrewStreamingOutput object provides several useful properties:
Code

Asynchronous Streaming

For async applications, you can use either akickoff() (native async) or kickoff_async() (thread-based) with async iteration:

Native Async with akickoff()

The akickoff() method provides true native async execution throughout the entire chain:
Code

Thread-Based Async with kickoff_async()

For simpler async integration or backward compatibility:
Code
For high-concurrency workloads, akickoff() is recommended as it uses native async for task execution, memory operations, and knowledge retrieval. See the Kickoff Crew Asynchronously guide for more details.

Streaming with kickoff_for_each

When executing a crew for multiple inputs with kickoff_for_each(), streaming works differently depending on whether you use sync or async:

Synchronous kickoff_for_each

With synchronous kickoff_for_each(), you get a list of CrewStreamingOutput objects, one for each input:
Code

Asynchronous kickoff_for_each_async

With async kickoff_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 the chunk_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

Cancellation and Resource Cleanup

CrewStreamingOutput supports graceful cancellation so that in-flight work stops promptly when the consumer disconnects.

Async Context Manager

Code

Explicit Cancellation

Code
After cancellation, streaming.is_cancelled and streaming.is_completed are both True. Both aclose() and close() are idempotent.

Important Notes

  • Streaming automatically enables LLM streaming for all agents in the crew
  • You must iterate through all chunks before accessing the .result property
  • 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
By leveraging streaming, you can build more responsive and interactive applications with CrewAI, providing users with real-time visibility into agent execution and results.