AAnvio
Reference ArchiveSource Docs

Subagent Delegation

Native multi-agent delegation with task assignment, result aggregation, failure handling, and progress tracking.

4 min read

This is a migrated reference document from the original Anvio source repo. Content is preserved as-is; canonical documentation lives in the sections above in the sidebar.

Original path: docs/40-subagent-delegation.md

Native multi-agent delegation with task assignment, result aggregation, failure handling, and progress tracking.

Delegation Model

Manager Agent
├── Research Agent    → gather context
├── Coding Agent      → implement changes
├── Review Agent      → code review
└── QA Agent          → test validation

Orchestration Modes

Extends existing SupervisorOrchestrator in packages/agents/src/orchestrator.ts:

ModeBehaviorUse Case
sequentialRun tasks in orderPipeline workflows
parallelConcurrent executionIndependent subtasks
fan-outParallel + no synthesisBulk processing
fan-inParallel + manager synthesisResearch → decision
hierarchicalNested orchestration plansComplex projects

Enhanced Orchestration Plan

# Runtime plan (generated or configured)
managerAgentId: project-manager
mode: hierarchical
tasks:
  - agentId: researcher
    input: "Research auth patterns for our stack"
    id: research-1
    onFailure: continue        # continue | abort | retry

  - agentId: architect
    input: "Design auth plugin based on: {{tasks.research-1.output}}"
    id: design-1
    dependsOn: [research-1]

  - agentId: software-engineer
    input: "Implement: {{tasks.design-1.output}}"
    id: impl-1
    dependsOn: [design-1]
    worktree: true             # isolated git worktree

  - agentId: code-reviewer
    input: "Review changes in worktree {{tasks.impl-1.worktree}}"
    id: review-1
    dependsOn: [impl-1]

  - agentId: qa-agent
    input: "Test auth flows"
    id: qa-1
    dependsOn: [review-1]

Architecture

Rendering diagram…

Sequence: Hierarchical Delegation

Rendering diagram…

Failure Handling

PolicyBehavior
abortStop all remaining tasks (default)
continueSkip failed task, proceed with dependents blocked
retryRetry up to maxAttempts with backoff
interface DelegationTask {
  agentId: string;
  input: string;
  id?: string;
  dependsOn?: string[];
  onFailure?: 'abort' | 'continue' | 'retry';
  maxAttempts?: number;
  worktree?: boolean;
}

Progress Tracking

Orchestrator publishes granular events:

EventData
ORCHESTRATION_STARTEDplan summary
DELEGATION_TASK_STARTEDtaskId, agentId
DELEGATION_TASK_COMPLETEDtaskId, result summary
DELEGATION_TASK_FAILEDtaskId, error
ORCHESTRATION_COMPLETEDstatus, result count

Progress visible via:

anvio orchestrate status <managerSessionId>
anvio logs --orchestration <managerSessionId>

Result Aggregation

ModeAggregation
fan-inManager synthesizes all sub-results
parallelArray of results returned
hierarchicalNested result tree
interface OrchestrationResult {
  managerSessionId: string;
  results: Array<{
    taskId: string;
    agentId: string;
    sessionId: string;
    result: AgentResult;
    status: 'completed' | 'failed' | 'skipped';
  }>;
  status: 'completed' | 'failed' | 'partial';
  synthesized?: string;       // fan-in output
}

Agent Configuration

# workspace/agents/project-manager.yaml
spec:
  orchestration:
    pattern: hierarchical
    delegates:
      - researcher
      - architect
      - software-engineer
      - code-reviewer
      - qa-agent
    defaults:
      onFailure: abort
      maxAttempts: 2

Kanban Integration

Delegation tasks sync to kanban:

  • Each subtask → kanban task with agent assignee
  • Column transitions driven by delegation status
  • Multi-agent board shows per-agent state

Extension Guide

Status (2026-10-25): items below that mention a plugin or plugin manifest describe design intent. Anvio has no plugin system (ROADMAP T-058); extending this subsystem today means changing the package code.

  1. Add custom aggregation strategies via plugin
  2. Implement TaskPlanner for automatic plan generation from goals
  3. Hook onOrchestrationCompleted for notifications

Operational Runbook

ScenarioAction
Stuck delegationanvio orchestrate cancel <sessionId>
Partial failureReview results array, re-run failed tasks
Debug plananvio orchestrate dry-run --plan plan.yaml

Package Boundaries

  • Orchestrator: packages/agents/src/orchestrator.ts (extend existing)
  • Planner: packages/agents/src/task-planner.ts
  • Progress: packages/agents/src/delegation-progress.ts

See also 03-runtime.md for runtime orchestration patterns.

Edit on GitHub

Last updated on

On this page