Overview
Complex tasks rarely fit in a single pass. The lead agent can spawn sub-agents on the fly to:- Research multiple topics concurrently
- Execute specialized workflows in parallel
- Handle time-consuming operations asynchronously
- Isolate context for focused sub-tasks
The task() Tool
Sub-agents are spawned via the task() tool:
Parameters
string
required
Brief task summary (shown in UI)
string
required
Detailed instructions for the sub-agent
string
default:"general-purpose"
Type of sub-agent to use:
general-purpose or bashinteger
default:"20"
Maximum conversation turns (prevents infinite loops)
Sub-agent Types
DeerFlow includes two built-in sub-agent types:- general-purpose
- bash
Description: Full-capability agent with all tools except
task()Tools:- Sandbox tools (bash, read_file, write_file, etc.)
- Research tools (web_search, web_fetch)
- Built-in tools (present_files, ask_clarification)
- Skills access
- Memory access
- Research tasks
- Code generation
- Data analysis
- Content creation
Concurrency Limits
DeerFlow enforces a maximum of 3 concurrent sub-agents to prevent resource exhaustion. Enforcement: TheSubagentLimitMiddleware truncates excess task() calls:
If the agent requests more than 3 sub-agents, only the first 3 are executed.
Execution Flow
1. Task Submission
The lead agent callstask():
2. Background Execution
The task is submitted toSubagentExecutor:
3. Progress Events
The sub-agent emits events during execution:4. Result Collection
The lead agent receives results:Context Isolation
Each sub-agent runs in its own isolated context: Isolated:- Conversation history
- Tool call history
- Intermediate results
- Sandbox filesystem
- Thread data directory
- Skills access
- Memory (read-only)
Timeout Handling
Sub-agents have a 15-minute timeout:Parallel vs Sequential
Parallel Execution
Multipletask() calls in a single response run concurrently:
Sequential Execution
Wait for results between calls:Error Handling
Sub-agents can fail in several ways:Task failed
Task failed
The sub-agent encountered an error during execution:Action: Retry with corrected prompt or handle the error.
Task timed out
Task timed out
The sub-agent exceeded the 15-minute limit:Action: Break the task into smaller sub-tasks.
Concurrency limit
Concurrency limit
More than 3 sub-agents requested:Action: Wait for existing tasks to complete.
Best Practices
Use clear, specific prompts
Use clear, specific prompts
Sub-agents work better with detailed instructions:✅ Good: “Research PyTorch’s distributed training capabilities, focusing on DDP and FSDP. Include code examples and performance benchmarks.”❌ Bad: “Research PyTorch”
Leverage parallelism
Leverage parallelism
When tasks are independent, run them concurrently:
Set appropriate max_turns
Set appropriate max_turns
Limit turns based on task complexity:
- Simple tasks:
max_turns=5 - Medium tasks:
max_turns=20(default) - Complex tasks:
max_turns=50
Use Cases
Research Aggregation
Multi-Step Workflow
Specialized Tasks
Next Steps
Sub-agent Tool API
Complete task() tool reference
Configuration
Configure sub-agent behavior
Sandbox
Understand shared filesystem
Context Engineering
Learn about context isolation