DS DevShelfHub Projects · AI tools
Tutorials / CrewAI / Streaming · API Reference
Streaming Page 28 of 29

CrewAI Streaming: Live LLM and Flow Output for Python Apps

By DevShelfHub

Real-time output across LLM calls, Flow steps, and batch kickoffs. Continue with observability and the BaseEventListener class reference for listener wiring details.

Series progress28 / 29
CrewAI streaming tutorial — CrewAI Streaming: Live LLM and Flow Output for Python Apps

Enable Streaming on an LLM

Wire stream=True on the LLM class so token chunks emit while the completion is still in flight.

python
from crewai import LLM, Agent
llm = LLM(model="openai/gpt-4o", stream=True)
agent = Agent(role="...", goal="...", backstory="...", llm=llm)

Chunk Types

  • LLMStreamChunkEvent — partial token chunks.
  • LLMThinkingChunkEvent — extended-thinking reasoning chunks (when supported).

Forward Chunks to a UI

Subscribe a BaseEventListener and push to your transport (SSE, WebSocket).

python
class StreamRelay(BaseEventListener):
    def on_event(self, event):
        if event.__class__.__name__ == "LLMStreamChunkEvent":
            sse_send(event.chunk)

Streaming with Flows

Construct Flow with stream=True. Each method's output streams to listeners. Combine with @persist for resumable streaming sessions.

Streaming with kickoff_for_each

Async batches stream results per-item as they complete. Use kickoff_for_each() or kickoff_for_each_async() from the crew API. Tune max_rpm on the Crew to avoid 429s.

Back-pressure

UI listeners that block the event thread will stall the run. Push chunks onto a queue and drain off-thread.

Kickoff entry points for streaming crews

Listeners behave the same whether you start work with kickoff() or kickoff_async(). Async services usually pair kickoff_async with tools that implement BaseTool._arun() so httpx-style I/O does not block the thread that is draining your chunk queue.

CrewAI streaming FAQ

How do I enable streaming on a CrewAI LLM?

Construct the LLM with stream=True so token chunks emit as events your listeners can forward to SSE, WebSockets, or logs without waiting for the full completion string.

What CrewAI events carry streamed LLM tokens?

LLMStreamChunkEvent surfaces partial tokens while LLMThinkingChunkEvent covers extended-thinking style chunks when the provider supports them.

How should I forward CrewAI stream chunks to a web UI?

Subscribe with BaseEventListener, push chunks onto a thread-safe queue, and drain that queue on a worker thread so slow clients cannot block the crew event loop.

Does CrewAI Flow support streaming?

Yes. Instantiate Flow with stream=True so each step can stream intermediate output while listeners record progress for dashboards or resumable sessions with @persist.

What is back-pressure when streaming CrewAI output?

Back-pressure means your consumer must keep up with producers. Blocking inside on_event stalls the run, so decouple network IO from the listener thread via queues or async tasks.

Where can I read more CrewAI streaming APIs?

Use the DevShelfHub CrewAI API reference for BaseEventListener and related classes, then revisit this tutorial while wiring observability and lite agent patterns.

Quick jump: API Reference