Planning and Multi-Agent Systems

Help an agent with a big task by making it plan first, and split work across agents with fresh context, plus the costs and when one agent is better.

15 minLesson 4 of 6
On this page
  1. Plan first, then act
  2. Several agents, each with a fresh context
  3. When one agent is better
  4. Try it yourself
  5. Common mistakes
  6. Check yourself
  7. What to practise next

You ask an agent to compare how three open-source web frameworks handle security updates: how fast they ship fixes, how they announce them, and how long old versions get patches. It reads Framework A's documentation, then B's, then C's. By the time it writes the report, its history holds dozens of pages. The report says Framework A supports old versions for two years. That was Framework C.

Nothing was wrong with any single step. The history got too long for the model to keep three similar sets of facts apart, a problem Context Rot looks at closely. There are two tools for it: make the agent plan, and split the work across several agents that each see less.

Plan first, then act

An agent running the agent loop picks one step at a time. On a long task that leads to drift: it follows an interesting lead, forgets a part of the request, and runs out of steps with one framework still unread.

The fix is cheap. Before any tool call, ask the model for a short plan. Keep that plan in the history as a checklist. Have the agent tick items off, and rewrite the plan when it learns something new.

Asking for a plan before actingIllustrative example. Real replies vary.
System prompt
Before using any tool, write a numbered plan of at most 6 steps. After each step, restate the plan with finished steps marked [done]. If a result changes what you need to do, rewrite the remaining steps and say why.
You
Compare how Framework A, B and C handle security updates: time to ship a fix, how fixes are announced, and how long old versions are supported. Cite a page for each claim.
Model
Plan: 1. Find Framework A's security policy page and note the three facts. 2. Same for Framework B. 3. Same for Framework C. 4. For any fact a policy page does not state, check release notes for the last 3 security fixes. 5. Build a table: framework × three facts, with a source per cell. 6. Write a short comparison under the table. Starting step 1.

The checklist makes it harder to forget part of the task. A person can read it and correct the approach before any work is done. And you can see progress: "step 4 of 6" means something.

The plan is a guess, not a contract. Step 4 exists because the agent expects some pages to be incomplete. If Framework B turns out to have no security page at all, the right move is to rewrite the remaining steps, not to follow the old ones.

Several agents, each with a fresh context

Planning keeps the agent on track, but all three frameworks' pages still pile up in one context. The second tool is to split the work.

In a common design, an orchestrator agent breaks the task into parts and hands each part to a worker agent. Each worker starts with an empty history and only its own part. It does the reading, and sends back a short summary. The orchestrator never sees the raw pages, only the summaries.

One orchestrator, three workersUse the arrows or ← → keys
  1. O300 tokensABC
    orchestrator context
    300

    1O is the orchestrator; A, B and C are workers. O reads the task and plans three independent parts, one per framework. Its context holds just the task and the plan.

  2. O900 tokensA200B200C200
    orchestrator context
    900

    2It writes each worker a brief of about 200 tokens: the overall goal, one framework, and the format to reply in. That is all a worker knows. The three can run at the same time.

  3. O900 tokensA12,200B12,200C12,200
    orchestrator context
    900

    3Each worker runs its own loop, reading pages about its framework. Each history grows to about 12,200 tokens, all about one framework, so nothing gets mixed up.

  4. O1,800 tokensAdoneBdoneCdone
    orchestrator context
    1800

    4Each worker replies with a summary of about 300 tokens: the three facts with a source each. The worker's long history is thrown away. 900 + 3 × 300 = 1,800.

  5. OreportABC
    orchestrator context
    1800
    single agent would hold
    36100

    5The orchestrator writes the comparison from 1,800 tokens of plan, briefs and clean summaries. A single agent would have written it with about 36,100 tokens of raw pages in its history.

  6. O1,800A12,200B12,200C12,200
    total across agents
    38400
    single agent
    36100

    6The catch: all four agents together handled about 3 × 12,200 + 1,800 = 38,400 tokens, more than the single agent. Splitting buys focus and speed. Do not count on it to save tokens.

1 / 6

The numbers are illustrative. The single-agent total assumes the task (100 tokens) plus 12,000 tokens of pages per framework, Both totals count what each agent holds, not what it re-reads on every call (The Agent Loop showed how fast that grows). Shorter histories re-read less, so splitting can sometimes save tokens. In practice, briefs, summaries and repeated searches often make it cost more. The shape is what matters: workers keep the orchestrator's context small and focused, and the work can run in parallel. Each worker is just the loop from the previous lesson, given its own goal.

// 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 worker knows only what is in that brief, so it must carry the goal, the boundaries of the part and the shape of the reply. "Research Framework B" gets back a vague essay.

When one agent is better

Multi-agent systems are popular to draw and often no better in practice. They often cost more in total. Every handoff loses context the orchestrator had and did not write down. And when the final answer is wrong, there are more places to look.

Split work only when the parts are truly independent: researching separate topics, checking separate files, trying separate approaches and keeping the best. Keep one agent when the parts depend on each other. Two workers writing different halves of the same program will each make reasonable choices about names, data formats and error handling, and the choices will not match.

Try it yourself

Try it: Write a worker's brief

The orchestrator in the framework comparison sends this brief to a worker. The worker comes back with a long history of the project and no dates. Rewrite the brief so the summary is usable in the final table.

Show a sample answer
Rewritten briefIllustrative example. Real replies vary.
You
Overall goal: a table comparing how three web frameworks handle security updates. You are covering Framework B only. Find these three facts: 1. Typical time from a reported vulnerability to a released fix. 2. Where fixes are announced (mailing list, blog, advisory database...). 3. How long older major versions receive security fixes. Use the project's own security policy and release notes first. If a fact is not stated anywhere, write "not stated" rather than estimating. Reply with exactly three bullet points, one per fact, each ending with the source URL. No background on the project.

Why it works: the worker knows how its output will be used (a table cell), exactly which three facts to find, where to look, what to do when a fact is missing, and the shape of the reply. That is the same brief you would give a contractor who cannot ask you questions.

Common mistakes

Check yourself

Quick check

Why do workers help an orchestrator write a more accurate report?

Which task is the best fit for several worker agents?

Halfway through, a result shows that step 4 of the agent's plan is no longer needed. What should happen?

What to practise next

More agents and more steps mean more ways to go wrong quietly. Continue with Evals to measure whether an agent actually does its job, then Guardrails to limit what it can break.