Skip to Content
GuidesWorkflowsDelegated Tasking

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

  1. Supervisor coordinates the overall task via the loop driver
  2. Identifies subtasks benefiting from specialization
  3. Spawns worker agents via ah agent start in isolated workspaces
  4. Workers run in isolated filesystem branches
  5. 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 coverage

Automated Code Review

At milestone boundaries, specialized review agents validate code quality.

Available Reviewers

ReviewerFocusBlocking
SecurityVulnerabilities, injection, auth bypassYes (if unfixable)
Test IntegrityTest cheating, weakened assertionsYes (if unfixable)
Goal AdherenceMilestone requirements matchYes (if unfixable)
Dependency HygieneOutdated deps, supply chain risksWarning
ArchitectureModule boundaries, cyclesWarning
DuplicationCode clones, repeated logicWarning
PerformanceAlgorithms, data structuresConditional
ConcurrencyThreading, synchronizationWarning
IdiomsProject style, patternsNo

Review Design Principles

  1. Fix, Don’t Just Complain: Reviewers implement fixes in isolated workspaces
  2. Narrow Scope: Each reviewer has one job and a clear checklist
  3. Require Evidence: Issues must cite specific code and be reproducible
  4. 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 = true

Custom 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 reviewer

Configuration

# .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

TriggerDescription
alwaysRun on every review cycle
path:patternRun when matching files change
label:nameRun 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 format

Research 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

  1. Implementation agent detects it’s blocked
  2. Coordinator identifies abandonment (agent deviated from plan)
  3. Research agent spawned with web search capabilities
  4. Research findings injected via session forking
  5. 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

  1. Detect Abandonment: Did the agent deviate due to blockers?
  2. Select Reviewers: Which specialists should examine changes?
  3. 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:

VerdictAction
Fixed IssuesAutomatically merged if tests pass
Unfixable BlockingImplementation agent must revise
WarningsLogged, 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