Skip to main content

What is LangGraph Server?

DeerFlow uses LangGraph as its core agent runtime. The LangGraph Server provides HTTP/SSE endpoints for creating threads, sending messages, and streaming agent responses.
Default Port: LangGraph Server runs on port 2024 in development.When using make dev from the project root, all API requests are proxied through Nginx on port 2026 with the /api/langgraph prefix.

Base URL

The LangGraph API is accessible at:
  • Production/Docker: http://localhost:2026/api/langgraph
  • Direct access (dev): http://localhost:2024

Architecture

DeerFlow’s LangGraph Server is configured via backend/langgraph.json:
The lead_agent graph factory (make_lead_agent) creates the main agent with:
  • Dynamic model selection based on runtime configuration
  • Middleware chain for thread isolation, memory, uploads, and more
  • Tools from sandbox, built-ins, MCP servers, and community integrations
  • System prompt with skills, memory context, and date injection

Using the LangGraph SDK

The official LangGraph SDK provides a Python client for interacting with LangGraph Server.

Installation

Basic Usage

Use assistant_id="lead_agent" when creating runs. This references the graph defined in langgraph.json.

Runtime Configuration

You can customize agent behavior by passing config.configurable parameters:

Available Configuration Options

Thread State Schema

DeerFlow extends LangGraph’s AgentState with additional fields in ThreadState:

Thread Isolation

Each thread gets isolated directories created by ThreadDataMiddleware:
  • Workspace: backend/.deer-flow/threads/{thread_id}/user-data/workspace/
  • Uploads: backend/.deer-flow/threads/{thread_id}/user-data/uploads/
  • Outputs: backend/.deer-flow/threads/{thread_id}/user-data/outputs/
Inside the agent’s sandbox, these paths are mapped to /mnt/user-data/workspace, /mnt/user-data/uploads, and /mnt/user-data/outputs.

Agent Graph Structure

The lead_agent graph is created using LangGraph’s create_agent() API with:
  1. Model: Selected via create_chat_model(name, thinking_enabled)
  2. Tools: Combined from multiple sources via get_available_tools()
  3. Middleware: 11 middleware components processing requests/responses
  4. System Prompt: Generated by apply_prompt_template() with context injection
  5. State Schema: ThreadState with custom reducers

Middleware Chain

Middlewares execute in strict order defined in src/agents/lead_agent/agent.py:207:
  1. ThreadDataMiddleware - Create per-thread directories
  2. UploadsMiddleware - Inject uploaded files into context
  3. SandboxMiddleware - Acquire and manage sandbox lifecycle
  4. DanglingToolCallMiddleware - Patch missing tool responses
  5. SummarizationMiddleware - Context reduction (optional)
  6. TodoListMiddleware - Task tracking (optional, plan_mode)
  7. TitleMiddleware - Auto-generate thread title
  8. MemoryMiddleware - Queue conversations for memory updates
  9. ViewImageMiddleware - Inject images for vision models
  10. SubagentLimitMiddleware - Enforce parallel task limits (optional)
  11. ClarificationMiddleware - Intercept clarification requests (always last)
Middleware order is critical for proper operation. See backend/src/agents/lead_agent/agent.py:198 for detailed comments.

API Endpoints

The LangGraph Server provides standard endpoints:

Alternative: Embedded Python Client

For Python applications running in the same process, use DeerFlowClient instead of HTTP:
DeerFlowClient shares the same configuration files and data directories as LangGraph Server, but doesn’t require any HTTP services.
See Python Client API for full documentation.

Next Steps

Thread Management

Learn how to create and manage conversation threads

Streaming

Stream agent responses with Server-Sent Events

Python Client

Use the embedded Python client for in-process access

Agent Configuration

Configure models, tools, and runtime behavior