Planning and Multi-Agent Systems
How to make an agent write a plan before it acts, how to split a task across several agents, and when a single agent is the better choice.
On this page
Planning means that an agent writes down the steps of a task before it starts using tools, and then keeps that list up to date as it works. A multi-agent system splits a task between several agents, usually one orchestrator that hands parts of the work to workers. Both techniques exist because an agent that works through a long task in a single conversation tends to lose track of the request, and its history fills with material it no longer needs (see Context Rot).
Without either technique, a long task goes wrong in a typical way. An agent asked to compare how three frameworks handle security updates reads the pages for the first, then the second, then the third. By the end its history holds dozens of similar pages, and the report credits one framework with a support period that belongs to another. No single step was wrong. The history simply became too long to keep three similar sets of facts apart.
How planning works
An agent in the agent loop chooses one step at a time, based only on what is in its history. On a long task it can follow an interesting lead, forget part of the request, or run out of steps with a part of the task untouched. A plan fixes this by putting the whole task in the history as a short numbered list. The agent marks steps as done, so at every turn it can see what has been finished and what is left.
The plan does three things. It stops the agent from forgetting part of the task, it lets a person read the approach and correct it before any work is spent, and it shows progress while the agent runs. A plan is only a guess made before the agent has seen any results. If Framework B turns out to have no security page, the agent has to rewrite the remaining steps instead of continuing with a step that cannot work.
Plan variants
Plan once, then execute
The agent writes the full plan at the start and follows it step by step. This works when the steps are known in advance and the results will not change them, as in the comparison above. It is cheap and easy to review, because a person can approve the plan before anything runs. It fails when an early result invalidates later steps, because the agent keeps following a plan that no longer fits.
Plan and revise as you go
The agent writes a plan, then restates it after each step with finished steps marked and the remaining steps changed if needed. This is what the prompt above asks for, and it is the better default for any task where the agent will discover things along the way, such as debugging or research. The cost is a few extra tokens per turn. The agent also needs to be told that rewriting the plan is expected. Otherwise it tends to keep the original plan even after a result has shown that a step is wrong.
Plan approved by a person
The agent writes the plan and stops until a person approves it. Use this when the task will change something that is hard to undo, such as editing many files or sending messages, because reviewing five lines is much cheaper than undoing a wrong action. It also means a person has to be available, so it does not suit unattended runs.
How several agents work together
Planning does not stop the pages for all three frameworks from piling up in one history. Splitting the work does. An orchestrator agent breaks the task into parts and gives each part to a worker agent. Each worker starts with an empty history and only its own part, does the reading, and sends back a short summary. The orchestrator never sees the raw pages.
1The orchestrator O splits the task into three independent parts, one per framework, for workers A, B and C. Its history holds only the task and the plan.
2Each worker receives a brief that contains the goal, one framework and the format of the reply. That is everything it knows. The three workers run at the same time.
3Each worker reads many pages about its own framework, so its history contains nothing about the other two and facts from different frameworks cannot be mixed up.
4Each worker replies with a short summary of three facts, each with a source, and its long history is thrown away. The orchestrator now holds the task, the plan and three short summaries.
5The orchestrator writes the comparison from the summaries alone. A single agent doing the same job would have had all the raw pages for all three frameworks in one history.
Splitting does not reduce the total amount of text the agents read. The briefs, the summaries and any repeated searches usually add more than the shorter histories save. What it gives you is a focused history for each agent and the ability to run the workers in parallel. Each worker is an ordinaryEach worker is an ordinary agent loop with its own goal (see The Agent Loop), so the orchestration code is short:
// runWorker(brief) runs one agent loop and returns its final answer.
function orchestrate(goal, parts, runWorker) {
const summaries = parts.map((part) =>
runWorker(`Overall goal: ${goal}\nYour part: ${part}\n` +
"Reply with at most 5 bullet points, each with a source link."));
return summaries; // in a real app, run the workers in parallel
}
const fakeWorker = (brief) => `summary of: ${brief.split("\n")[1]}`;
console.log(orchestrate("Compare security updates",
["Framework A", "Framework B", "Framework C"], fakeWorker));
// [ 'summary of: Your part: Framework A', ... ]# run_worker(brief) runs one agent loop and returns its final answer.
def orchestrate(goal, parts, run_worker):
summaries = [
run_worker(f"Overall goal: {goal}\nYour part: {part}\n"
"Reply with at most 5 bullet points, each with a source link.")
for part in parts
]
return summaries # in a real app, run the workers in parallel
fake_worker = lambda brief: f"summary of: {brief.splitlines()[1]}"
print(orchestrate("Compare security updates",
["Framework A", "Framework B", "Framework C"], fake_worker))
# ['summary of: Your part: Framework A', ...]The brief is the only thing the worker knows, so it has to contain the goal, the boundaries of the worker's part and the shape of the reply. A brief that says only "Research Framework B" produces a vague essay that the orchestrator cannot combine with the others.
Multi-agent patterns
Orchestrator and workers
This is the pattern shown above. The orchestrator splits the task, the workers each handle one independent part, and the orchestrator merges the summaries. It suits research over several sources, checks that repeat over many files, and any job whose parts can be done without knowing the others' results. It fails when the split is wrong. If the parts depend on each other, the workers make incompatible choices, and the orchestrator has to reconcile them without having seen the underlying material.
Several attempts at the same task
Here every agent gets the same task, usually with a different approach or a different random seed, and something picks the best result: a test suite, a scoring prompt or a person. This is useful when quality varies a lot between runs and a result can be checked cheaply, for example code that either passes the tests or does not. It costs the full price of every attempt, and it only helps if the selection step is reliable. A weak judge picks a confident wrong answer as easily as a right one.
A worker and a reviewer
One agent produces a draft, and a second agent with a fresh context checks it against the original request and a list of criteria. The reviewer does not share the author's reasoning, so it is less likely to accept a mistake just because the author argued for it. This works best when the reviewer is given something specific to check, such as "every claim has a source". A reviewer told only to "check the work" tends to approve it. The reviewer can also be wrong, so it reduces errors without removing them.
A pipeline of specialists
Each agent handles one stage and passes a structured result to the next, for example extract, then classify, then write. Each stage can have a short prompt and its own tools. It is easy to test one stage at a time. The weakness is that an error in an early stage passes silently through every later one, so each handoff should be a defined format that can be validated.
What goes wrong with workers
A worker can fail, return nothing useful, or return a summary that contradicts another worker's. The orchestrator has to decide what to do in each case, and the decision belongs in its prompt: retry the part once with a clearer brief, report the part as missing, or ask a person. An orchestrator that is not told this tends to fill the gap with a guess and present it as a finding.
Workers should also have limits. Give each one a maximum number of steps, and give the orchestrator a maximum number of workers it may start. Without limits, a confused orchestrator can keep starting workers for the same part.
Because the orchestrator sees only summaries, it cannot notice a worker that read the wrong page. This is why each claim needs a source, and why a final check on a few claims, by a person or by a reviewer agent, is worth the cost on anything important.
When one agent is better
Multi-agent systems cost more in total, lose any context that is not written into the handoff, and give mistakes more places to hide. A single agent with a plan is simpler to build and much simpler to debug, because the whole run is in one history. Good reasons to split are separate topics, separate files, or separate approaches from which you keep the best. Research assistants often use parallel workers to read sources. Coding agents more often stay single, because edits to one codebase depend on each other.
Pitfalls
What this changes in practice
For a task that takes more than a few tool calls, ask the agent for a short plan first and tell it to update the plan as it learns. For a task that touches things you cannot easily undo, read the plan before the agent starts. Split into workers only when you can name the parts, the parts do not depend on each other, and one history would hold more than the agent can keep straight. When you do split, spend your effort on the briefs: state the goal, the part's boundaries, what to do when a fact is missing, and the exact format of the reply.
The orchestrator sends this brief, and the worker returns a long project history with no dates. Rewrite it so the summary fits the final table.
Show a sample answer
This brief works because the worker knows how its output will be used, which facts to find, where to look, what to do when a fact is missing and what shape the reply must have. It is written the way you would write for someone who cannot ask questions, as described in Writing a Good Brief.
Check yourself
Why do workers help an orchestrator write a more accurate report?
Which task is the best fit for several worker agents?
Halfway through a task, a result shows that step 4 of the plan is no longer needed. What should the agent do?
What to practise next
Continue with Evals to measure whether an agent does its job, and then Guardrails to limit what it can break.