Overview
Plan Mode adds a TodoList middleware to the agent, providing task tracking capabilities for complex multi-step workflows. When enabled, the agent can break down tasks, track progress, and provide visibility into what’s being done.Plan Mode uses LangChain’s built-in
TodoListMiddleware with custom DeerFlow-style prompts.Benefits
Task Breakdown
Break complex tasks into manageable steps
Progress Tracking
Track task status in real-time
User Visibility
Users see what the agent is working on
Parallel Execution
Multiple tasks can be in progress simultaneously
Enabling Plan Mode
Plan Mode is controlled via runtime configuration through theis_plan_mode parameter in RunnableConfig.
Basic Configuration
Dynamic Plan Mode
You can enable/disable plan mode dynamically based on task complexity:How It Works
Agent Creation
When
make_lead_agent(config) is called, it extracts is_plan_mode from config.configurable.Middleware Chain
Config is passed to
_build_middlewares(config) which reads is_plan_mode and calls _create_todo_list_middleware(is_plan_mode).TodoList Middleware
If
is_plan_mode=True, a TodoListMiddleware instance is created and added to the middleware chain.Middleware Architecture
The write_todos Tool
When Plan Mode is enabled, the agent has access to awrite_todos tool:
Tool Description
Task States
- pending
- in_progress
- completed
Task not yet started.
Using write_todos
The agent uses the tool to manage its task list:When to Use Plan Mode
Ideal Use Cases
Multi-Step Research Projects
Multi-Step Research Projects
When tasks require:
- Multiple searches from different angles
- Data collection from various sources
- Synthesis of information
Content Generation with Research
Content Generation with Research
When creating:
- Presentations (research → outline → slides)
- Reports (gather data → analyze → write)
- Web pages (research design → implement)
Code Projects
Code Projects
When building:
- Applications with multiple components
- Features requiring setup, implementation, testing
- Refactoring projects
Analysis Tasks
Analysis Tasks
When performing:
- Data analysis with multiple stages
- Comparative analysis
- Complex calculations
When NOT to Use
- ❌ Single, straightforward questions
- ❌ Quick conversational queries
- ❌ Simple file operations
- ❌ Trivial calculations
Custom Prompts
DeerFlow uses custom prompts that match the overall prompt style:System Prompt Features
- Uses XML tags (
<todo_list_system>) for consistency - Emphasizes CRITICAL rules and best practices
- Clear “When to Use” vs “When NOT to Use” guidelines
- Focuses on real-time updates and immediate completion
Tool Description Features
- Detailed usage scenarios with examples
- Strong emphasis on NOT using for simple tasks
- Clear task state definitions
- Comprehensive best practices
- Task completion requirements
Custom prompts are defined in
_create_todo_list_middleware() in backend/src/agents/lead_agent/agent.py:57.Example Workflow
Here’s how Plan Mode works in practice:Accessing Todo State
The todo list is stored in the thread state:Best Practices
Use for Appropriate Complexity
Use for Appropriate Complexity
Enable Plan Mode for tasks that genuinely benefit from tracking:
- 3+ distinct steps
- Multiple stages
- Long-running operations
Clear Task Descriptions
Clear Task Descriptions
Tasks should be:
- Specific and actionable
- Independent when possible
- Properly sequenced when dependent
Update Status Promptly
Update Status Promptly
Mark tasks as completed immediately after finishing:
- Don’t batch multiple completions
- Update status before moving to next task
- Ensure “completed” reflects actual completion
Parallel Execution
Parallel Execution
Multiple tasks can be in_progress simultaneously for:
- Independent tasks
- Waiting on external operations
- Parallel research
Troubleshooting
TodoList not appearing
TodoList not appearing
Verify plan mode is enabled:
Agent not using write_todos
Agent not using write_todos
Task might be too simple. Try:
- More complex, multi-step requests
- Explicit instruction: “Create a plan first”
- Check if task has 3+ distinct steps
Tasks stuck in pending
Tasks stuck in pending
Agent might not be updating status. This is usually:
- Expected behavior (task not started yet)
- Processing issue (check logs)
- Task might be blocked waiting for clarification
Too many tasks created
Too many tasks created
Agent might be over-planning. Consider:
- Using a less complex prompt
- Disabling plan mode for this task
- Providing more specific instructions
Configuration Reference
Runtime Configuration
Middleware Position
TodoListMiddleware is positioned before ClarificationMiddleware:Next Steps
Creating Skills
Build skills that leverage Plan Mode
Custom Tools
Create tools for task execution
Configuration
Learn about agent configuration
Architecture
Understand agent and middleware architecture