Evaluation & Operations
MDX
Managing Agent Cost and Latency
Control model calls, context growth, tool delays, retries, and quality tradeoffs in multi-step systems.
Editorial review: clarity, operational relevance, safety boundaries, and source quality.
Measure complete tasks
Per-call metrics hide the cost of loops and retries. Track tokens, tool time, wall-clock duration, and spend from goal to verified outcome.
Measure per completed task, including planning calls, retrieval, tool waits, retries, summarization, and verification. Report percentiles because averages hide slow loops. Segment by task type and outcome; a cheap failed task is not efficient, and an expensive escalation may still be correct for a difficult case.
Reduce unnecessary decisions
Move deterministic routing and validation into code, summarize stale context, cache safe results, and batch independent work. Fewer model turns often improve reliability as well as speed.
The best optimization is often removing model decisions. Use code for known routing, parallelize independent reads, cache safe immutable results, send only decision-relevant context, and stop after verified success. Optimize tool latency too: a fast model waiting on sequential APIs still produces a slow experience.
Route by difficulty
Use smaller or faster models for simple structured steps and reserve stronger reasoning for ambiguous decisions. Evaluate the full routing policy because one weak step can dominate task failure.
Model routing needs confidence from observable task features or an escalation policy. Start with the least expensive model that meets the step's evaluation target, then escalate on defined uncertainty or failure. Re-evaluate the entire path because extra classification and fallback calls can cost more than one capable call.
Practical example
Reducing a research agent from twelve turns to five
Tracing reveals three repeated searches, sequential retrieval from independent sources, and a final model call that only formats known fields. The team deduplicates queries, runs the two sources in parallel, renders the report in code, and retains one verification call. Task success remains stable while wall time and variance fall. The gain comes from changing orchestration, not shortening every prompt.
Field checklist
Apply it in practice
- Measure cost and latency from goal to verified outcome.
- Slice percentiles by task type and terminal state.
- Remove deterministic decisions from the loop.
- Evaluate routing policies including escalation overhead.
Decision framework
Questions to answer before you build
Optimize the cost and time of verified outcomes, not individual calls. Loops, tool waits, retries, routing overhead, and failed tasks determine the user experience.
Where is total time spent?
Trace model time, queueing, sequential tool calls, retrieval, retries, human waits, and verification across complete task percentiles.
Which decisions can disappear?
Move known routing, formatting, arithmetic, and validation into code; parallelize independent reads and cache safe immutable results.
When should a stronger model be used?
Route by measured step difficulty and escalate on defined uncertainty. Include classifier and fallback overhead in the comparison.
Common failure signals
Watch for these warning signs
- Celebrating a low per-call price while loops make tasks expensive.
- Reducing context until the agent needs more retries or loses key constraints.
- Optimizing average latency while difficult cases remain unpredictably slow.
Selected primary references
Continue with the source material
These sources inform the wider editorial perspective for this topic. They are not presented as line-by-line citations for every statement.
- NISTAI Risk Management Framework ↗A voluntary framework for governing, mapping, measuring, and managing AI risk.
- OWASPOWASP Top 10 for LLM Applications 2025 ↗A practical catalogue of common security risks in LLM-enabled applications.
- AnthropicDemystifying evals for AI agents ↗Evaluation strategies for multi-step, tool-using agent systems.