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 viabackend/langgraph.json:
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
Runtime Configuration
You can customize agent behavior by passingconfig.configurable parameters:
Available Configuration Options
| Parameter | Type | Default | Description |
|---|---|---|---|
thinking_enabled | bool | True | Enable extended thinking mode for supported models |
reasoning_effort | str | None | Reasoning effort level (e.g., “low”, “medium”, “high”) |
model_name | str | Config default | Override the model for this conversation |
is_plan_mode | bool | False | Enable TodoList middleware for task tracking |
subagent_enabled | bool | False | Enable the task tool for delegating to sub-agents |
max_concurrent_subagents | int | 3 | Maximum number of parallel sub-agent tasks |
agent_name | str | None | Use a custom agent (requires custom agent setup) |
Thread State Schema
DeerFlow extends LangGraph’sAgentState with additional fields in ThreadState:
Thread Isolation
Each thread gets isolated directories created byThreadDataMiddleware:
- 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
Thelead_agent graph is created using LangGraph’s create_agent() API with:
- Model: Selected via
create_chat_model(name, thinking_enabled) - Tools: Combined from multiple sources via
get_available_tools() - Middleware: 11 middleware components processing requests/responses
- System Prompt: Generated by
apply_prompt_template()with context injection - State Schema:
ThreadStatewith custom reducers
Middleware Chain
Middlewares execute in strict order defined insrc/agents/lead_agent/agent.py:207:
ThreadDataMiddleware- Create per-thread directoriesUploadsMiddleware- Inject uploaded files into contextSandboxMiddleware- Acquire and manage sandbox lifecycleDanglingToolCallMiddleware- Patch missing tool responsesSummarizationMiddleware- Context reduction (optional)TodoListMiddleware- Task tracking (optional, plan_mode)TitleMiddleware- Auto-generate thread titleMemoryMiddleware- Queue conversations for memory updatesViewImageMiddleware- Inject images for vision modelsSubagentLimitMiddleware- Enforce parallel task limits (optional)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:- Thread Management - Create, list, and manage conversation threads
- Streaming - Stream agent responses with SSE
- State Management - Get and update thread state
- Interrupts - Handle clarification requests
Alternative: Embedded Python Client
For Python applications running in the same process, useDeerFlowClient instead of HTTP:
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