Evalsevalsmetricslatencycostsafety

Eval Metrics: What to Measure and How

A catalogue of agent metrics — outcome, trajectory, retrieval, efficiency and safety — with a precise definition and computation for each, so a number means the same thing across versions.

Interview question
Progress
Before this, know:RAG Evaluation

You have not marked these as done yet. Read on anyway if they feel familiar; come back to them if something here does not land.

Key points

  • Each metric needs a written definition, a per-case computation and an aggregation rule.
  • Layer metrics: outcome (success, correctness), trajectory (tool selection, arguments, steps), efficiency (latency, tokens, cost), safety (violations).
  • Use medians and p95 for steps, latency and cost; means hide runaway runs.
  • Tool selection and argument correctness are the metrics that localise agent regressions.
  • Hallucination rate requires the trace to capture the exact context the model saw.
  • Safety metrics are thresholds, not averages.

Metrics need definitions, not names

"Accuracy went from 81% to 85%" is meaningless unless everyone agrees what counts as correct, on which dataset, scored by what. Each metric below has a definition (what it measures), a computation (how a single case is scored and how cases aggregate) and a note on who can score it — code, a judge, or a human.

Pick metrics in layers: an outcome metric that captures what the user wanted, a few trajectory metrics that explain how the agent got there, efficiency metrics that bound cost and latency, and safety metrics that must stay at zero. A change that improves the outcome while doubling steps is not obviously a win.

Outcome and trajectory metrics

Outcome metrics score the end result. Trajectory metrics score the path — which tools were called, with what arguments, in how many steps. Trajectory metrics are what make agent evals different from plain LLM evals: two runs can reach the same answer, one in 3 steps with the right tools and one in 14 steps with a lucky guess.

  • Task success: did the run achieve the goal? Per case: 1/0 by a deterministic outcome check (record exists, ticket closed, test passes) or a judge with a rubric. Aggregate: mean → success rate. The headline metric for end-to-end evals.
  • Answer correctness: is the final text right? Per case: exact/normalised match for closed answers, judge-vs-reference score (0–1) for open answers. Aggregate: mean. Distinct from success — an agent can answer correctly but fail to perform the required action.
  • Tool selection accuracy: fraction of steps where the tool chosen matches the expected tool for that state. Per case: matches / expected tool calls. Aggregate: micro-average across all steps. Catches a router or description bug directly (wrong-tool-selected).
  • Tool argument correctness: for each correctly selected tool, do the arguments validate against the schema and match the expected values (exact, or within tolerance for numbers/dates)? Per case: correct args / tool calls. Detects tool-argument-drift after prompt or model changes.
  • Number of steps: LLM calls (or loop iterations) per run. Report median and p95, not mean — one runaway run dominates a mean. A rising p95 with flat success means the agent is getting lucky, not better.
  • Hallucination rate: fraction of claims (or answers) not supported by the provided context or tool results. Per case: judge extracts claims and checks each against the context; unsupported / total. Requires the trace to include the context the model saw.

Retrieval, efficiency and safety metrics

Retrieval metrics score the RAG layer in isolation (see RAG Evaluation). Efficiency metrics should be recorded on every run, eval or production, because they are free once traces exist. Safety metrics are usually thresholds, not averages: the acceptable number of exfiltrated secrets is zero.

  • Retrieval quality: recall@k (gold chunk in top k), precision@k, MRR (1 / rank of first relevant chunk). Needs a labelled query→relevant-chunk set. Compute per query, average over queries.
  • Latency p50 / p95: wall-clock from request to final answer. p50 is the typical experience; p95 is what your slowest 1 in 20 users get and what timeouts must be set against. Never report a mean latency.
  • Tokens: prompt + completion tokens per run, split by call. Track prompt tokens per step — growth over steps is the signature of context bloat (context-overflow-degradation).
  • Cost: tokens × price per model, plus tool costs (search API, sandbox minutes). Report cost per task, median and p95, and total per eval run. A 4% accuracy gain that triples cost per task needs a business case.
  • Safety violations: count of runs that called a forbidden tool, leaked a secret or PII pattern, executed a blocked action, or produced output failing the output guardrail. Aggregate as a count with a hard threshold of 0 for the severe categories.

Computing metrics from traces

Every metric above is a function of the trace plus the dataset entry. That is the argument for storing traces in a structured form: metrics become pure functions you can re-run, version and unit-test.

