Sub topic 14
Cost and latency trade-offs
This chapter covers what delegation costs in tokens and in wall-clock time, and how to estimate both before you start. It assumes you have read the chapters on the orchestrator-worker pattern, delegation briefs, and parallel versus sequential execution. You should also know that a model's context window holds everything it reads and writes, and that tool calls add to it.
Why delegation is not free
A single agent pays for one growing conversation. A multi-agent run pays for several conversations, and each one has its own overhead.
Four costs add up when you delegate:
- Brief tokens. The orchestrator writes a brief for each subagent. The subagent then reads it as input.
- Startup context. Each subagent loads its own system prompt, tool definitions, and any project files it needs to read. The parent already has some of this in its context, but the subagent cannot see it. It must read the material again.
- Work tokens. The subagent's own tool calls and observations. This is the work you wanted done, and it would cost something in a single-agent run too.
- Return tokens. The summary the subagent sends back. The orchestrator reads it as input on every later turn.
Only the work tokens are shared with a single-agent run. The other three are the price of isolation.
Token cost is not the same as the number of tokens processed once. Most agent loops resend the whole conversation on every turn. If your provider supports prompt caching, repeated prefixes are cheaper, but the new tokens on each turn are still billed at the normal rate. Check your provider's pricing for the exact discount and cache lifetime.
A simple cost model
You can estimate a run with a rough formula. Let S be the fixed startup tokens for one agent (system prompt, tool definitions, initial file reads). Let W be the work tokens one task needs. Let B be the brief size and R the size of a returned summary.
For n tasks run as subagents:
subagent_total ≈ n × (S + B + W) + n × R (read again by the orchestrator)
single_total ≈ S + n × WThe difference is roughly (n − 1) × S + n × (B + R). This is the delegation overhead. It grows linearly with the number of subagents.
The formula leaves out one effect that favors delegation. In a single agent, every turn resends the history. After task 1 finishes, tasks 2 to n carry task 1's observations in their context. The per-turn input cost therefore rises as the run goes on. Subagents start with small contexts, so their per-turn cost stays low.
This gives a break-even rule of thumb. Delegation saves tokens when the work of each task is large compared with the startup cost, and when the observations are bulky (long file reads, test logs, search results) but the answer is small. It costs more when tasks are tiny.
A worked estimate
Suppose a refactor splits into 4 independent tasks. Assume these round numbers:
| Quantity | Value |
|---|---|
| Startup tokens per agent (`S`) | 6,000 |
| Brief size (`B`) | 400 |
| Return summary (`R`) | 300 |
| Work per task (`W`) | 20,000 |
The subagent run costs about 4 × (6,000 + 400 + 20,000) + 4 × 300 = 106,800 tokens of work and overhead. The single-agent run costs about 6,000 + 4 × 20,000 = 86,000 tokens before counting history resends.
On raw tokens the subagent run is about 24% higher. The single agent then pays extra because its history grows. If the average single-agent turn carries 40,000 tokens of history instead of 20,000, its input cost per turn doubles, and the gap can close or reverse. The numbers here are illustrative. Measure your own runs rather than trusting them.
Latency: where time goes
Latency is the wall-clock time from your request to a result you can use. Compare these paths:
- Sequential single agent: the sum of all task times.
- Parallel subagents: the slowest task, plus orchestration overhead.
- Sequential subagents: the sum of all task times, plus the overhead of each handoff.
The overhead has three parts: the orchestrator's time to plan and write briefs, the subagents' startup reads, and the orchestrator's time to read results, merge them, and verify.
The speed-up from parallelism is limited by the longest task and by the serial parts of the work. If one task takes 10 minutes and three others take 2 minutes each, running them in parallel finishes in about 10 minutes, not 4. Splitting the long task further gives more benefit than adding more workers.
The chart uses days in place of minutes only because Gantt charts need dates. Read each day as one minute. The point is that task D sets the finish time.
Parallelism raises cost rate, not total cost
Running four subagents at once does not make each one cheaper. It makes the spend happen faster. If you pay per token, the total is the same as running them one after another. What changes is the rate at which you hit limits:
- Rate limits. Providers cap requests or tokens per minute. Several agents running at once can hit the cap, and requests then fail or wait. See the failure handling chapter for retries.
- Concurrency caps. Your agent runtime may limit how many subagents can run at one time.
- Local resources. Parallel test runs and builds compete for CPU, memory, and ports.
Set a concurrency limit in your orchestrator rather than starting everything at once. This sketch uses a semaphore to cap parallel work:
import asyncio
from dataclasses import dataclass
@dataclass
class Task:
name: str
brief: str
async def run_subagent(task: Task) -> dict:
# Placeholder: replace with a call to your agent runtime.
await asyncio.sleep(0.1)
return {"name": task.name, "status": "ok", "summary": f"finished {task.name}"}
async def run_limited(task: Task, limit: asyncio.Semaphore) -> dict:
async with limit:
return await run_subagent(task)
async def orchestrate(tasks: list[Task], max_parallel: int = 3) -> list[dict]:
limit = asyncio.Semaphore(max_parallel)
outcomes = await asyncio.gather(
*(run_limited(t, limit) for t in tasks), return_exceptions=True
)
results = []
for task, outcome in zip(tasks, outcomes):
if isinstance(outcome, Exception):
results.append({"name": task.name, "status": "failed", "summary": str(outcome)})
else:
results.append(outcome)
return results
if __name__ == "__main__":
tasks = [Task(f"task-{i}", "Do the work.") for i in range(6)]
for result in asyncio.run(orchestrate(tasks)):
print(result)With six tasks and max_parallel=3, the tasks run in two waves. Total time is about two task durations rather than one, but you avoid bursts that trigger rate limits.
Levers for controlling cost
You can reduce both cost and latency without giving up delegation.
- Right-size the task. Delegate work with large observations and small answers, such as searching a codebase or reading long logs. Keep one-line edits in the parent.
- Keep returns short. Ask for a summary and a result, not file contents. The brief's "Return" line controls this.
- Trim startup reads. Name the exact files in the brief so the subagent does not explore. Exploration is the largest hidden cost in most runs.
- Match the model to the task. Routine work such as renaming, formatting, or writing simple tests often succeeds on a smaller, cheaper, faster model. Reserve the strongest model for planning and review. Test this on your own tasks, because quality varies.
- Set limits. Give each subagent a maximum number of turns or a time limit. A stuck subagent that loops on a failing command is a common source of runaway spend.
- Cap fan-out. More subagents means more overhead and more to review. Use the smallest number that removes the real bottleneck.
The cost nobody bills: review time
The orchestrator's merge and verify step is not free. Your own time reviewing the combined result also counts. Four parallel subagents produce four diffs to read. If the tasks overlap, you also pay to resolve conflicts. A run that finishes in 10 minutes but needs 30 minutes of human review can be slower overall than a careful single-agent run.
This is why decomposition quality matters for cost. Tasks that are truly independent merge cleanly. Tasks that touch the same files create rework that cancels the time saved.
Common errors
- Delegating tiny tasks. Startup cost exceeds the work. Do these in the parent.
- Ignoring the slowest task. Adding workers does not help if one task dominates the timeline.
- Unbounded fan-out. Launching dozens of subagents and hitting rate limits, then paying for retries.
- Long returns. A subagent that pastes full files back into the orchestrator's context removes the benefit of isolation.
- No stop condition. A subagent without a turn or time limit can spend a large budget on one failing step.
- Estimating once. Costs depend on your repository, model, and prompts. Track real token counts per run and adjust.
Exercise
A task splits into 3 independent subagent tasks. Each needs 15,000 work tokens, startup is 5,000 tokens per agent, each brief is 300 tokens, and each return is 200 tokens. Using the chapter's formulas, how many tokens does the subagent run use versus a single agent, ignoring history growth? Task times are 4, 4, and 12 minutes, and orchestration overhead is 3 minutes. How long does the parallel run take compared with a sequential single agent?
Show answer
Subagent run: 3 × (5,000 + 300 + 15,000) + 3 × 200 = 60,900 + 600 = 61,500 tokens. Single agent: 5,000 + 3 × 15,000 = 50,000 tokens. The subagent run uses about 11,500 more tokens. Parallel time is about 12 + 3 = 15 minutes, set by the slowest task. The sequential single agent takes 4 + 4 + 12 = 20 minutes, with no handoff overhead. Parallelism saves about 5 minutes here for roughly 23% more tokens, and splitting the 12-minute task would help more than adding workers.
Exercise
Name two ways a parallel run can cost more than the numbers suggest, and one setting that limits each.
Show answer
Rate limits and retries: bursts of requests can fail and be repeated, so cap concurrency with a semaphore or the runtime's parallelism setting. Runaway subagents: a subagent stuck on a failing step keeps spending tokens, so set a maximum turn count or time limit per subagent. Human review of overlapping diffs is a third cost, limited by decomposing into tasks with disjoint file scopes.