Lesson 50.2 · 2 of 4 · 5 min read · Reviewed 24 Nov 2026
Cost and latency trade-offs
By the end, you can
- Compare architectures on cost and latency.
- Estimate the cost of an agent design.
Rough shapes
| Architecture | Model calls | Input per call | Latency |
|---|---|---|---|
| Single call | 1 | Prompt | Lowest |
| Workflow (k steps) | k | Each step’s own input | k sequential, or fewer if parallel |
| Agent (n steps) | n | Grows each step | n sequential |
| Multi-agent (m agents) | Sum of all agents | Each agent’s growing history | Parallel workers help; coordination adds |
A worked estimate
agent, 12 steps, history grows by ~2,000 tokens per step, 3,000-token start:
input tokens = sum over steps of (3,000 + 2,000 x step)
= 12 x 3,000 + 2,000 x (0+1+...+11) = 36,000 + 132,000 = 168,000
The growing history dominates. That’s why the levers below matter.
Levers
| Lever | Effect |
|---|---|
| Prompt caching | Re-sent history becomes cheap cache reads (70.1) |
| Clearing old tool results / compaction | Keeps history from growing without limit (chapters 59, 60) |
| Subagents with summaries | Keeps the lead agent’s context small (49.5) |
| Lower effort for simple steps | Fewer tokens per step (13.6) |
| Parallel tool calls | Fewer sequential round trips (33.3) |
| Smaller models for narrow workers | Cheaper per token (71.2) |
Judge by cost per finished task
An architecture that costs more per call but finishes more tasks without human help can be cheaper overall (71.1).
Key points
- Cost grows with the number of calls and with how much context each call re-sends.
- Agents re-send growing history every step; multi-agent systems multiply that by the number of agents.
- Latency comes from sequential steps; parallel calls and smaller models cut it.
- Prompt caching, compaction and lower effort are the main levers once the shape is chosen.
Estimate cost and latency by shape
Compare input tokens and latency across architectures with a small, honest model.
You will have: A script that prints rough token totals per architecture and sequential versus parallel latency.
Steps
- Run the starter: the agent looks as cheap per step as a single call.
- Fix agent() so each step re-sends a history that grows.
- Compare the totals for all four shapes.
- Print the latency when the independent lookups run in parallel.
- Halve the growth (as compaction might) and see how much the agent total drops.
Done when
- The agent total is 96,000 tokens, 8x the workflow.
- Multi-agent multiplies that by the number of agents.
- Parallel lookups bring latency from 9.0 s to 3.0 s.
Open in the Playground No API key needed.
Starter code (Python)
# Rough cost and latency by architecture. Numbers are illustrative.
def single_call(prompt=6000):
return prompt
def workflow(steps=3, per_step=4000):
return steps * per_step
def agent(steps=8, start=5000, growth=2000):
# TODO: each step re-sends the history, which grows by `growth` tokens per step
return steps * start
def multi_agent(agents=3, **kw):
return agents * agent(**kw)
for name, toks in [("single call", single_call()), ("workflow (3 steps)", workflow()),
("agent (8 steps)", agent()), ("multi-agent (3 agents)", multi_agent())]:
print(f"{name:24} {toks:>8,} input tokens")
# Latency for four independent lookups (2.0 s each) and a 1.0 s summary
LOOKUPS, LOOKUP_S, SUMMARY_S = 4, 2.0, 1.0
print(f"sequential: {LOOKUPS * LOOKUP_S + SUMMARY_S:.1f} s")
# TODO: print the time when the four lookups run in parallel
Show a solution
# Rough cost and latency by architecture. Numbers are illustrative.
def single_call(prompt=6000):
return prompt
def workflow(steps=3, per_step=4000):
return steps * per_step
def agent(steps=8, start=5000, growth=2000):
return sum(start + growth * k for k in range(steps))
def multi_agent(agents=3, **kw):
return agents * agent(**kw)
for name, toks in [("single call", single_call()), ("workflow (3 steps)", workflow()),
("agent (8 steps)", agent()), ("multi-agent (3 agents)", multi_agent())]:
print(f"{name:24} {toks:>8,} input tokens")
# Latency for four independent lookups (2.0 s each) and a 1.0 s summary
LOOKUPS, LOOKUP_S, SUMMARY_S = 4, 2.0, 1.0
print(f"sequential: {LOOKUPS * LOOKUP_S + SUMMARY_S:.1f} s")
print(f"parallel: {LOOKUP_S + SUMMARY_S:.1f} s")