Parallel Subagents: Fan-Out and Fan-In Basics
Parallel subagents run several independent agent calls at once (fan-out) and then combine their results (fan-in). Because model calls spend nearly all their time waiting for the network, running ten of them concurrently takes about as long as running the slowest one. This is the main way multi-agent systems reduce latency on wide tasks.
Two reasons to parallelise
The first is sectioning: split a task into independent parts, such as reviewing each file in a pull request or researching each competitor. The second is voting: run the same task several times, perhaps with different prompts, and compare the answers to improve confidence. Both use the same mechanics.
When tasks are independent
Parallelism only works when no subtask needs another's output. A quick test: could you hand each subtask to a different person, in different rooms, and have them all start now? If yes, they are independent. If subtask B needs A's result, they are sequential, and forcing them parallel gives wrong answers.
Fan-out with threads
The Anthropic Python SDK client is thread-safe, so a thread pool is the easiest way to fan out. A later post covers asyncio for larger fan-outs. Here, three reviewers each check a different aspect of the same code snippet.
import time
from concurrent.futures import ThreadPoolExecutor
import anthropic
client = anthropic.Anthropic()
def call(system: str, user: str) -> str:
r = client.messages.create(
model="claude-sonnet-5-5", max_tokens=1500, system=system,
messages=[{"role": "user", "content": user}],
)
return "".join(b.text for b in r.content if b.type == "text").strip()
REVIEWERS = {
"security": "Review the code for security problems only. Max 3 bullets.",
"performance": "Review the code for performance problems only. Max 3 bullets.",
"readability": "Review the code for readability problems only. Max 3 bullets.",
}
CODE = """
def get_user(db, name):
rows = db.execute("SELECT * FROM users WHERE name = '" + name + "'")
return [r for r in rows if r[1] == name]
"""
def review(item):
aspect, prompt = item
return aspect, call(prompt, CODE)
start = time.perf_counter()
with ThreadPoolExecutor(max_workers=3) as pool:
results = dict(pool.map(review, REVIEWERS.items()))
print("elapsed: %.1fs" % (time.perf_counter() - start))
for aspect, text in results.items():
print("\n[" + aspect + "]\n" + text)
The elapsed time will be close to a single call, not three. The security reviewer should flag the string-concatenated SQL query. Fan-in here is simple: print the results in a fixed order. In larger systems, a synthesizer agent merges and deduplicates them.
Designing the fan-in
Merging is where most parallel designs go wrong. Decide up front how results combine.
- Concatenate when results are independent sections of a report.
- Synthesize with another model call when results overlap or may conflict.
- Vote when results are labels or short answers: take the majority, and treat disagreement as low confidence.
- Select the best using a judge agent when you only need one result.
Limits you must respect
- Rate limits. Many parallel calls can trigger 429 errors. Cap concurrency and retry with backoff. The SDK already retries some failures by default.
- Cost. Parallel runs cost the same per call as sequential ones, but fan-out makes it easy to launch fifty calls without noticing. Set a maximum.
- Partial failure. One of ten workers will eventually fail. Decide whether the whole run fails or continues with the nine that succeeded.
- Ordering. Do not rely on completion order. Use
pool.mapor attach an id to each result.
When not to parallelise
Two or three tiny calls rarely justify the extra code. Parallelism also hurts when it breaks shared context that the tasks actually need. Parallelise the wide, independent parts, keep the dependent parts sequential, and measure the difference.
A worked timing example
Suppose each review call takes about six seconds. Run sequentially, three reviewers take around eighteen seconds. Run in parallel, the total is close to six seconds plus a little overhead. Add a fan-in step that takes another five seconds and the end-to-end time becomes eleven seconds instead of twenty-three. The saving grows with the number of branches, until you reach rate limits or until the fan-in itself becomes the slowest part. Measure with a timer around each phase rather than guessing, because the synthesis call is often the real bottleneck.
Making fan-in cheaper
If ten workers each return five hundred words, the synthesizer must read five thousand words. Ask workers for a tight format: a three-line summary, key facts, and a confidence level. Shorter results make the fan-in step faster and cheaper, and they reduce the chance that the synthesizer overlooks something buried in a long report. Tell workers what the output will be used for, because that helps them decide what to keep.
Comments
No comments yet. Have a question or a tip? Be the first to share it.