Skip to main content

Overview

CrewAI exposes a frame-based streaming contract for runtimes that need more than plain text chunks. The contract emits ordered StreamFrame objects for Flow lifecycle events, direct LLM tokens, tool activity, conversation messages, and custom events. Use this API when you are building a UI, service bridge, terminal app, or deployment runtime that needs a stable stream of structured events while a Flow, chat turn, or direct LLM call is running.

StreamFrame

Every frame has the same envelope:
The channel field is the fastest way to route frames in consumers: frame.type preserves the source event type, so consumers can handle specific events inside a channel.

Stream a Flow

Set stream=True on a Flow to make kickoff() return a stream session:
You must consume the stream before reading stream.result. Accessing the result early raises a RuntimeError so consumers do not accidentally treat a partial run as complete. You can also call flow.stream_events(...) directly when you want streaming for a single invocation without setting stream=True on the Flow instance.

Filter by Channel

StreamSession exposes channel projections that preserve global frame order within the selected channel:
Available projections are: Use stream.interleave(["flow", "llm", "messages"]) when a consumer wants only some channels but still needs their relative order.

Async Streaming

Use astream() for async consumers:
The async session has the same projections as the sync session.

Stream a Direct LLM Call

llm.call(...) still returns the final assembled result. Use llm.stream_events(...) when you want to iterate over chunks as they arrive while keeping the structured event payload:
llm.stream_events(...) temporarily enables streaming for the wrapped call and restores the LLM’s previous stream setting afterward. Provider integrations continue to emit the underlying LLM stream events; this helper provides a common iterator API over those events for every LLM provider.

Conversational Turns

Conversational Flows can stream one user turn with stream_turn():
During stream_turn(), the built-in conversational answer path enables LLM token streaming for that turn and restores the LLM’s previous stream setting afterward. Custom route handlers that create their own agents or LLM instances should configure those LLMs for streaming if they need token-level output.

Cleanup

Use the session as a context manager when possible. If a client disconnects before the stream is exhausted, close the session explicitly:
For async streams, use await stream.aclose().

Legacy Chunk Streaming

Crew streaming with stream=True still returns the chunk-oriented CrewStreamingOutput API described in Streaming Crew Execution. Direct llm.call(...) still returns the final LLM result. The frame contract is intended for runtimes that need a stable event envelope across Flows, direct LLM calls, conversational turns, tools, and messages.