Lesson 19.4 · 4 of 4 · 4 min read · Reviewed 24 Nov 2026
Cost, latency and step budgets as metrics
By the end, you can
- Treat cost, latency and step count as eval metrics.
- Set budgets an agent must meet.
Efficiency metrics
| Metric | Why it matters |
|---|---|
| Steps per run | More steps means more cost, more latency, more chances to go wrong |
| Input and output tokens | Drives cost; context growth shows up here |
| Cost per run and per success | The real unit cost (71.1) |
| Wall time, p50 and p95 | What users wait for |
| Tool errors per run | Retries waste time and money |
Report them together
version success steps p50 cost per success p95 time
v14 90% 6 baseline 38 s
v15 91% 12 about 2x 71 s
Seen side by side, v15 is a hard sell.
Budgets
Set a budget per task type, for example “refund requests: at most 8 steps, 60 s”. In the evalEval: A repeatable test that measures how well an AI system performs on a set of cases with defined success criteria., a run that exceeds its budget counts as a failure, even if it eventually succeeded. This matches production, where you’d stop the run anyway (71.3).
Variance
AgentsAgent: A system where a model decides its own next steps, calling tools in a loop until the task is done. vary run to run. Run each case a few times and report the spread, not just the average (20.2).
Key points
- An agent that succeeds but takes 40 steps and costs ten times more may be a regression.
- Record tokens, cost, wall time and steps for every eval run, alongside quality scores.
- Set budgets per task type and fail the eval when a run exceeds them.
Report cost and steps beside success
Put success rate, steps, cost per success and budget failures side by side for two agent versions.
You will have: A comparison table for v14 and v15 with a budget-adjusted success rate.
Steps
- Read the recorded runs: success, steps, credits and seconds per run.
- Compute success rate, median steps, cost per success and p95 time for each version.
- Apply the budget: at most 8 steps and 60 seconds, or the run counts as a failure.
- Print both versions in one table and say which you would ship.
Done when
- v15 shows higher raw success than v14.
- v15's budget-adjusted success is lower than v14's.
- Cost per success is printed in credits for both.
Open in the Playground No API key needed.
Starter code (Python)
# (success, steps, credits, seconds) per run. Illustrative numbers.
RUNS = {
"v14": [(1, 6, 10, 30), (1, 5, 9, 28), (1, 7, 12, 41), (0, 8, 13, 44), (1, 6, 10, 33),
(1, 6, 11, 35), (1, 5, 9, 26), (1, 7, 12, 39), (1, 6, 10, 31), (0, 9, 14, 52)],
"v15": [(1, 12, 20, 70), (1, 11, 19, 64), (1, 6, 10, 32), (1, 13, 22, 75), (1, 12, 21, 69),
(1, 7, 12, 40), (1, 12, 20, 71), (0, 14, 24, 80), (1, 11, 18, 62), (1, 6, 11, 35)],
}
BUDGET = {"steps": 8, "seconds": 60}
def summarise(runs):
# TODO: success rate, median steps, credits per success, p95 seconds (use the max for 10 runs)
# TODO: budget-adjusted success: success and steps <= 8 and seconds <= 60
return {"success": 0, "steps_p50": 0, "cost_per_success": 0, "p95_s": 0, "in_budget": 0}
for v, runs in RUNS.items():
print(v, summarise(runs))
Show a solution
RUNS = {
"v14": [(1, 6, 10, 30), (1, 5, 9, 28), (1, 7, 12, 41), (0, 8, 13, 44), (1, 6, 10, 33),
(1, 6, 11, 35), (1, 5, 9, 26), (1, 7, 12, 39), (1, 6, 10, 31), (0, 9, 14, 52)],
"v15": [(1, 12, 20, 70), (1, 11, 19, 64), (1, 6, 10, 32), (1, 13, 22, 75), (1, 12, 21, 69),
(1, 7, 12, 40), (1, 12, 20, 71), (0, 14, 24, 80), (1, 11, 18, 62), (1, 6, 11, 35)],
}
BUDGET = {"steps": 8, "seconds": 60}
def median(xs):
s = sorted(xs); n = len(s)
return s[n // 2] if n % 2 else (s[n // 2 - 1] + s[n // 2]) / 2
def summarise(runs):
wins = sum(r[0] for r in runs)
in_budget = sum(1 for ok, steps, _, secs in runs if ok and steps <= BUDGET["steps"] and secs <= BUDGET["seconds"])
return {
"success": wins / len(runs),
"steps_p50": median([r[1] for r in runs]),
"cost_per_success": sum(r[2] for r in runs) / max(1, wins),
"p95_s": max(r[3] for r in runs),
"in_budget": in_budget / len(runs),
}
print(f"{'version':8}{'success':>9}{'steps p50':>11}{'credits/success':>17}{'p95 s':>7}{'in budget':>11}")
for v, runs in RUNS.items():
s = summarise(runs)
print(f"{v:8}{s['success']:>9.0%}{s['steps_p50']:>11}{s['cost_per_success']:>17.1f}{s['p95_s']:>7}{s['in_budget']:>11.0%}")
print(f" {v}: raw success {s['success']:.0%}, budget-adjusted {s['in_budget']:.0%}")
print("verdict: v15 succeeds more often but most runs blow the budget; keep v14")
Finished the chapter? Take the chapter check.