Module 5 · Lesson 4 · 15 min read
The supervisor and the hierarchical structure
Supervisor and Hierarchical Teams
Introduction
When the subtasks are varied and their path cannot be set in advance, we need an agent that distributes the work and follows it up: the supervisor. This lesson explains the supervisor's responsibilities, the difference between rule-based routing and model-based routing, and how to set limits for it that prevent looping and excessive cost.
Learning objectives
- Identify the responsibilities of the supervisor agent in the team
- Compare rule-based routing with dynamic routing by the language model
- Build a simple supervisor with a maximum number of steps and failure handling
- Judge when you need more than one hierarchical level
What is the supervisor?
The supervisor is an agent that does not do the core work itself but manages worker agents. Anthropic describes this pattern as "orchestrator-workers": the orchestrator splits the task dynamically, sends the parts to the workers, then collects their results. The difference from the simple parallel pattern is that the subtasks are not known in advance; the supervisor determines them according to the request.
The supervisor's main responsibilities:
- Decomposition: turning the request into clear subtasks.
- Routing: choosing the right worker for each subtask.
- Follow-up: checking each worker's result and acting on failure, by retrying, skipping or escalating to a human.
- Aggregation: merging the results into a consistent final answer.
- Control: respecting a maximum number of steps and a cost budget.
Rule-based or model-based routing?
The supervisor can choose the worker in two ways:
| Method | How it works | Advantages | Disadvantages |
|---|---|---|---|
| Rule-based | A table that links the task type to a worker | Deterministic, easy to test and cheap | Does not handle unexpected requests |
| LLM-based | The model reads the request and chooses the worker | Flexible with varied requests | May make mistakes, and costs extra calls |
The practical solution is often a mix: rules for the clear cases and the model for the ambiguous ones, with a closed list of workers that the supervisor cannot go beyond. In ready-made frameworks, CrewAI for example provides a hierarchical process Process.hierarchical alongside the sequential process (according to the official documentation, reviewed 18 November 2026).
A practical example: a study plan supervisor
A student asks: "Calculate the number of study hours if I study 3 subjects at 4 hours per subject, and define the terms agent and supervisor for me." The supervisor splits the request into three tasks: a calculation and two definitions. The following simulation uses rule-based routing and deterministic functions instead of models:
def calc_worker(task):
a, op, b = task["expr"]
if op not in ("+", "*"):
return {"ok": False, "error": "Unsupported operation"}
return {"ok": True, "value": a * b if op == "*" else a + b}
def glossary_worker(task):
glossary = {"agent": "A system that perceives its environment and takes actions to achieve a goal"}
term = task["term"]
if term not in glossary:
return {"ok": False, "error": f"Term not found: {term}"}
return {"ok": True, "value": glossary[term]}
ROUTES = {"calc": calc_worker, "define": glossary_worker}
def supervisor(subtasks, max_steps=5):
results, steps = {}, 0
for t in subtasks:
if steps >= max_steps:
results["note"] = "The supervisor stopped at the maximum number of steps"
break
steps += 1
worker = ROUTES.get(t["kind"])
if worker is None:
results[t["id"]] = "No suitable worker"
continue
out = worker(t)
results[t["id"]] = out["value"] if out["ok"] else "Could not: " + out["error"]
return results, steps
subtasks = [
{"id": "hours", "kind": "calc", "expr": (3, "*", 4)},
{"id": "agent", "kind": "define", "term": "agent"},
{"id": "supervisor", "kind": "define", "term": "supervisor"},
]
results, steps = supervisor(subtasks)
for k, v in results.items():
print(f"{k}: {v}")
print("Number of steps:", steps)Notice three design decisions: the supervisor does not break down when a worker fails to find a term, but records the reason clearly; if a task type comes in that has no worker, it does not invent one; and there is a maximum number of steps even if the subtasks increase.
When do we add a second hierarchical level?
When the supervisor manages a large number of workers with widely different skills, its instructions and context swell. The solution is to create sub-supervisors: a research supervisor managing the research agents, a writing supervisor managing the writers and proofreaders, and a general supervisor above them. But each level adds delay, calls and a new point of failure.
A practical rule: start with one level, and add a second level only when you notice that the supervisor's instructions have become long and branching, or that its routing decisions have started to decline in a way you can measure on a fixed set of examples.
Summary
The supervisor is an agent that splits the task, routes its parts to workers, follows up their results and collects them, within limits on steps and cost. Routing can rely on deterministic rules or on the language model, and a mix of the two is common. The supervisor must handle worker failures clearly without breaking down. Additional hierarchical levels help large teams but add delay and points of failure.
Terms
| Term | English | Definition |
|---|---|---|
| Supervisor | Supervisor | An agent that manages the workers, distributes tasks to them and collects their results |
| Worker agent | Worker Agent | An agent that carries out a specific subtask |
| Orchestrator and workers | Orchestrator-Workers | A pattern in which the orchestrator splits the task dynamically among workers |
| Routing | Routing | Choosing the right worker for each subtask |
| Escalation | Escalation | Handing the case to a human when it cannot be resolved automatically |
Review questions
- What is the difference between the orchestrator-workers pattern and the simple parallel pattern?
- When would you prefer rule-based routing to model-based routing?
- How should the supervisor behave if one of the workers fails?
- What signs indicate that you need a second hierarchical level?
References
- Building effective agents (Anthropic) www.anthropic.com Reviewed on 2026-11-18
- CrewAI Agents docs.crewai.com Reviewed on 2026-11-18
