Lesson 49.2 · 2 of 5 · 4 min read · Reviewed 24 Nov 2026
Hierarchical teams
By the end, you can
- Describe hierarchical agent teams.
- Know when extra layers are worth it.
The shape
[ director ]
/ \
[ research lead ] [ engineering lead ]
/ \ / \
[web] [papers] [code] [tests]
When it helps
- The task has distinct sub-domains, each needing its own plan.
- One supervisor would have to juggle too many workers or too much context.
- Different teams need different tools, permissionsPermission rule: An allow, ask or deny rule that controls which tools, commands or paths a coding agent may use. or models.
Costs
| Cost | Why |
|---|---|
| Latency | Each layer waits on the one below |
| Tokens | Every layer reads and writes summaries |
| Information loss | Summaries of summaries drop detail |
| Debugging | Failures hide deeper in the tree |
Practical advice
- Start with one supervisor (49.1). Add a layer only when tracesTrace: A record of everything that happened during one request or agent run, as a tree of timed steps. show the supervisor is overloaded.
- Define what each lead must return: a fixed format with findings, confidence and open questions.
- Let leads pass up references (file paths, document ids) rather than retyping content, so detail isn’t lost.
Key points
- Hierarchical teams stack supervisors: a top supervisor manages team leads, who manage workers.
- It mirrors an organisation chart and suits very large tasks with distinct sub-domains.
- Each layer adds latency, cost and a place where information gets lost.
- Most tasks need at most one supervisor layer; add more only when one supervisor is overwhelmed.
Count the cost of extra layers
Measure how a second supervisor layer changes latency and how much detail reaches the top.
You will have: A small tree simulator that compares a flat team with a two-layer hierarchy.
Steps
- Run the starter: nothing reaches the top yet.
- Write summarise() so each summary keeps only KEEP facts.
- Write the recursive run(): children in parallel, summaries passed up, one layer of latency added.
- Compare flat and two-layer results.
- Raise KEEP to 4 and note which cost goes away and which remains.
Done when
- Flat: 18 of 24 facts reach the top in 14 s.
- Two layers: 6 of 24 facts in 18 s.
- You can state when a second layer would be worth that cost.
Open in the Playground No API key needed.
Starter code (Python)
# Each supervisor layer adds latency and loses detail. Measure it.
WORKER_FACTS = 4 # facts each worker finds
KEEP = 3 # facts any summary keeps
WORKER_S, LAYER_S = 10, 4 # illustrative seconds for a worker, and for each supervisor layer
def summarise(facts):
# TODO: a summary keeps only the first KEEP facts
return facts
def run(tree):
"""tree is a worker name (str) or a list of subtrees under one supervisor. Returns (facts, seconds)."""
if isinstance(tree, str):
return [f"{tree}-fact{i}" for i in range(WORKER_FACTS)], WORKER_S
# TODO: run every child (they run in parallel, so take the slowest), summarise each child's facts,
# then add LAYER_S seconds for this supervisor
facts, slowest = [], 0
return facts, slowest
workers = [f"w{i}" for i in range(1, 7)]
flat = workers # one supervisor, six workers
two_layer = [workers[:3], workers[3:]] # top supervisor, two leads, three workers each
for name, tree in [("flat", flat), ("two layers", two_layer)]:
facts, secs = run(tree)
print(f"{name}: {len(facts)} of {WORKER_FACTS * len(workers)} facts reach the top, {secs} s")
Show a solution
# Each supervisor layer adds latency and loses detail. Measure it.
WORKER_FACTS = 4 # facts each worker finds
KEEP = 3 # facts any summary keeps
WORKER_S, LAYER_S = 10, 4 # illustrative seconds for a worker, and for each supervisor layer
def summarise(facts):
return facts[:KEEP]
def run(tree):
"""tree is a worker name (str) or a list of subtrees under one supervisor. Returns (facts, seconds)."""
if isinstance(tree, str):
return [f"{tree}-fact{i}" for i in range(WORKER_FACTS)], WORKER_S
facts, slowest = [], 0
for child in tree:
f, s = run(child)
facts += summarise(f)
slowest = max(slowest, s)
return facts, slowest + LAYER_S
workers = [f"w{i}" for i in range(1, 7)]
flat = workers # one supervisor, six workers
two_layer = [workers[:3], workers[3:]] # top supervisor, two leads, three workers each
for name, tree in [("flat", flat), ("two layers", two_layer)]:
facts, secs = run(tree)
print(f"{name}: {len(facts)} of {WORKER_FACTS * len(workers)} facts reach the top, {secs} s")