Multi-Agentmulti-agenthierarchicaltreedelegationscale

Hierarchical Pattern

Manager → team leads → workers scales a supervisor to many parallel sub-tasks, but each level compresses information and multiplies latency and cost.

Interview question
Progress

Builds on Workflow Orchestration and Agent Loops in the Agentic AI roadmap.

Key points

  • Hierarchy fixes fan-out limits of a single supervisor.
  • Each level compresses; carry critical findings as structured fields.
  • Latency = depth × coordination + slowest leaf; cost = total agent runs.
  • Depth 2, fan-out 5–10 is the practical envelope.
  • If intermediate levels only fan out, replace them with code.

Why add levels

A single supervisor with 30 specialists must hold 30 tool descriptions and merge 30 results; selection accuracy and context both suffer. A hierarchy groups specialists under leads: the manager picks among 4 leads, each lead among ~7 workers. This is the same reason organisations and B-trees have fan-out limits — a node can only manage so many children well.

The canonical use is large, decomposable work: "migrate 40 services to the new auth library" becomes a manager assigning services to backend/frontend/infra leads, each spawning one worker per service in parallel.

Two-level hierarchy
Manager: plan + mergeLead: backendLead: frontendLead: infraWorker: svc AWorker: svc BWorker: webWorker: terraformSummaries flow up
UserLLMAgentToolDataDecisionHumanGuardrail

The compression tax

Information travels up as summaries. A worker that discovers "service B has a hard-coded token in a test fixture" writes it in a 400-token report; the lead condenses 6 reports into 300 tokens; the manager reads "backend: 6/6 migrated, minor issues". The security finding is gone. Design the upward schema to carry structured flags (blocking_issues: []) that cannot be summarised away.

Latency is the depth times the per-level round trip plus the slowest leaf. Two levels of 5 s coordination plus a 60 s worker is 70 s minimum. Cost is the total number of agent runs — for 40 workers and 4 leads and 1 manager, 45 agent loops, each with its own prompt overhead.

  • Keep depth at 2; three levels is rarely justified and nearly impossible to debug from a trace.
  • Fan-out per node of 5–10; beyond that, selection and merging degrade.
  • Leaf workers should be the cheapest model that passes the worker eval; leads and manager can be stronger.

Deterministic alternative

Ask whether the hierarchy is really doing judgment at each level or just fan-out. If the manager's "plan" is "one worker per service", that is a for loop plus a queue, not an agent. Replace the coordination layers with code and keep LLMs only at the leaves; you get the same parallelism with zero compression loss and a trivially testable orchestrator (When Not to Use Multi-Agent).

Fan-out with code, judgment at the leaves
1import asyncio
2
3async def migrate_all(services: list[str]) -> list[dict]:
4 sem = asyncio.Semaphore(8) # bound concurrency and cost
5 async def one(svc: str) -> dict:
6 async with sem:
7 return await worker_agent.run(f"Migrate {svc} to auth-v2", budget_tokens=30_000)
8 reports = await asyncio.gather(*(one(s) for s in services))
9 blocking = [r for r in reports if r["blocking_issues"]] # structured, never summarised
10 return blocking or reports

When to use — and when not to

Use it when
  • Dozens of parallel, similar sub-tasks with a few genuinely different groups.
  • Sub-task groups need different leads with different domain prompts or tools.
  • Batch workloads where a minute of latency is acceptable.
Avoid it when
  • Fewer than ~10 sub-tasks — a flat supervisor suffices.
  • Intermediate levels make no decisions — use a queue and a loop.
  • Interactive use cases.

Failure modes

Reference · show
  • Critical findings summarised away on the way up.
  • Cost explosion from unbounded worker spawning (cost-explosion-after-launch).
  • One slow leaf stalls the whole tree without per-worker timeouts.
  • Leads duplicate or contradict each other's decisions with no shared state.

Tradeoffs

Complexity
low → high
Latency
low → high
Cost
low → high
Reliability
poor → strong
Debuggability
hard → easy

Check yourself

Answer out loud or on paper first, then compare. These come from the interview questions linked to this lesson.

  1. A team split a single agent into a supervisor with four workers and quality dropped. What are the likely causes and what would you do?

    Show a strong answer

    The usual causes: the supervisor loses information when summarising the task for workers and their results for itself; workers lack context the single agent had (the user's original phrasing, earlier tool results); hand-offs use free-form prose so details drift; the supervisor makes extra round trips and hits iteration or budget caps; and errors compound because a worker's mistake is taken as truth by the supervisor. See Supervisor Pattern and Agent-to-Agent Communication.

    I would pull traces for the regressions and compare the single-agent run with the multi-agent run on the same input: where did the needed fact disappear? Then fix the boundary: pass structured messages including the original request, make workers return typed outputs with confidence and citations, cap supervisor rounds, and give the supervisor the raw worker outputs rather than its own summaries when they fit the budget.

    If after that the multi-agent version is not measurably better on the golden set, revert. The single agent was a working baseline; the split has to earn its place.

    Full interview question, with follow-ups and red flags →
  2. Costs of your agent grew ten times faster than traffic after launch. How do you find the cause and bring it under control?

    Show a strong answer

    Cost growing faster than traffic means cost per task grew, so I attribute cost from traces: tokens and dollars per run broken down by step, model, tool, and task type, then look at the distribution rather than the mean; a fat tail of long runs often accounts for most of the spend. Common drivers: context accumulating across steps (history and tool results never compressed), more steps per task on real inputs than in the demo, retries counted in tokens, and evaluation or judge calls running on every production request. See Logging, Metrics and Alerts and Token Budgets.

    Controls in order of impact: per-run token and dollar budgets that stop runaway runs; compression of history and tool outputs so tokens per step stay flat; prompt caching for stable prefixes; routing simple steps (classification, extraction) to a small model and reserving the strong model for judgement steps; caching tool results and retrieval within and across runs; and removing steps that evals show add nothing. See Fallbacks, Caching and Model Routing and Context Selection & Compression.

    Every cost change is validated against the golden set so quality does not silently drop.

    Full interview question, with follow-ups and red flags →
  3. What would a hand-off fidelity check look like?

    Show a strong answer

    Extract entities and constraints from the user request; assert they appear in each worker input; report the miss rate per hop.

    Full interview question, with follow-ups and red flags →