Teaches agents how to effectively use the delegateToAgent tool for orchestrating multi-agent work. Covers dependency graph analysis, parallel vs serial execution patterns, and progress tracking...
Master the delegateToAgent tool to orchestrate work across specialist agents efficiently.
The delegateToAgent tool allows you to delegate tasks to other specialist agents. Key capabilities:
delegateToAgent({
agentName: string, // Name of the agent to delegate to
task: string // Specific task or question for that agent
})
Critical Feature: Multiple delegateToAgent calls can run in parallel. The tool uses immutable context branching - each call is isolated and doesn't interfere with others.
Before delegating, you need to know which agents are available. Use manageAgent with the list action:
manageAgent({ action: "list" })
This returns all specialist agents defined in the project. If you're unsure which agent is appropriate for a task, ask the user which agent they'd like you to delegate to.
Workflow:
manageAgent({ action: "list" }) to see available agentsdelegateToAgent using the chosen agentBefore delegating, always analyze task dependencies to determine:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β EXECUTION STRATEGY β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Independent tasks? ββYESβββΊ Delegate in PARALLEL β
β β β
β NO β
β β β
β βΌ β
β Has dependencies? ββYESβββΊ Delegate in SERIAL β
β β (wait for dependency) β
β NO β
β β β
β βΌ β
β Single task βββββββΊ Delegate immediately β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Look for dependency markers in plans and task lists:
| Marker | Example | Meaning |
|---|---|---|
Depends on: |
Depends on: Phase 1 |
Must complete Phase 1 first |
Requires: |
Requires: Task 2.1 |
Must complete Task 2.1 first |
After: |
After: API implementation |
Sequential dependency |
| Task numbering | 3.2 follows 3.1 |
Implicit ordering within phase |
Infer dependencies from task semantics when markers are absent:
| First Task | Dependent Task | Reasoning |
|---|---|---|
| Create schema/types | Use schema/types | Definition before usage |
| Implement feature | Write tests for feature | Code before tests |
| Design API | Implement API | Design before implementation |
| Build component | Integrate component | Build before integration |
| Research/analyze | Implement based on research | Information before action |
Heuristic: If Task B references output, artifacts, or decisions from Task A, then B depends on A.
For detailed sequence diagrams showing parallel, serial, and mixed execution with plan updates, see assets/EXAMPLE.md.
When tasks have no dependencies on each other, delegate simultaneously:
User: "Review the auth module for security, performance, and code style"
Analysis:
- Security review: independent
- Performance review: independent
- Code style review: independent
Execution: Call all three delegateToAgent in parallel
βββββββββββββββββββββββββββββββββββββββββββ
β delegateToAgent(security, "review") ββββ
β delegateToAgent(performance, "review") ββββΌβββΊ All run simultaneously
β delegateToAgent(codestyle, "review") ββββ
βββββββββββββββββββββββββββββββββββββββββββ
When tasks have dependencies, execute sequentially:
User: "Design the API, then implement it, then write tests"
Analysis:
- Design API: no dependencies
- Implement API: depends on design
- Write tests: depends on implementation
Execution: Sequential chain
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β delegateToAgent(architect, "design API") β
β β β
β βΌ (wait for completion) β
β delegateToAgent(developer, "implement API") β
β β β
β βΌ (wait for completion) β
β delegateToAgent(developer, "write tests") β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Complex work often has parallel branches with serial dependencies:
Plan Phase 2:
- Task 2.1: Create database schema (no deps)
- Task 2.2: Create API types (no deps)
- Task 2.3: Implement API endpoints (requires 2.1, 2.2)
- Task 2.4: Write integration tests (requires 2.3)
Execution:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β WAVE 1 (parallel): β
β delegateToAgent(developer, "create schema") β
β delegateToAgent(developer, "create API types") β
β β β
β βΌ (wait for both) β
β WAVE 2 (serial): β
β delegateToAgent(developer, "implement endpoints")β
β β β
β βΌ (wait) β
β WAVE 3 (serial): β
β delegateToAgent(developer, "write tests") β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
When executing tasks from a plan markdown file, update it as work progresses:
Checkbox Updates:
Before: - [ ] Create user schema
After: - [x] Create user schema
Status Field Updates:
Before: **Status**: β Not Started
After: **Status**: β Complete
Phase Status:
Before: **Status**: In Progress
After: **Status**: Complete
Timestamp Comments (optional, for audit trail):
##### 2.1 Create Database Schema
**Status**: β Complete
**Completed**: 2026-01-31 14:32
When given a general request without a plan, use available tracking tools:
Example mental model:
User: "Set up authentication with JWT, add user roles, and create admin dashboard"
Dependency analysis:
βββ JWT auth implementation (independent)
βββ User roles system (depends on auth? check...)
β βββ Roles need users β depends on auth
βββ Admin dashboard (depends on roles)
Execution order:
1. delegateToAgent(developer, "implement JWT auth")
2. delegateToAgent(developer, "add user roles system")
3. delegateToAgent(developer, "create admin dashboard")
The delegateToAgent tool has built-in safeguards:
| Constraint | Limit | Error |
|---|---|---|
| Max depth | 5 levels | MAX_DEPTH_EXCEEDED |
| Circular reference | AβBβA | CIRCULAR_REFERENCE |
| Missing context | No session | CONTEXT_NOT_INITIALIZED |
If you hit max depth, the task is too deeply nested. Consider restructuring to reduce delegation layers.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ORCHESTRATION CHECKLIST β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 1. β‘ Parse tasks from plan/request β
β 2. β‘ Identify explicit dependency markers β
β 3. β‘ Infer implicit dependencies from semantics β
β 4. β‘ Group into parallel waves β
β 5. β‘ Execute wave 1 (all parallel) β
β 6. β‘ Wait for wave 1 completion β
β 7. β‘ Update plan/todos with completed tasks β
β 8. β‘ Execute wave 2 (may be parallel or serial) β
β 9. β‘ Repeat until all tasks complete β
β 10. β‘ Final plan/status update β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