This skill teaches how to delegate tasks to specialist agents using delegateToAgent, optimizing dependency graph analysis and progress tracking.
npx playbooks add skill getcosmos/agent-skills --skill cosmos-delegate-to-agent
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](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 │
└─────────────────────────────────────────────────────────────┘Weekly roundup of top Claude Code skills, MCP servers, and AI coding tips.