Skip to main content

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:
Thread IDs must be unique. Creating a thread with an existing ID will fail.

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 by ThreadDataMiddleware:

Virtual Path Mapping

Inside the sandbox, these paths are mapped:
The agent sees only virtual paths. Path translation happens automatically in sandbox tools.

Working with Messages

Message Format

DeerFlow uses LangChain message types:

Retrieving Messages

Deleting Threads

Delete a thread and its associated data:
This permanently deletes:
  • All conversation history
  • Thread state (title, artifacts, todos)
  • Isolated workspace files
  • Cannot be undone

Interrupts

DeerFlow supports interrupts via the ask_clarification tool. When the agent needs user input:

Interrupt Flow

  1. Agent calls ask_clarification tool with a question
  2. ClarificationMiddleware intercepts in after_model hook
  3. Returns Command(goto=END) to halt execution
  4. Thread state shows next: ["__interrupt__"]
  5. 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

Store thread IDs in your database to maintain conversation continuity across sessions.
Use metadata to organize and filter threads:
Implement a cleanup strategy for inactive threads:
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