Cruxly › AI engineering › Agentic Systems
Evaluating Agents: Trajectories, Task Success and Cost per Success
the final answer can be right while the path was wrong, and an average hides unreliability
Open the interactive lessonPrompt: "We have a support agent that looks up orders, issues refunds and replies to customers. It demos well. How do you know it is good enough to ship, and how do you know the next prompt change did not make it worse?"
30 minutes first. The trap is answering with "we will grade the replies with an LLM judge". An agent changes the world, so the interviewer wants to hear what you check in the world, what you check about the path, how you handle the fact that it is stochastic, and what number you put on the slide for the budget owner.
Why a final-answer eval misses agent failures
A chat eval grades what the model said. An agent eval has to grade what the system did. The reply "Your refund of Rs 799 has been issued" is the last thing the agent produces, and it is the one thing that is cheap to fake: the model writes it whether or not the refund call worked. Grading only that text rewards fluent agents, not correct ones.
Take one task, for example: refund order ORD-5521, which was delivered damaged, Rs 799. Here are four runs, and how a final-answer grader and a state-plus-trajectory grader score each.
| Run | What happened | Reply says | Final-answer grader | State + trajectory grader |
|---|---|---|---|---|
| A | Looked up the order, refunded Rs 799, replied | Refund issued | pass | pass |
| B | Refund API returned an error, agent did not notice | Refund issued | pass | fail: no refund row exists |
| C | Refunded Rs 799 but first called get_order six times with the same arguments | Refund issued | pass | pass on outcome, flagged on trajectory (redundant calls) |
| D | Skipped the policy check and the approval step, refunded Rs 799 anyway | Refund issued | pass | outcome right, trajectory fail (unsafe path that happened to succeed) |
Runs B and D are the whole argument. B is the failure that a text grader cannot see at all. D is the one that will hurt later: the end state is correct, but the agent is willing to skip a gate, and next week the amount will be Rs 79,900.
So grade two things, and keep them as separate columns.
- Task success. Did the world end up in the right state? Refund row for the right order and amount, no other order touched, ticket closed, no duplicate refund. This is a yes or no that code can decide.
- Trajectory quality. Was the path acceptable? Look for the wrong tool (a modify tool where a read tool was enough), redundant calls (same tool, same arguments, more than once), a skipped step that the policy requires (lookup before refund, approval above the threshold), and budget overruns (turns, tokens, wall-clock time).
:::key Outcome and trajectory fail differently An outcome failure tells you the agent cannot do the task. A trajectory failure on a successful outcome tells you it can do the task but cannot be trusted to. Merging them into one score loses exactly the signal that decides whether you can remove the human. :::
A small golden task set, an environment you can reset, and two kinds of grader
Start with 30 to 50 tasks, not 5,000. A golden task set is a list of cases where you know the right end state, and its value is that you can rerun it after every prompt, tool or model change. For the support agent, for example, a first set could be 20 ordinary tickets, 8 edge cases (partial refund, duplicate request, customer changes their mind mid-chat), 6 refusals (policy says no), and 6 adversarial cases (an injection attempt in the ticket text, a request for another customer's order). Every production incident becomes a new case, so the set grows where the agent actually fails.
Each task is a small bundle, and the environment is the important part.
task_id: refund-damaged-001
initial_state: fixture "orders_v3" (ORD-5521 delivered, Rs 799, no refund)
user_script: "my order ORD-5521 arrived damaged, please refund it"
expected_state: refunds has exactly one row {order: ORD-5521, amount: 799}
forbidden: any write to another order; any call to delete_*
budget: 12 turns, 60,000 tokens, 90 seconds
The environment must reset to the same state before every run. If run 1 refunds ORD-5521, run 2 sees an order that is already refunded and "fails" for a reason that has nothing to do with the agent. Practical ways to get a reset: load a database fixture into a throwaway container per run, use an in-memory fake of the payments API, or snapshot and restore. Scripted users (a small program or a model playing the customer with a fixed brief) keep multi-turn tasks repeatable. If the real API cannot be sandboxed, point the tools at a fake that records every call, so the grader can read the call log.
Choose the cheapest grader that can decide the question.
| Grader | Good for | Weak spot |
|---|---|---|
| Programmatic state check (query the DB, diff the sandbox) | Did the refund row exist, with the right amount, once? | Cannot judge tone or whether an explanation was accurate |
| Programmatic trajectory check (rules over the call log) | Forbidden tools, missing steps, repeated identical calls, budget | Rules must be written per task family |
| LLM judge | "Was the reply polite and consistent with the policy text?" | Biased and inconsistent until calibrated |
Use code wherever the answer is a fact about the world, and keep the LLM judge for the parts that are language. Calibrate any judge against human labels before trusting it: have a person label, for example, 50 replies, run the judge on the same 50, and look at where they disagree. Pin the judge's model and prompt version, because a judge that silently changes moves your whole score history.
pass^k, pass@k, and cost per successful task
An agent is stochastic, so one run per task is a coin flip, not a measurement. Run each task k times, for example 5 to 8, and decide which question you are asking.
- pass@k is "solved in at least one of k attempts". It measures whether the agent can do the task, which suits a coding assistant whose output a person reviews before using it.
- pass^k (pass-hat-k) is "solved in all k attempts". The tau-bench paper (Yao et al., Sierra, 2024) uses it for tool-agent-user tasks, because an agent that handles customers unsupervised has to succeed every time, not once.
If the per-attempt success probability on a task is p, then pass@k is 1 - (1-p)^k and pass^k is p^k. With p = 0.9 and k = 5, pass@5 is about 99.999% and pass^5 is 0.9^5, about 59%. With p = 0.6 and k = 8, pass^8 is about 2%. Same agent, and the first number makes it look finished while the second says a customer will meet a failure within a day. Report pass^k per task, then average across tasks, and also report the tasks that were sometimes right, because those are your flaky ones and the best place to look first.
Then report cost and latency per successful task, not per run. A failed run still spent tokens and time, and that spend has to land on the successes. For example:
| Cost per run | Success rate | Cost per successful task | |
|---|---|---|---|
| Agent A (small model) | Rs 3.00 | 50% | Rs 3.00 / 0.50 = Rs 6.00 |
| Agent B (larger model) | Rs 4.50 | 90% | Rs 4.50 / 0.90 = Rs 5.00 |
Agent B costs 50% more per run and less per success. The same arithmetic applies to latency: the latency a customer experiences is the time to a correct resolution, including any retry or human escalation the failures cause. Quote p50 and p95 per successful task, since a long tail of 40-step runs is invisible in an average.
:::warn Do not compare two agents on a different task mix If agent B was tested on the hard half of the suite, its per-success cost is not comparable with A's. Freeze the task set, the fixtures and the grader versions for a comparison, and record them next to the number. :::
Follow-ups they will ask
"The LLM judge says 94% but our users complain. What do you do?" Check the judge against human labels on a few dozen of the complaint cases, not on a random sample. Judges tend to pass fluent text, so they miss the very failures users notice. Move every fact you can into a code grader (was the refund issued, was the right order touched), and keep the judge for tone and policy wording only.
"Can we run the whole suite on every commit?" Split it. A cheap smoke set of 10 to 15 tasks with k = 1 runs on every change; the full set with k = 5 runs nightly and before a release, because the full set costs real money. Gate a release on pass^k not dropping and on trajectory violations not rising, with a small tolerance, since stochastic noise means a score of 0.82 against 0.84 may be nothing.
"How big must the set be before a difference is real?" Say plainly that it depends on the effect size and the noise, and that you would compare the two versions on the same tasks (a paired comparison) and look at which tasks flipped, rather than trusting two averages. A 30-task suite can catch a collapse; it cannot separate a 2-point change.
"What about tasks with no single right end state?" Grade the constraints instead of the answer: nothing forbidden touched, required facts present, budget respected, and an LLM or human rubric for the open part. Be upfront that this grade is weaker and label it that way in the report.
"The agent passed everything, then failed in production. Why?" The suite did not contain that case. Treat the incident as a test: reproduce it in the sandbox from the trace, fix it, and add it to the set so it can never come back silently. The next lesson on reading a trace covers how.
How to say it in the interview
"I would not grade the reply text first. I would build a small set of tasks, each with a resettable sandbox and a known correct end state, and grade two things separately: did the environment end up right, checked by code against the database, and was the path acceptable, meaning right tools, no forbidden calls, inside a step budget. Because the agent is stochastic I would run every task several times and report pass^k, success on all k runs, not pass@k. And I would report cost and latency per successful task, so a cheap agent that fails half the time cannot look cheaper than it is."
Checklist
- Graded the end state of the world with code, not just the final reply
- Scored task success and trajectory quality as separate columns
- Named the trajectory failures: wrong tool, redundant calls, skipped required step, budget overrun
- Built 30-50 golden tasks with a resettable environment and a recorded call log
- Chose the cheapest grader that decides each question, and calibrated any LLM judge on human labels
- Ran each task k times and reported pass^k, not only pass@k
- Reported cost and latency per successful task, with p95
- Froze the task set, fixtures and grader versions when comparing two agents
Related lessons
- The Agent Loop in Depth: ReAct, Plan-and-Execute, Reflection and Stop Conditions
- Designing Tools an Agent Can Actually Use
- Agent Memory: Working, Episodic, Semantic and Procedural, Without the Rot
- Context Engineering for Long-Horizon Agents
- Frameworks, Protocols and Durable Execution: MCP, A2A and Long-Running Agents
- Reliable Agents: Retries, Idempotency, Checkpoints and Sagas