Lesson 4 of 7 · Patterns
Orchestrator-Workers
The orchestrator-workers pattern: a lead LLM splits a task into sub-tasks at run time, workers handle each and results are combined. When it beats a workflow.
- 4 min read
- Intermediate
- Reviewed
- Explain the orchestrator-workers pattern
- Contrast it with sectioning, where the parts are fixed in advance
- Combine worker results into one answer
- Limit and check what an orchestrator can plan
When you can't list the parts in advance
Sectioning works when you know the parts beforehand. But how many files need changing for a rename? Which sources need reading for a research question? It depends on the request.
A rename across a codebase
# ---- Orchestrator-workers: a lead model decides the sub-tasks at run time ----
def orchestrator(request):
"""Stands in for an LLM that reads the request and splits it into sub-tasks.
Unlike a fixed workflow, the list depends on the request."""
if "rename" in request:
return [{"worker": "code", "task": f"update {f}"} for f in ["billing.py", "invoice.py", "tests/test_billing.py"]] \
+ [{"worker": "docs", "task": "update README section 'Billing'"}]
return [{"worker": "code", "task": "update main.py"}]
def code_worker(task):
return f"{task}: 3 lines changed"
def docs_worker(task):
return f"{task}: 1 paragraph rewritten"
WORKERS = {"code": code_worker, "docs": docs_worker}
def synthesise(results):
"""Stands in for the orchestrator's final call that combines the workers' results."""
return f"Renamed the function across {len(results)} places:\n" + "\n".join(f" - {r}" for r in results)
request = "Please rename calculate_total to compute_invoice_total everywhere"
subtasks = orchestrator(request)
print("Orchestrator planned", len(subtasks), "sub-tasks")
results = [WORKERS[s["worker"]](s["task"]) for s in subtasks] # independent: can run in parallel
print(synthesise(results))The orchestrator (a stand-in for a model here) looked at the request and produced four sub-tasks: three code files and one documentation section. A different request would produce a different list, which is the point of the pattern. The workers are simple and independent, so they can run in parallel, and a final synthesis step combines their results into one summary.
Keeping orchestrators in check
Because the orchestrator invents the plan, constrain it:
- Allowed workers only: it can assign sub-tasks only to worker types you defined.
- Limits: a maximum number of sub-tasks, and a budget for the whole run.
- Validate the plan before running it (as in the plan-and-execute lesson).
- Check worker results before synthesis; one failed worker shouldn't silently disappear from the summary.
Common mistakes
Summarise an orchestrator's plan: how much work goes to each kind of worker.
subtasks = [
{"worker": "search", "task": "find 2026 EV sales figures"},
{"worker": "search", "task": "find charging network growth"},
{"worker": "analyst", "task": "compare with 2025"},
{"worker": "writer", "task": "draft summary"},
]
# The orchestrator produced these sub-tasks. Count how many each worker type gets,
# and print them sorted by worker name, like:
# analyst: 1
What is the key difference between orchestrator-workers and sectioning?
Summary
- An orchestrator decides the sub-tasks at run time; workers handle them; a synthesis step combines results.
- It suits tasks whose parts depend on the request, such as code changes and research.
- Constrain it: allowed workers, limits, plan validation and result checks.
- It sits between fixed workflows and full multi-agent systems.
Next: evaluator-optimiser loops.
Finished reading? Tick it off to track your progress.