Skip to content
AgenticAIWiki
  1. Learn
  2. Part 8
  3. 41. Workflow patterns
  4. 41.4

Lesson 41.4 · 4 of 5 · 6 min read · Reviewed 24 Nov 2026

Orchestrator-workers

By the end, you can

  • Explain who decides the subtasks in orchestrator-workers.
  • Choose between parallelization and orchestrator-workers for a task.

In orchestrator-workersOrchestrator-workers: A pattern where a lead model breaks a task into subtasks, hands them to worker calls and combines the results., a central LLMLarge language model (LLM): A neural network trained on large amounts of text to predict the next token, which lets it generate and transform language. reads the task, decides what subtasks are needed, hands them to worker calls, and then combines the results.

Example

“Rename the user_id field to account_id across the service.” The orchestrator inspects the request and decides it needs to edit the API layer, the database layer and the tests. A different request might need one worker, or seven. Nobody could have hard-coded that list.

How it differs from parallelization

The shapes look alike in the diagram, but the decision is made in a different place:

Parallelization Orchestrator-workers
Who splits the task Your code, written in advance An LLM, at run time
Number of subtasks Fixed Varies with the input

Design notes

  • Give workers only the context they need and a clear output format, so the synthesis step can combine them.
  • Decide how a failed worker is reported to the orchestrator, rather than silently dropping its part.
  • This pattern is a short step from a multi-agent systemMulti-agent system: A design where several agents with different roles or contexts work together on a task. with subagentsSubagent: A separate agent instance, with its own context and instructions, that a main agent delegates a task to. (chapter 43).

Key points

  • An orchestrator LLM decides the subtasks at run time.
  • Workers handle subtasks; a final step synthesizes their results.
  • Use it when the split depends on the input and cannot be hard-coded.
Hands-on labRuns in the Playground

Let an orchestrator plan the workers

Build orchestrator-workers where the number of subtasks depends on the request, with a shared worker output format and failed workers reported.

You will have: An orchestrator, a worker and a synthesiser that handle two rename requests needing different numbers of workers.

Steps

  1. Read the fake codebase: files grouped by layer, some mentioning user_id.
  2. Write plan(request) as the stand-in orchestrator: decide which layers need a worker from what the request and codebase contain.
  3. Write worker(layer) that returns the shared format {layer, status, files_changed}.
  4. Make one worker fail and make sure the synthesis reports it rather than dropping it.
  5. Run two requests and print the plan and the combined result for each.

Done when

  • The user_id rename plans 3 workers; the invoice_ref rename plans 1.
  • Every worker result has the same keys.
  • The failed worker appears in the final summary as failed.

Open in the Playground No API key needed.

Starter code (Python)
codebase = {"api": ["routes.py uses user_id", "schemas.py uses user_id"], "db": ["models.py uses user_id"],
            "tests": ["test_api.py uses user_id"], "billing": ["invoice.py uses invoice_ref"]}

def plan(field):
    # TODO: the orchestrator picks only the layers whose files mention the field
    return list(codebase)

def worker(layer, field):
    # TODO: return {"layer": ..., "status": "ok" | "failed", "files_changed": [...]}; make "tests" fail
    return {}

def synthesise(results):
    # TODO: summarise changed files and list failed layers
    return results

for field in ["user_id", "invoice_ref"]:
    layers = plan(field)
    print(field, "plan:", layers)
    print("  ", synthesise([worker(l, field) for l in layers]))
Show a solution
codebase = {"api": ["routes.py uses user_id", "schemas.py uses user_id"], "db": ["models.py uses user_id"],
            "tests": ["test_api.py uses user_id"], "billing": ["invoice.py uses invoice_ref"]}

def plan(field):
    return [layer for layer, files in codebase.items() if any(field in f for f in files)]

def worker(layer, field):
    if layer == "tests":
        return {"layer": layer, "status": "failed", "files_changed": [], "error": "test runner timed out"}
    changed = [f.split()[0] for f in codebase[layer] if field in f]
    return {"layer": layer, "status": "ok", "files_changed": changed}

def synthesise(results):
    changed = [f for r in results for f in r["files_changed"]]
    failed = [f"{r['layer']} ({r['error']})" for r in results if r["status"] == "failed"]
    return f"changed {changed}; failed: {failed or 'none'}"

for field in ["user_id", "invoice_ref"]:
    layers = plan(field)
    print(f"{field}: {len(layers)} workers {layers}")
    results = [worker(l, field) for l in layers]
    assert all(set(r) >= {"layer", "status", "files_changed"} for r in results)
    print("  ", synthesise(results))
Quick checkA code change needs a different number of file edits depending on the request. Which pattern fits?
How sure are you?
Pick an answer and how sure you are