Overview
DeerFlow supports streaming agent responses using Server-Sent Events (SSE). This allows you to:- Display agent responses in real-time as they’re generated
- Show tool calls and results as they happen
- Track task progress with sub-agents
- Handle interrupts and clarification requests
- Display thinking process for supported models
Streaming with LangGraph SDK
Use thestream method to receive events as they occur:
Stream Modes
DeerFlow supports multiple streaming modes:Event Types
DeerFlow streams three primary event types:1. Values Events
Full state snapshots after each agent step:2. Messages-Tuple Events
Per-message updates for incremental rendering:3. End Event
Signals stream completion:SSE Protocol
DeerFlow follows the standard Server-Sent Events protocol:event:line specifying the event typedata:line with JSON payload- Empty line separating events
Building a Chat UI
Here’s a complete example of streaming to a chat interface:Handling Sub-Agent Events
Whensubagent_enabled is true, you’ll receive task-related events:
Sub-agent tasks execute in background threads. You can have up to
max_concurrent_subagents tasks running in parallel (default: 3).Thinking Mode
Whenthinking_enabled is true for supported models, you’ll receive extended thinking content:
- Show in expandable section
- Display in real-time like regular content
- Hide from user but log for debugging
Interrupt Events
When the agent callsask_clarification, the stream will pause:
Error Handling
Handle errors gracefully during streaming:Connection Management
Timeouts
Set timeouts to prevent hanging:Reconnection
If the connection drops, you can resume from state:Performance Optimization
Buffer events for batching
Buffer events for batching
Reduce UI updates by batching events:
Use messages-tuple for chat UIs
Use messages-tuple for chat UIs
messages-tuple mode is optimized for incremental rendering:Throttle UI updates
Throttle UI updates
Prevent excessive re-renders:
Complete Example
Next Steps
Thread Management
Learn about thread lifecycle and state management
Python Client
Use the embedded client for in-process streaming
Sub-Agents
Understand parallel task execution with sub-agents
Middleware Chain
Deep dive into middleware processing pipeline