How to reduce AI agent latency and cost: measure first, then cut steps
For agent builders4 min read

Here is how to reduce AI agent latency and cost: measure where the time and tokens go in each run, then cut the biggest item. Usually that is the number of model calls. This post gives a small meter you can add to any agent, then the changes that tend to pay off: fewer steps, easier routing and hard caps.
Why agents are slow and expensive
Each step in an agent loop is a model call, often followed by a tool call. Cost and delay grow with the number of steps, and every step re-sends the growing conversation. Anthropic's article on building agents states the trade directly: agents trade latency and cost for better performance, so use them when that trade is worth it.
Source: Building effective agents(opens in a new tab)
Add a meter first
You cannot reduce what you have not counted. This small class records steps, tokens and elapsed time for one run, and turns tokens into money using prices you enter yourself. Take the prices from your provider's pricing page, since they change.
import timefrom dataclasses import dataclass, field @dataclassclass RunMeter: price_in: float # money per 1M input tokens (from your provider) price_out: float # money per 1M output tokens started: float = field(default_factory=time.perf_counter) steps: int = 0 tokens_in: int = 0 tokens_out: int = 0 def add_step(self, tokens_in, tokens_out): self.steps += 1 self.tokens_in += tokens_in self.tokens_out += tokens_out def report(self): cost = (self.tokens_in * self.price_in + self.tokens_out * self.price_out) / 1_000_000 return {"steps": self.steps, "tokens_in": self.tokens_in, "tokens_out": self.tokens_out, "cost": round(cost, 4), "seconds": round(time.perf_counter() - self.started, 2)} meter = RunMeter(price_in=3.0, price_out=15.0) # example numbers onlyfor tin, tout in [(1200, 150), (1900, 120), (2600, 300)]: meter.add_step(tin, tout)print(meter.report())Notice that input tokens rise at every step in the example. That is the usual pattern, because each call includes the earlier history. Most providers return token counts in their responses, so feed those numbers into add_step rather than estimating.
Log the report with every run, and compare median and high percentile values across tasks. The metrics post in this series shows how to compute them.
How to reduce AI agent latency: changes that usually pay off
| Change | Why it helps | What to watch |
|---|---|---|
| Remove steps | Each step is a model call and a delay | Success rate on the eval set |
| Route easy requests to a smaller model | The article describes sending easy queries to a smaller model | Misrouted hard requests |
| Run independent calls in parallel | Total time becomes the slowest call | Rate limits |
| Shorten the context | Fewer input tokens each step | Lost information |
| Cap iterations | A stuck loop cannot run forever | Tasks that need more steps |
The building agents article describes routing as sending an input to a specialized follow-up, such as a smaller model for easy queries, and parallelization as running calls at the same time. It also recommends stopping conditions such as a maximum number of iterations.
Start with the largest cost
- Run your eval set with the meter on. Sort runs by cost.
- Read the three most expensive transcripts. Look for repeated calls, tool results that are far too large, and loops.
- Fix the cause. A tool that returns a whole document when one field is needed is a common one.
- Re-run the eval set. Keep the change only if success did not drop.
- Set a step cap just above the highest healthy run, and alert when runs hit it.
Frameworks may have their own defaults. AgentOven's feature page, for example, lists a default of 10 turns for its agent loop and a default context budget of 16,000 tokens per agent. Check the defaults in whatever you use and set them on purpose.
Source: AgentOven features(opens in a new tab)
One more habit helps: keep a price list of your own runs. Multiply the cost of a typical run by the number of runs you expect per day, and compare it with the value of the task. If a run costs more than the work is worth, no amount of tuning on latency will fix the design.
Do not cut blindly
A cheaper agent that fails more often can cost more once you count retries, human review and unhappy users. Always read cost next to success rate. Anthropic's eval guide also suggests using constraints such as turn limits to measure efficiency, which gives you a way to compare two versions on the same budget.
Source: Demystifying evals for AI agents(opens in a new tab)
Last, simplify first. If a single model call with good context does the job, the cheapest agent is no agent. The article recommends starting with the simplest solution and adding complexity only when it measurably helps.