Delegated Tasking
Break down complex tasks by delegating subtasks to specialized agents, enabling supervisor-worker patterns and automated code review workflows.
Overview
Delegated tasking enables:
- Supervisor-Worker Pattern: Main agent delegates subtasks to specialists
- Automated Code Review: Specialized reviewers validate each aspect of changes
- Research Delegation: Spawn research agents when blocked on technical challenges
- Parallel Review: Multiple reviewers work simultaneously in isolated workspaces
Supervisor-Worker Pattern
Within the long-horizon task execution system, the supervisor agent can spawn worker agents for subtasks:
ah task create --agent claude --prompt "Build a REST API with proper security and performance optimization"How It Works
- Supervisor coordinates the overall task via the loop driver
- Identifies subtasks benefiting from specialization
- Spawns worker agents via
ah agent startin isolated workspaces - Workers run in isolated filesystem branches
- Supervisor merges and coordinates results
Example Workflow
Supervisor Agent
├── Spawns: Security Reviewer
│ └── Audits authentication, validates inputs
├── Spawns: Performance Optimizer
│ └── Profiles queries, optimizes hot paths
└── Spawns: Test Writer
└── Adds comprehensive test coverageAutomated Code Review
At milestone boundaries, specialized review agents validate code quality.
Available Reviewers
| Reviewer | Focus | Blocking |
|---|---|---|
| Security | Vulnerabilities, injection, auth bypass | Yes (if unfixable) |
| Test Integrity | Test cheating, weakened assertions | Yes (if unfixable) |
| Goal Adherence | Milestone requirements match | Yes (if unfixable) |
| Dependency Hygiene | Outdated deps, supply chain risks | Warning |
| Architecture | Module boundaries, cycles | Warning |
| Duplication | Code clones, repeated logic | Warning |
| Performance | Algorithms, data structures | Conditional |
| Concurrency | Threading, synchronization | Warning |
| Idioms | Project style, patterns | No |
Review Design Principles
- Fix, Don’t Just Complain: Reviewers implement fixes in isolated workspaces
- Narrow Scope: Each reviewer has one job and a clear checklist
- Require Evidence: Issues must cite specific code and be reproducible
- Standardized Output: Structured verdicts for automated processing
Enabling Code Review
# .agents/config.toml
[code_review]
# Enable automated code review
enabled = true
# Run reviews in parallel (requires AgentFS or similar)
parallel = true
# Reviewers to run
reviewers = [
"security",
"test-integrity",
"goal-adherence",
"architecture"
]Sequential vs Parallel Reviews
Sequential Mode:
- Each reviewer runs after the previous
- Later reviewers see fixes from earlier ones
- Simpler but slower
Parallel Mode (recommended with AgentFS):
- All reviewers run simultaneously
- Each gets isolated copy-on-write workspace
- Fixes merged after all complete
[code_review]
# Enable parallel reviews
parallel = trueCustom Review Agents
Define project-specific reviewers for domain-specific rules.
Directory Structure
.agents/reviewers/
├── migrations.md # Database migration reviewer
├── api_contracts.md # API compatibility reviewer
└── branding.md # UI/branding consistency reviewerConfiguration
# .agents/config.toml
[[review_agents]]
name = "migrations"
model = "sonnet"
blocking = true
prompt_file = ".agents/reviewers/migrations.md"
trigger = "path:migrations/**" # Only when migrations change
[[review_agents]]
name = "api_contracts"
model = "sonnet"
blocking = true
prompt_file = ".agents/reviewers/api_contracts.md"
trigger = "path:src/api/**"
[[review_agents]]
name = "branding"
model = "haiku"
blocking = false
prompt_file = ".agents/reviewers/branding.md"
trigger = "always"Trigger Types
| Trigger | Description |
|---|---|
always | Run on every review cycle |
path:pattern | Run when matching files change |
label:name | Run when task has specific label |
Writing Reviewer Prompts
# migrations.md
You are a database migration reviewer. Your job is to ensure migrations are:
1. **Reversible**: Every migration has a working rollback
2. **Safe**: No data loss, proper null handling
3. **Performant**: Indexed columns, no table locks on large tables
## Review Checklist
- [ ] Migration has both up and down methods
- [ ] Down method correctly reverses up
- [ ] New columns have appropriate defaults
- [ ] Indexes added for foreign keys
- [ ] No raw SQL without parameterization
## When You Find Issues
1. Reproduce the issue
2. Implement the fix
3. Verify the fix works
4. Report in standard JSON formatResearch Delegation
When agents encounter blocking technical challenges, they can delegate research.
Enabling Research
ah task create --agent claude --allow-web-search --prompt "Implement OAuth2 with the latest best practices"Research Flow
- Implementation agent detects it’s blocked
- Coordinator identifies abandonment (agent deviated from plan)
- Research agent spawned with web search capabilities
- Research findings injected via session forking
- Implementation agent continues with new knowledge
Research Agent Behavior
The research agent:
- Investigates the technical challenge
- Searches documentation and resources
- Creates a forked session from the best moment
- Injects targeted instructions to unstuck the agent
Configuration
[research]
# Enable research delegation
enabled = true
# Model for research agent
model = "sonnet"
# Allow web search
web_search = true
# Maximum research duration
timeout = "5m"Coordinator Agent
The coordinator examines implementation work and decides next steps.
Coordinator Responsibilities
- Detect Abandonment: Did the agent deviate due to blockers?
- Select Reviewers: Which specialists should examine changes?
- Route to Research: If blocked, spawn research agent
Abandonment Criteria
The coordinator detects abandonment when:
- Agent loops on the same error
- Agent explicitly noted a blocker
- Agent chose simpler alternative that doesn’t meet goals
- Code changes are unrelated to milestone goals
Coordinator Output
{
"outcome": "request-reviews",
"reviewers": ["security", "test-integrity"]
}or
{
"outcome": "deliver-expert-help",
"branch_point_id": "snapshot-123",
"expert_feedback": "Research findings..."
}Supervisor Policy
The supervisor processes review results:
| Verdict | Action |
|---|---|
| Fixed Issues | Automatically merged if tests pass |
| Unfixable Blocking | Implementation agent must revise |
| Warnings | Logged, don’t block advancement |
Supervisor Decisions
After reviews complete, the supervisor decides:
- CONTINUE_DEVELOPMENT: More work needed on current milestone
- NEW_REVIEW_ROUND: Re-review after substantial merged changes
- DEVELOPMENT_COMPLETE: All criteria met, exit successfully
- NOTIFY_MANAGEMENT: Human input needed
- STOP_DEVELOPMENT: Insurmountable blockers, exit with failure
Configuration Reference
# .agents/config.toml
[delegation]
# Allow agents to spawn sub-agents
enabled = true
# Maximum concurrent delegated tasks
max_concurrent = 5
[code_review]
enabled = true
parallel = true
reviewers = ["security", "test-integrity", "goal-adherence"]
[research]
enabled = true
model = "sonnet"
web_search = true
timeout = "5m"
[supervisor]
# Maximum time before supervisor checks in
max_session_duration = "2h"
# Automatically merge non-blocking fixes
auto_merge_fixes = true