Trajectory Evals
Score full agent traces-not just final answers-for process quality and efficiency.
In plain words
Instead of only checking whether the agent got the right answer, you also check the steps it took to get there.
Think of it like…
Marking a maths exam by working, not just the final answer: a correct number reached by wrong reasoning, or after pages of scribbling, tells the teacher the student isn't reliable.
Where you’ve seen it
Reference trajectory for "Refund my damaged order": search_orders → get_order → issue_refund. The agent actually runs search_orders, search_orders (repeated), get_order, issue_refund. Exact match fails; in-order match passes (the reference steps appear in order); step precision is 3/4 = 0.75 (one redundant call) and recall 3/3 = 1.0; efficiency is 4 steps versus 3 optimal, 33% over. Across 100 cases, outcome success is 92% but only 68% follow an acceptable path without redundant calls, and 6% perform issue_refund before verifying the order status, a safety violation the outcome check never saw.
Words you’ll hear
- Reference trajectory
- An expected or acceptable sequence of steps for a task.
- In-order / any-order match
- Whether reference steps appear in sequence (extra steps allowed) or in any sequence.
- Step precision and recall
- Share of actual steps that are expected, and share of expected steps that occurred.
- Trajectory efficiency
- Actual steps, tokens or cost relative to an optimal or reference path.
Visual diagram
Theory & deep dive
Metrics for comparing paths
With a reference sequence R and actual sequence A, common scores are: exact match (A equals R; strict, suits tightly scripted workflows), in-order match (R appears as a subsequence of A, so extra steps are tolerated), any-order match (all steps of R appear, order ignored), and precision/recall (precision = steps in A that belong to R / |A|; recall = steps in R found in A / |R|). Add efficiency (A length, tokens and cost versus the reference), loop detection (the same call with the same arguments repeated) and step-level correctness (each call's tool and arguments scored as in tool-call accuracy).
Because real tasks often have several valid routes, give a set of acceptable trajectories or define constraints instead of a single path: must call get_order before issue_refund; must never call issue_refund twice; must ask for confirmation before irreversible actions; at most 6 steps. Rule-based checks over the trace are cheap, deterministic and good at safety properties. For open-ended agents where no reference exists, use an LLM judge on the trace with a rubric (was each step justified? was information gathered before acting?) and validate it against human review.
Reference: A → B → C. Actual: A → A → B → C. In-order match: yes. Precision: 3 expected-step occurrences out of 4 actual steps (counting the repeated A as redundant) = 0.75. Recall: 3/3 = 1.0. Efficiency: 4 steps vs 3, 33% over.
Using trajectory evals in practice
Collect traces from every run with step ids, tool calls, arguments, observations, tokens and timings (see the tracing lessons). Run the evaluators automatically in CI on golden tasks and on sampled production runs. Report outcome success and path quality side by side, with percentages for loops, redundant calls, constraint violations and budget overruns, and use the trace viewer to inspect the first bad step in failing runs. Often the earliest wrong step (a bad search query, a skipped verification) explains the rest.
Watch for over-constraining: demanding an exact path penalises smarter solutions and blocks improvements, so prefer constraints and outcome checks, and use exact matching only where the workflow is truly fixed. Also account for non-determinism: run each task several times (3 to 5) and report the pass rate and variance; a path that works 3 times out of 5 is a reliability problem. Combine with cost budgets ("median 4 steps, p95 under 8") to turn path quality into an engineering target.
92 of 100 tasks end with the right result, but 6 of those processed the refund before checking order status, and 24 contained at least one redundant call. A path-aware report shows 68% clean runs and a safety-rule violation rate of 6%, driving a prompt and tool-guard fix.
How it works, step by step
Step 1 of 41. Define references or rules
Write reference trajectories, acceptable alternatives and constraints (ordering, forbidden calls, step budget).
- Prefer
- constraints to rigid paths
When to use it & trade-offs
What it is
Trajectory evaluation scores the whole path an agent takes (the sequence of reasoning steps, tool calls and observations), not just its final answer. Two agents can reach the same answer, one in three clean steps and the other after eleven wandering ones, two retries and a risky call. Trajectory evals compare the actual path with a reference trajectory using exact match, in-order match, any-order match, or step-level precision and recall, and add efficiency (steps, tokens, cost, latency) and safety checks along the way.
Why it matters: Outcome-only evals miss agents that succeed by luck, waste money or take unsafe shortcuts, and they can't tell you *where* a failing run went wrong. Trajectory metrics localise the failing step, expose looping and redundant calls, and give a measurable target for cost and latency. They're also what lets you compare two agent designs that both "work" on the final answer.
When to reach for it
- Debugging where an agent run went wrong
- Controlling cost, latency and loops
- Enforcing safety and ordering constraints
When to avoid or be careful
- Requiring one exact path for open-ended tasks
- Judging a run on the final answer only
- Evaluating each task once despite non-determinism
Outcome vs trajectory evaluation
Strengths: Simple; matches user value; allows any valid route.
Watch out: Misses waste, luck and unsafe shortcuts; weak diagnostics.
Strengths: Pinpoints deviations; deterministic.
Watch out: Brittle if many valid paths exist.
Strengths: Flexible; encodes constraints.
Watch out: Needs rule design and judge validation.
Interview signals & numbers to know
When this topic comes up
- “The agent gets there eventually”
- “It called the same tool five times”
- “Why did it take 12 steps?”
- Step precision and recall
- Safety constraints on tool order
Benchmarks & rules of thumb
- 0.75 / 1.0
- step precision and recall in the example
- 92% vs 68%
- outcome success vs clean-path rate
- 3 – 5
- repeats per task to measure variance
Common mistakes & follow-ups
Common interview mistakes
- Penalising correct alternative routes by demanding exact trajectories.
- Ignoring loops and redundant calls because the answer was right.
- Running each task once and missing flaky paths.
Likely interviewer follow-ups
- How would you evaluate an agent beyond its final answer?
- When would you use exact match versus in-order match?
- How do you encode safety rules on a trajectory?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Trajectory Evals with generative AI interview Q&A and hands-on practice.