Skip to main content

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 the stream method to receive events as they occur:

Stream Modes

DeerFlow supports multiple streaming modes:
Use messages-tuple for chat UIs and values when you need complete state after each step.

Event Types

DeerFlow streams three primary event types:

1. Values Events

Full state snapshots after each agent step:
When to use: Need complete state, building history view, resuming interrupted sessions.

2. Messages-Tuple Events

Per-message updates for incremental rendering:
When to use: Chat UI, showing tool execution, incremental text rendering.

3. End Event

Signals stream completion:
When to use: Cleanup, final state snapshot, enabling UI controls.

SSE Protocol

DeerFlow follows the standard Server-Sent Events protocol:
Each event has:
  • event: line specifying the event type
  • data: 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

When subagent_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

When thinking_enabled is true for supported models, you’ll receive extended thinking content:
Display options:
  • Show in expandable section
  • Display in real-time like regular content
  • Hide from user but log for debugging
Thinking content can be lengthy. Consider truncating or collapsing it in your UI.

Interrupt Events

When the agent calls ask_clarification, the stream will pause:
Handling interrupts:

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

Reduce UI updates by batching events:
messages-tuple mode is optimized for incremental rendering:
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