Trajectory metrics from a trace; aggregation happens outside.
1def trajectory_metrics(trace, case):
2 calls = [s for s in trace.spans if s.kind == "tool"]
3 expected = case.expected_tools # ordered list of (name, args)
4 selected = sum(1 for s, (name, _) in zip(calls, expected) if s.name == name)
5 args_ok = sum(1 for s, (name, args) in zip(calls, expected)
6 if s.name == name and s.input == args)
7 return {
8 "tool_selection": selected / max(len(expected), 1),
9 "tool_args": args_ok / max(selected, 1),
10 "steps": len([s for s in trace.spans if s.kind == "llm"]),
11 "tokens": sum(s.tokens_in + s.tokens_out for s in trace.spans if s.kind == "llm"),
12 "cost_usd": sum(s.cost_usd for s in trace.spans),
13 "latency_ms": trace.end_ms - trace.start_ms,
14 }

When to use — and when not to

Use it when
  • Defining the scorecard before building an eval suite.
  • Deciding whether a model upgrade is a net improvement across quality, cost and latency.
  • Setting SLOs and alert thresholds for production (Logging, Metrics and Alerts).
Avoid it when
  • Do not report a single blended score; it hides which layer regressed.
  • Do not compute retrieval metrics on the final answer — they need labelled chunks.
  • Do not use mean latency or mean cost for anything user-facing.

Failure modes

Reference · show
  • Success rate rises while p95 steps doubles — the agent is brute-forcing, and cost follows.
  • Answer correctness scored by a judge without a reference, so the judge rewards confident wrong answers.
  • Tool argument correctness computed with exact string match on free-text arguments, producing false failures.
  • Cost tracked in tokens only, ignoring tool API charges that dominate the bill.
  • Safety violations averaged into a percentage and treated as "acceptable at 0.5%".

Check yourself

Answer out loud or on paper first, then compare. These come from the interview questions linked to this lesson.

  1. How do you choose evaluation metrics for an agentic system, and what goes wrong when you pick the wrong ones?

    Show a strong answer

    Start from what the task needs to be true and write checks for that. Outcome metrics depend on the task: exact match for extraction, schema validity for structured output, task completion for agents (did the ticket get created with the right fields), groundedness and citation precision for RAG. Process metrics tell you why: tool-selection accuracy, argument validity rate, steps per task, cap-hit rate, retrieval recall@k. Operational metrics: cost per success, p95 latency, error rate. See Eval Metrics: What to Measure and How.

    Prefer Deterministic Evaluators wherever a check can be coded (did the JSON validate, does the answer contain the required id, did the forbidden tool get called); use an LLM-as-Judge with a specific rubric only for qualities like tone or completeness, and calibrate it against humans.

    Wrong metrics mislead: a 1–10 quality score hides whether the failure is retrieval or generation; average accuracy hides a regression on the critical 5% of cases; a single outcome metric cannot say whether cost or latency became unacceptable.

    Full interview question, with follow-ups and red flags →
  2. Costs of your agent grew ten times faster than traffic after launch. How do you find the cause and bring it under control?

    Show a strong answer

    Cost growing faster than traffic means cost per task grew, so I attribute cost from traces: tokens and dollars per run broken down by step, model, tool, and task type, then look at the distribution rather than the mean; a fat tail of long runs often accounts for most of the spend. Common drivers: context accumulating across steps (history and tool results never compressed), more steps per task on real inputs than in the demo, retries counted in tokens, and evaluation or judge calls running on every production request. See Logging, Metrics and Alerts and Token Budgets.

    Controls in order of impact: per-run token and dollar budgets that stop runaway runs; compression of history and tool outputs so tokens per step stay flat; prompt caching for stable prefixes; routing simple steps (classification, extraction) to a small model and reserving the strong model for judgement steps; caching tool results and retrieval within and across runs; and removing steps that evals show add nothing. See Fallbacks, Caching and Model Routing and Context Selection & Compression.

    Every cost change is validated against the golden set so quality does not silently drop.

    Full interview question, with follow-ups and red flags →
  3. Groundedness went up and user satisfaction went down. Why?

    Show a strong answer

    Likely more refusals or hedging; check answer rate and completeness as the counter-metric.

    Full interview question, with follow-ups and red flags →