Topic 3 of 5 · 5 min read
Latency and token cost of agent searches
Goal: Estimate the cost and latency of an agentic retrieval run from its trace and set step and token budgets that cap it.
An agentic retrieval run costs one model call plus one tool result for every step, and the cost grows with every step because the whole history is sent again, so cap steps, result size and parallel work up front.
Check yourself · 1 of 3
Why does the token cost of an agent run grow faster than the number of steps?
Why it matters
A single-pass answer is one retrieval and one generation. An agent might do six searches, two document reads and a final answer. Each model call sends the growing conversation, so tokens rise faster than the step count. Latency adds up too: calls run one after another unless you run them in parallel. The Anthropic research system write-up notes that multi-agent setups use far more tokens than a chat, so they only pay off on questions of enough value.
How to estimate from a trace
Read the trace and count:
- Model calls. One per step, plus the final answer.
- Tokens in. Sum of the prompt size at each call. It includes the system prompt, tool definitions, the question and every earlier result.
- Tokens out. Reasoning notes, tool arguments and the answer.
- Seconds. Each model call plus each tool call. Add them for sequential steps; take the longest for parallel ones.
Then price it with your provider's per-token rates, taken from its pricing page at the time you plan.
How to cap it
- Step budget. A hard maximum on tool calls, for example 8. On the last allowed step, tell the agent to answer with what it has and name the gaps.
- Result budget. Limit hits per search (
limit: 5) and snippet length. Truncate a document read to a maximum. - Context hygiene. Drop or summarise old results the agent no longer needs.
- Parallelism for breadth. For a question with independent parts, run sub-agents or parallel searches. Wall-clock time falls; total tokens do not.
- Timeouts. A per-tool timeout and a total deadline.
MAX_STEPS = 8
MAX_HITS = 5
for step in range(MAX_STEPS):
reply = model.call(messages, tools=tools)
if reply.is_final:
break
messages += run_tools(reply.tool_calls, max_hits=MAX_HITS)
else:
messages.append(system("Step budget reached. Answer now and list what is missing."))
reply = model.call(messages)
What goes wrong
- No budget. One ambiguous question triggers dozens of calls.
- Counting steps, not tokens. Three steps that each return a full document can cost more than ten that return snippets.
- Parallelism treated as savings. It cuts time, not tokens.
- Estimating from the happy path. Budget from the median and the worst traces, not the best.
Examples
Reading a trace
step model_in model_out tool tool_s
1 1,900 120 search 0.6
2 3,400 90 search 0.5
3 6,800 110 read_doc 0.9
4 9,900 260 (final) -
Four model calls, 22,000 input tokens in total. Step 3's document read added 3,100 tokens and every later call paid for them again. Capping read size would lower steps 3 and 4 directly.
Parallel breadth
A question asks for incidents in five product areas. Five sub-agents search in parallel, each with its own context, and return a short summary. The user waits for the slowest one instead of the sum of five. Total tokens are the same or higher, plus the cost of the merge step.
Key points
- Each step is a model call that re-sends the growing history, so token use rises faster than the step count.
- Estimate a run from its trace: model calls, tokens in and out, and seconds for sequential and parallel steps.
- Cap a run with a step budget, a result budget (hits and snippet length) and a total deadline.
- On the last allowed step the agent should answer with what it has and name the gaps.
- Parallel searches or sub-agents cut wall-clock time but not total tokens.
Common mistakes
- Setting no step limit and finding out the cost from the invoice.
- Budgeting by number of steps while each step returns a full document.
- Believing parallel sub-agents lower the token bill.
- Measuring only the easy questions and ignoring the long tail of expensive runs.
Check yourself · 2 of 3
An agent run is reaching its step budget without a final answer. What should happen on the last allowed step?
Check yourself · 3 of 3
Five parallel sub-agents each search one product area, then a lead agent merges their summaries. What does this change compared with doing the five searches one after another?
Practice items, not counted towards your mastery.
Start here
- How we built our multi-agent research system (Anthropic) (opens in a new tab)ArticleFree
How a lead agent plans, fans out parallel search sub-agents and merges results, with the costs and failure modes the team met.
- ReAct: Synergizing Reasoning and Acting in Language Models (opens in a new tab)PaperFree
The original reason-act-observe loop that every search-and-read agent is built on.
- Self-RAG: Learning to Retrieve, Generate, and Critique through Self-Reflection (opens in a new tab)PaperFree
Shows a model deciding when to retrieve and critiquing what it retrieved, the judge step in the loop.
More for this topic
- Writing effective tools for AI agents (Anthropic) (opens in a new tab)ArticleFree
How to design tool names, parameters and result formats an agent can use well, including search tools.