Hierarchical Supervisors (Orchestrator + Workers)
A supervisor plans and delegates; workers execute and report back — a robust pattern for complex tasks.
Hierarchical Supervisors (Orchestrator + Workers) is a free AI Agents lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AI Agents learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Supervisor Pattern
One "supervisor" agent decides what to do and delegates to specialized "worker" agents. Workers report back; supervisor synthesises.
Closer to how human teams work than free-form conversations.
Structure
Two levels (sometimes more):
- Supervisor — sees the user query, breaks it down, picks workers, integrates results
- Workers — specialized agents (research, code, math) each with their own tools and prompts
Why Hierarchy?
- Cleaner reasoning — supervisor sees the big picture
- Specialization — each worker is small and focused
- Easier to evaluate — test workers independently
- Easier to add new capabilities — just register a new worker
LangGraph Implementation
from langgraph.graph import StateGraph, END
from typing import TypedDict, Annotated
import operator
class State(TypedDict):
messages: Annotated[list, operator.add]
next: str
def supervisor(state):
# Ask LLM which worker should handle this
decision = supervisor_llm.invoke(state['messages']).content # 'researcher' / 'coder' / 'FINISH'
return {'next': decision}
def researcher(state):
result = research_agent.run(state['messages'][-1].content)
return {'messages': [{'role': 'tool', 'content': result}], 'next': 'supervisor'}
def coder(state):
result = code_agent.run(state['messages'][-1].content)
return {'messages': [{'role': 'tool', 'content': result}], 'next': 'supervisor'}Wiring the Graph
g = StateGraph(State)
g.add_node('supervisor', supervisor)
g.add_node('researcher', researcher)
g.add_node('coder', coder)
g.set_entry_point('supervisor')
g.add_conditional_edges(
'supervisor',
lambda s: s['next'],
{'researcher': 'researcher', 'coder': 'coder', 'FINISH': END}
)
g.add_edge('researcher', 'supervisor')
g.add_edge('coder', 'supervisor')
app = g.compile()Worker Independence
Each worker is a self-contained mini-agent. Build and test each in isolation; compose them under the supervisor.
Worker Tool Sets
Limit each worker to ONLY the tools they need:
- Researcher — search, fetch
- Coder — read_file, write_file, run_python
- Database — list_tables, run_sql
Cleaner tool descriptions; less confusion.
Communication Format
Workers return structured summaries to the supervisor — not full transcripts. Saves tokens, easier for supervisor to integrate:
class WorkerResult(BaseModel):
summary: str
citations: list[str]
next_step_suggestion: str = ''Termination
Supervisor decides when to stop. Typically:
- Confidence above threshold
- Task complete signal from a worker
- Step counter exceeded
Multi-Level Hierarchies
For very complex tasks, add a third layer: a "team lead" supervisor for engineering, another for research, etc. Each delegates to per-area workers.
Cost Profile
Each supervisor decision is an LLM call. Each worker is its own loop. Total cost ~ N_supervisor_decisions × cost_per_decision + N_worker_loops × cost_per_loop.
When to Use
- Complex tasks with clear sub-domains
- Tasks needing different prompting styles per step
- Systems where you want to add capabilities incrementally
Anti-Patterns
- Supervisor doing all the actual work — defeats the purpose
- Workers calling other workers without supervisor knowing — loses control
- Too many workers (>10) — supervisor selection gets unreliable
Supervisor Role
What is the supervisor's main job in this pattern?
Recap
Supervisor + workers > one big agent. Each worker is small, focused, independently testable. Supervisor decides who works on what.
Frequently asked questions
Is the “Hierarchical Supervisors (Orchestrator + Workers)” lesson free?
Yes — the full text of “Hierarchical Supervisors (Orchestrator + Workers)” is free to read here on the web, and the AI Agents course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AI Agents course, upgrade to CoddyKit PRO.
What will I learn in “Hierarchical Supervisors (Orchestrator + Workers)”?
A supervisor plans and delegates; workers execute and report back — a robust pattern for complex tasks. You practise AI Agents with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AI Agents?
No prior experience is required. AI Agents on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Hierarchical Supervisors (Orchestrator + Workers)” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AI Agents lesson?
Yes. Every AI Agents lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Conversation-Based Multi-Agent (AutoGen)
- Hierarchical Supervisors (Orchestrator + Workers)
- Agent Roles and Specialisations
- Communication Protocols (Message Buses)