Lesson 5.2: The orchestrator and worker pattern
Learn the orchestrator and worker pattern: how a lead agent splits a job, writes clear briefs, handles failed workers and combines results.
By the end of this lesson you will be able to describe the orchestrator and worker pattern, break a job into pieces that workers can do on their own, write a brief a worker can act on without guessing, decide how many workers to use, handle workers that fail or return poor results, and combine what comes back. You will work out that a lead reading eight worker results holds about 12,000 tokens where doing the work itself would put 164,000 in its context, and that five workers each succeeding 90 per cent of the time all succeed only 59 per cent of the time, rising to 95 per cent if each is allowed one retry. You should have read Lesson 5.1, which explains when to split work at all. No code is needed. The mathematics is multiplication and powers.
Lesson 5.1 gave the reasons to split work. This lesson takes the most common shape of a split and builds it carefully. In the orchestrator and worker pattern, one agent, the orchestrator or lead, receives the job. It does not do the detailed work itself. It decides how to divide the job, starts workers, gives each a brief, waits for results, checks them and combines them into one answer. The workers are sub-agents. Each does one piece in its own clean context and reports back.
The pattern is simple to describe and easy to get wrong. Most failures in it come from three places: a brief that left something out, a worker that failed quietly, and a combining step that lost detail. This lesson is about those three.
The roles
The orchestrator owns the goal. It knows what the user asked for, what a good answer looks like and what the whole job needs. Its context is deliberately light. It holds the request, the plan, the briefs it has sent and the short results that return. It never holds the raw material the workers read. Its tools are few: start a worker, read results, and perhaps a simple way to record progress.
The workers own pieces. Each knows only its brief. It does not know the user's original wording, the other workers or the final shape of the answer, unless the brief says so. It has the tools its piece needs and no others. It returns a result in the format the brief asked for.
This separation is the point. The lead keeps the whole in view and stays small. The workers go deep and are discarded. If the lead starts doing detailed work itself, its context fills and the benefit is lost. If a worker starts to wander into the whole goal, it duplicates the lead's job.
Step one: decomposing the job
The lead's first and hardest task is deciding the pieces. Three rules help.
Each piece should be able to succeed or fail on its own. A worker asked to "research competitor A" can be judged complete. A worker asked to "do the second half of the analysis" cannot, because it depends on the first half.
Pieces should not overlap. If two workers read the same documents and draw conclusions, you pay twice and may get two answers that disagree. Divide by a clear boundary, such as one competitor each, one region each, one set of invoices each or one question each.
Pieces should be about the same size. Time is set by the slowest worker, as Lesson 5.1 showed. If one piece is five times bigger, split it again.
There are two ways to decompose. In a fixed decomposition your code decides the pieces in advance: one worker per invoice batch, one per region. This is predictable and easy to test. In a dynamic decomposition the lead reads the request and decides the pieces itself: "this question has three parts, so I will start three workers". This is flexible but less predictable. A common middle path is a fixed set of kinds of worker, such as a searcher, a reader and a checker, with the lead choosing how many of each.
A useful guide to size is the effort a piece needs. A simple lookup needs one worker making a handful of calls. A comparison of several things may need a few workers. A broad research question may need many. If you let the lead choose the number, give it a rule in its instructions, such as "use one worker for a simple fact, at most three for a comparison and at most eight for a broad question". Without such a rule, a lead tends to either start too few or far too many.
Step two: writing the brief
The brief is the only thing a worker knows. A worker that does not understand its task will do something plausible and wrong, and you will not see why. A good brief has seven parts.
Part · What it says · ExampleGoal · What the piece is for, in one sentence · "Find out whether Supplier S7's three latest invoices match their purchase orders."
Scope · What is in and out · "Only the three invoices listed. Do not review other suppliers."
Inputs · What the worker has been given · "Invoice IDs 8841, 8852 and 8869. The purchase order system is available."
Tools and sources · What it may use · "Use the purchase order lookup and the invoice viewer. Do not use the web."
Output format · The exact shape of the reply · "Return a table: invoice ID, PO found (yes or no), amount match (yes or no), one-line note."
Limits · Stop rules and budget · "Use at most 12 tool calls. If a record is missing, say so and stop."
Context the worker lacks · Anything the lead knows that matters · "Amounts differing by less than ₹10 are rounding, not errors."
Compare a poor brief and a good one for the same piece. Poor: "Check Supplier S7's invoices." The worker does not know which invoices, what to check, what to return or when to stop. It may check all of them, or the wrong ones, and reply in prose that the lead cannot easily merge. Good: the same task written with the seven parts above. The good brief is longer, but it is the difference between a usable result and a guess.
Two habits make briefs better. First, say what done looks like. A worker does not know when to stop unless you tell it. Second, ask for the evidence along with the answer. "Return the verdict and the record IDs you used" lets the lead, or a later check, confirm the result. A worker that returns only "all fine" cannot be checked.
Step three: waiting and handling failure
Workers fail in ordinary ways. A tool times out. The worker runs out of steps. It returns a result in the wrong format. It misreads the brief. It reports success when it has not succeeded. The lead must expect all of these.
Let the lead's design settle five questions in advance.
Timeouts. How long will the lead wait for a worker? If it waits without limit, one stuck worker stops the whole job. Set a time limit and a step limit on each worker.
Retries. If a worker fails, will the lead try again? For tool errors and timeouts, a retry often works. For a misunderstood brief, a retry with the same brief will fail the same way. Retry with the same brief for temporary faults and with a clearer brief, adding what went wrong, for misunderstandings. Cap the retries.
Partial results. If one of eight workers fails after retries, should the lead stop, or continue and mark the gap? For a report, a clearly marked gap is often better than no report. For a payment run, stopping is safer. Decide by what a missing piece would cost.
Format checks. Before the lead uses a result, a small piece of code should confirm it has the required fields. Rejecting a malformed result at once is far cheaper than finding it in the final answer.
Honest reporting. Tell workers that "I could not find this" and "I am not sure" are acceptable answers, and ask them to say so. A worker that feels it must produce a result will sometimes invent one.
Predict first: five workers run side by side, and each one succeeds 90 times in 100. The lead needs all five. What is the chance that all five succeed on the first attempt? And if each worker may retry once, so that it fails only when both attempts fail, what is it then? Work out both before reading on.
All five succeed with probability 0.9 to the power 5, which is 0.59. That is, the lead is missing at least one piece in four runs out of ten. With one retry, a worker fails only if both attempts fail, which has probability 0.1 × 0.1 = 0.01, so each worker succeeds 99 times in 100. All five succeed with probability 0.99⁵ = 0.951. The retry cost little: on average each worker makes 1.1 attempts, since a retry is needed only on the 10 per cent of first attempts that fail, so five workers make about 5.5 attempts in place of 5. A 10 per cent increase in worker effort buys a rise in reliability from 59 to 95 per cent. With ten workers the numbers are starker: 0.9¹⁰ = 35 per cent without retries and 0.99¹⁰ = 90 per cent with one.
This calculation assumes failures are independent and that a retry is as likely to work as the first attempt. Neither is quite true. If a tool is down, every retry fails, and if a brief is unclear, retries repeat the mistake. But the shape holds: a modest number of retries removes most chance failures.
Step four: combining the results
When the results arrive, the lead must turn them into one answer. This step looks easy and is where detail is lost. Four habits protect it.
Keep results in a fixed format. If every worker returns the same table or the same fields, the lead can merge them mostly by code. A fixed format also makes it obvious when a field is missing. When results are free prose, the lead must interpret each one, and different workers phrase the same thing differently.
Merge by code where you can. Counting, sorting, removing duplicates and totalling are jobs for ordinary code, not for the model. Ask the model to judge, summarise and explain, and let code do arithmetic and bookkeeping. A model asked to add up forty numbers from eight worker tables will sometimes get it wrong. Code will not.
Watch for conflicts. Two workers may report different values for the same thing, for example two sources giving different figures for a supplier's bank account. The lead should not quietly pick one. It should flag the conflict, say which sources disagree and, where possible, ask a further worker or a person to settle it.
Keep the evidence. The final answer should say where each claim came from. If the lead has the record IDs or source links from the workers, it can pass them on. If it does not, the user cannot check anything. This is also what lets a reviewer, human or agent, verify the answer later.
Why the lead's context stays small
The main benefit of the pattern is what the lead does not read. Suppose a job has eight pieces, each needing about 20,000 tokens of raw reading and tool results. If a single agent did all of it, its context would end up holding 160,000 tokens of that material, plus its own 4,000 tokens of instructions, so 164,000. With workers, the lead holds its 4,000 tokens, eight briefs of about 400 tokens and eight results of about 600 tokens, so 4,000 + 8 × (400 + 600) = 12,000 tokens. The lead's context is about 7 per cent of the size. That means each of its steps is cheaper and faster and less likely to confuse one piece with another. The workers still read the 160,000 tokens between them, but each reads only its own 20,000, and discards it.
How many workers?
More workers is not always better. Four limits apply.
The work. There must be enough independent pieces. Eight workers cannot share a job with three pieces.
The rate limits. Your model provider limits how many requests you can send at once. Twenty workers starting together may hit the limit and be rejected, which causes the failures and retries above. Cap the number running at once, and queue the rest.
The cost. Each worker pays for its fixed block. Doubling the workers for a job with a long fixed block can raise the bill with no extra speed, if the slowest piece sets the time.
The lead's capacity. The lead must read every result. Fifty results of 600 tokens each is 30,000 tokens, and the lead's quality at combining them falls as the pile grows. Beyond about ten workers, consider a middle layer: sub-leads that each combine a group's results into one. This adds a level and its hand-offs, so use it only when you must.
A sensible default for most jobs is three to eight workers, a cap on how many run at once and a retry limit of one or two.
Three worked examples
Example 1: weekly invoice review
The finance agent receives 40 invoices. A fixed decomposition splits them into eight batches of five. Each worker receives a brief with the invoice IDs, the three checks to run, the rounding rule and the table format to return. The lead's code validates each table, merges them, counts exceptions and asks the model to write a short summary naming the three biggest issues and the suppliers involved. One batch times out and is retried once. Another returns a table with a missing column and is rejected and retried with a note about the format. The final summary says all 40 were checked, which the lead knows because the merged table has 40 rows.
Example 2: a market research question
A manager asks, "How are Indian lenders using gold loans against unsecured credit?" The lead plans three workers: one to gather regulator and industry data, one to read the latest results of listed lenders and one to find recent news. It tells each which sources to prefer and to return five bullet findings with a source link each. It does not let the three read each other's work. When the results return, two disagree about the growth rate of gold loan balances. The lead flags the conflict, starts a fourth worker with the two sources and the question "which figure is right, and why?", and includes the answer with both sources in the report. Without that step, the report would have quietly used one figure.
Example 3: a dynamic job
A user asks for help preparing for a customer meeting. The lead reads the request and sees four needs: the customer's recent activity, open issues, relevant product news and suggested talking points. It starts three workers for the first three, since each is independent, and writes the talking points itself once their results return, since that piece depends on all of them. This shows the lead choosing both what to delegate and what to keep. It keeps the piece that needs the whole picture.
A design worksheet for the pattern
1. Write the goal and the form of the final answer.
2. List the pieces. For each, check that it can succeed alone, does not overlap with another and is of similar size.
3. Choose fixed or dynamic decomposition, and if dynamic, write the rule for how many workers.
4. Write the brief template with the seven parts.
5. Write the result format, and the code that checks it.
6. Set the time limit, step limit and retry limit for each worker.
7. Decide what the lead does if a worker fails after retries.
8. Decide how the lead merges results, which parts code does, and how conflicts are handled.
9. Cap how many workers run at once.
10. Plan the test: run the same ten jobs against a single agent and compare.
Common mistakes
The lead doing the detailed work. It fills its context and loses the benefit of the pattern. Keep the lead's tools few.
Vague briefs. A worker needs the goal, scope, inputs, tools, format, limits and missing context.
Overlapping pieces. Two workers on the same material cost twice and may disagree.
Unbalanced pieces. One huge piece sets the time for everyone.
No format for results. Free prose is hard to merge and to check.
Letting the model do arithmetic and bookkeeping. Use code.
Ignoring failure. Set timeouts, retries and a plan for partial results.
Quietly resolving conflicts. Flag them and settle them with evidence.
Too many workers at once. Respect rate limits, cost and the lead's capacity.
Never comparing with a single agent. The pattern earns its place only if it does better.
Key takeaways
In the orchestrator and worker pattern, a light lead agent divides a job, briefs workers, handles failures and combines results. Each worker does one piece in its own clean context.
Good pieces can succeed or fail alone, do not overlap and are of similar size. Decompose by a fixed rule where possible, and give the lead a rule for how many workers to use when it decides.
A brief has seven parts: goal, scope, inputs, tools, output format, limits and the context the worker lacks. Ask for evidence along with answers.
Plan for failure. Five workers at 90 per cent all succeed 59 per cent of the time, and 95 per cent with one retry each, for about 10 per cent more effort.
Combine with fixed formats, code for arithmetic and bookkeeping, flagged conflicts and kept evidence.
The lead's context stays small: 12,000 tokens against 164,000 in the lesson's example.
Limit workers by the work, rate limits, cost and the lead's ability to read results. Three to eight is a sound default.
Check yourself
1. Name the three rules for a good piece of work to hand to a worker.
It can succeed or fail on its own, it does not overlap with other pieces and it is of similar size to them.
2. List four of the seven parts of a brief.
Any four of: goal, scope, inputs, tools and sources, output format, limits, and context the worker lacks.
3. Ten workers each succeed 90 per cent of the time on an attempt. What is the chance all ten succeed with no retries? With one retry each?
0.9¹⁰ = 0.349, about 35 per cent. With one retry each worker succeeds 99 per cent of the time, and 0.99¹⁰ = 0.904, about 90 per cent.
4. Why should code, and not the model, add up figures returned by workers?
Models sometimes make arithmetic errors, especially over many numbers. Code is exact and cheap.
5. Two workers return different values for the same fact. What should the lead do?
Flag the conflict, name the sources, and settle it with a further check or a person, instead of quietly choosing one.
6. Why is it unwise to start thirty workers at once?
Rate limits may reject requests, each worker pays for its fixed block, and the lead's quality falls as it reads too many results. Cap the number running at once.
Try this
Set aside seventy-five minutes.
1. Take a job with at least four independent parts. Write it in two sentences, with the form of the final answer.
2. List the pieces and check each against the three rules. Fix any that overlap or are lopsided.
3. Write the seven-part brief for one piece, then adapt it for the others.
4. Define the result format as a table or a short list of fields, and write down the checks code will run on it.
5. Choose the time limit, step limit and retry limit, and decide what happens if a worker still fails.
6. Use the simulators to estimate the chance that every worker returns and how small the lead's context stays.
7. Write how the lead will merge results, which parts are code, and how conflicts will be handled.
A good result is a design document for one orchestrator and its workers: the pieces, the brief template, the result format, the failure rules and the merge steps. Lesson 5.3 turns to what happens between agents: how work is handed over, routed and delegated.
Tags: Agentic AI Orchestrator pattern Sub-agents Task decomposition Agent design