Sub topic 14
Splitting work across several agents
This chapter assumes you have read the agent loop chapter, can read Python, and have seen the deterministic metrics tool from earlier. It covers when to use more than one agent and how to coordinate them.
When one agent is not enough
A single agent with a few tools is the right default. It is easier to log, cheaper to run and simpler to debug. Consider splitting the work when one of these happens:
- The prompt grows so long with instructions and tool descriptions that the model starts ignoring parts of it.
- Tasks are independent, such as pulling ad data, reading competitor pages and summarizing CRM notes, and could run at the same time.
- Different steps need different permissions. A worker that reads ad spend should not also be able to send email.
- You want an independent check. A reviewer agent that did not write the draft is less likely to repeat the writer's mistakes.
A common layout
The usual pattern has one orchestrator and several workers. The orchestrator is an agent or a plain program that splits the brief into tasks, sends each task to a worker and merges the results. Each worker has its own prompt, its own small set of tools and its own step limit.
A minimal orchestrator
The orchestrator can be ordinary code. It does not need to be a model. Here each worker is a function, standing in for a full agent loop. The orchestrator collects results and records failures instead of stopping.
def data_worker(task):
return {"ctr": 0.0167, "cpc": 0.84}
def web_worker(task):
raise TimeoutError("competitor site did not respond")
def orchestrate(workers, brief):
"""Run each worker on the brief; keep results and failures apart."""
results, failures = {}, {}
for name, worker in workers.items():
try:
results[name] = worker(brief)
except Exception as exc:
failures[name] = str(exc)
return {"results": results, "failures": failures}
out = orchestrate({"data": data_worker, "web": web_worker}, "Monthly report")
print(out)The output shows the data result and a recorded failure for the web worker. The writer should be told which inputs are missing so the report states the gap and does not fill it with a guess.
Common errors
- Splitting too early. Every handoff adds cost, latency and a place for errors. Start with one agent and split only when you can name the problem a split solves.
- Passing prose between workers. A summary of a summary loses numbers. Pass structured output, such as JSON with source fields, so the reviewer can trace each figure.
- Letting workers share one broad set of permissions. Give each worker only the tools and data it needs.
- No limits on the whole run. Per-worker step limits are not enough. Set a total budget for steps, tokens and time on the orchestrator, and log each worker's cost separately.
- Trusting agreement. Two agents that agree may have read the same wrong source. Verification still needs deterministic checks, such as the unsupported-numbers check.
Exercise
A monthly report agent has one long prompt and tools for ad data, CRM and sending email. Name two reasons to split it into workers and one thing the split should not change.
Show answer
First, the email tool needs tighter permissions than the read-only data tools, so a separate worker (or a human-gated step) limits what a mistake can do. Second, the data pulls are independent and can run in parallel, and a separate reviewer gives an independent check. The split should not change the rules that metrics come from deterministic code and that numbers are verified and approved by a person before publishing.