Planning and Multi-Agent Systems
An agent that takes one step at a time, with no overall plan, can wander. On large tasks it helps to plan first, and sometimes to share the work among several agents.
Planning
Ask the agent to write a plan before it acts: the steps, their order and how it will know each is done.
Before you take any action, write a plan:
1. List the steps needed to complete the task.
2. For each step, state which tool you will use and what result you expect.
3. State how you will verify that the whole task has been completed correctly.
Then carry out the plan. If a step fails or you learn something that changes
the plan, update it before continuing.
A written plan helps in three ways. The agent stays on course. A person can review it before any action is taken. And when something goes wrong, you can see whether the plan or its execution was at fault.
A task list
A simple and effective form of plan is a list of tasks that the agent keeps up to date.
tasks = [
{"id": 1, "task": "Collect last quarter's sales by region", "status": "pending"},
{"id": 2, "task": "Identify the three weakest regions", "status": "pending"},
{"id": 3, "task": "Draft recommendations for each", "status": "pending"},
{"id": 4, "task": "Check figures against the source data", "status": "pending"},
]
def update(task_id, status):
for t in tasks:
if t["id"] == task_id:
t["status"] = status
def show():
for t in tasks:
mark = {"done": "x", "in progress": ">", "pending": " "}[t["status"]]
print(f"[{mark}] {t['id']}. {t['task']}")
update(1, "done"); update(2, "in progress")
show()
print("next:", next(t["task"] for t in tasks if t["status"] != "done"))
Stored outside the context window, a task list also lets a long task continue after the context has been compacted or a new session has started.
Plans change
A plan is a starting point. The agent should revise it when a step fails, when a tool returns something unexpected, or when it learns that an assumption was wrong. An agent that follows a broken plan to the end is worse than one with no plan.
Multi-agent systems
A multi-agent system divides a task among several agents, each with its own instructions, tools and context window.
The most common arrangement is the orchestrator and sub-agents:
- A lead agent analyses the task and breaks it down.
- It hands each part to a sub-agent with a clear brief.
- The sub-agents work, often in parallel, each in its own context.
- Each returns a condensed result.
- The lead agent combines the results.
def subagent(brief):
# each sub-agent would run its own agent loop in a fresh context
return f"summary for: {brief}"
def lead_agent(task):
briefs = [
"Find the pricing of competitor A, with sources",
"Find the pricing of competitor B, with sources",
"Find recent customer reviews of both",
]
results = [subagent(brief) for brief in briefs] # in practice, run in parallel
return "Final report\n" + "\n".join(f"- {r}" for r in results)
print(lead_agent("Compare our two main competitors"))
Why use more than one agent
- Separate contexts. Each sub-agent explores in its own window and returns a short result, so the lead agent’s context is not filled with detail.
- Parallel work. Independent subtasks run at the same time.
- Specialisation. Each agent can have its own instructions and a small, focused set of tools.
The costs
- More tokens. Several agents use far more than one. Anthropic’s account of building a multi-agent research system reports that such systems use several times the tokens of a single-agent conversation.
- Coordination. Agents can duplicate each other’s work, leave gaps or contradict one another.
- Lost information. A sub-agent knows only what its brief tells it.
- Harder debugging. A failure can come from any agent or from the hand-over between them.
Use several agents when the task is valuable, can be divided into largely independent parts, and is too large for one context. For tightly connected work, where every part depends on the others, a single agent usually does better.
Writing a brief for a sub-agent
A sub-agent starts with nothing but what you give it. A good brief includes:
- the objective, and how it serves the larger task,
- what is already known, so that it is not repeated,
- what to return, and in what format,
- which tools and sources to use,
- limits on scope, so that it does not wander.
A brief that is too short, such as “research the competitor”, leads to duplicated or irrelevant work.
Other arrangements
- A pipeline, where each agent hands over to the next, such as researcher, writer and reviewer.
- A reviewer, where a separate agent checks the work of the first. A fresh context often notices what the author missed.
- Hand-off, where a general agent passes the conversation to a specialist.
Start with one
Build a single agent that works. Add a second only when you can point to a problem it solves: a context that overflows, subtasks that could run in parallel, or a need for an independent check.
Practice
Write the briefs a lead agent would give three sub-agents for the task “Recommend a laptop for a data analyst with a budget of 1,200”. Make sure the briefs do not overlap.