Overview
Threads represent individual conversation sessions in DeerFlow. Each thread maintains its own:- Conversation history - All messages exchanged
- State data - Title, artifacts, todos, uploads, viewed images
- Isolated workspace - Dedicated directories for files and outputs
- Sandbox connection - Persistent or ephemeral execution environment
Creating Threads
Create a new thread using the LangGraph SDK:Thread IDs
Thread IDs are UUIDs automatically generated by LangGraph. You can also provide your own:Listing Threads
Retrieve all threads with pagination:Getting Thread Details
Retrieve a specific thread:Thread State
DeerFlow extends the standard LangGraph state with additional fields:State Schema
Getting State
State Operations
Update thread state directly:State updates trigger the middleware chain, so changes like adding uploads will be processed by
UploadsMiddleware.Thread Configuration
Threads inherit runtime configuration from runs. You can specify different configs for each run:Configuration Options
Thread Isolation
Each thread gets isolated directories managed byThreadDataMiddleware:
Virtual Path Mapping
Inside the sandbox, these paths are mapped:Working with Messages
Message Format
DeerFlow uses LangChain message types:Retrieving Messages
Deleting Threads
Delete a thread and its associated data:Interrupts
DeerFlow supports interrupts via theask_clarification tool. When the agent needs user input:
Interrupt Flow
- Agent calls
ask_clarificationtool with a question ClarificationMiddlewareintercepts inafter_modelhook- Returns
Command(goto=END)to halt execution - Thread state shows
next: ["__interrupt__"] - Client provides clarification and resumes run
See Streaming - Interrupt Events for handling interrupts in streaming mode.
Checkpointing
LangGraph automatically checkpoints thread state after each step. This enables:- Time travel - Rewind to any previous state
- Branching - Create alternate conversation paths
- Recovery - Resume after crashes
Example: Complete Thread Lifecycle
Best Practices
Use consistent thread IDs
Use consistent thread IDs
Store thread IDs in your database to maintain conversation continuity across sessions.
Add metadata for filtering
Add metadata for filtering
Use metadata to organize and filter threads:
Clean up old threads
Clean up old threads
Implement a cleanup strategy for inactive threads:
Handle interrupts gracefully
Handle interrupts gracefully
Always check for interrupt state before assuming completion:
Next Steps
Streaming
Learn how to stream agent responses in real-time
File Uploads
Upload files for agent processing
Plan Mode
Enable task tracking with TodoList middleware
Memory
Understand how memory works across threads