Sometimes several agents share the work. Each agent has its own context, so the work can run in parallel.
Patterns
| Pattern | How it works | Example in the shopping task |
|---|---|---|
| Lead and workers | A lead agent splits the task, and the workers run in parallel | One worker searches each shop |
| Reviewer | One agent drafts and another checks | A reviewer checks the cart against the request |
| Buyer and seller | Agents from 2 organisations talk, using the A2A protocol | Our agent asks the agent of the shop for a deal |
Cost
- more agents cost more
- the research system of Anthropic, a lead agent plus helpers, beat a single agent by 90.2%, but it used about 15 times the tokens of a chat
- start with one agent, and add more only for work that can truly run in parallel
Remembering tip
Lead and workers split the work, the reviewer checks it, and buyer and seller negotiate it.
Code
Lead and workers, with a thread pool as the parallel part:
from concurrent.futures import ThreadPoolExecutor
def worker(shop_name):
"""One worker agent searches one shop and returns a short summary."""
return f"{shop_name}: best total 47.85" # placeholder for a full agent run
shops = ["ShopA", "ShopB", "ShopC"]
with ThreadPoolExecutor() as pool:
summaries = list(pool.map(worker, shops)) # workers run in parallel
lead_context = "\n".join(summaries) # the lead keeps only the summariesNotes:
- the lead agent sees only the summaries, which keeps its context lean, see Context Engineering
- a team of agents has more steps in total, so the errors compound faster, see Compounding Errors in Agents