AlgoViz

Evaluating complete agent runs

hard 6 min

Agent behavior is stochastic and stateful.

Video lesson · Chapter 1 of 4

Three tries for one room

0:00 / 3:47

Theory

Read or listen first. About 2 min.

What it is

Agent behavior is stochastic and stateful. Multiple routes can be correct, and an apparently correct final sentence can hide an incorrect external effect. Use a resettable environment and explicit success predicates to compare runs fairly.

Why it exists

Record constraints, costs and failure types alongside pass rates. Repeated trials estimate consistency, and category-level results reveal which tasks remain unreliable despite a good average.

Three runs of a booking assistant

Initial state → Independent trials (reset fixture). Independent trials → Reliability score (grade final state)
Initial state → Independent trials (reset fixture). Independent trials → Reliability score (grade final state)

Inside this chapter

Chapter sources
Why Agent Evaluation Is Hard
Several trajectories may satisfy one goal. Matching a single reference trace penalizes legitimate alternatives, while checking only the final text misses unsafe actions. Evaluate final environment state, constraints respected and resource use, and examine traces to understand failures.

A trace-matching grader punishes a legitimate alternative route, while a final-message grader rewards a run that said "confirmed" after double-booking. The robust approach is to define success as a predicate over the environment after the run (exactly one reservation, inside the budget, for the right dates), plus explicit checks for forbidden actions. Traces are then diagnostic material, not the score.

Example. Two different tool sequences can reserve the same permitted room. Score the final reservation and constraints before comparing the trajectories.

Another example. A coding agent may fix a bug by editing either the parser or the caller. Grading by "the test suite passes and no unrelated files changed" accepts both, whereas diffing against one reference patch rejects a valid fix.

Two routes, one correct end state

Grade the reservation table and constraints first; read traces to explain failures.
Agent Metrics
Track task success, constraint violations, cost and latency as separate measurements. Define what counts as one attempt and whether human assistance was allowed. An average success rate can conceal a severe regression on rare high-impact tasks. Slice results by task and failure type.

Decide the unit before counting: is one attempt a single run, or a run plus any retries? Was a human allowed to help? Then keep success, violations, cost and latency as separate columns and slice by task family, because rare high-impact tasks (refunds, deletions) disappear inside an average. A release that holds success level while doubling cost or adding violations is a regression.

Example. Two releases each solve 80 of 100 jobs. One doubles cost and another violates a constraint. Report those differences explicitly.

Another example. A travel agent's success rate rises from 78% to 81%, but the gain is all in simple one-way flights while multi-city itineraries drop from 60% to 45%. Per-family slicing catches it.

Same success rate, different releases

MetricRelease ARelease BRelease C
Jobs solved80/10080/10080/100
Cost per solved job1.0x2.0x1.0x
Constraint violations003
Median latency40 s45 s38 s
Illustrative numbers. A single success column would rank these three as equal.
Simulation-Based Testing
A simulator provides controllable users, tool responses and environment changes. Include stale reads, timeouts and conflicting updates as well as successful calls. Validate the simulator against real distributions. A model that exploits a predictable simulator can look competent while failing on actual requests.

A simulator replaces real users and tools with controllable fakes so you can reset state and reproduce runs. Its value comes from the faults you inject: timeouts, stale reads, conflicting writes, users who change their minds. Its weakness is predictability, as an agent can learn the simulator's habits. Compare simulator traffic with real logs (message lengths, error rates, intents) and refresh scenarios when they drift apart.

Example. Inject an unavailable room into a booking fixture. A successful simulation should end with a feasible alternative or a justified handoff.

Another example. A customer-service simulator always phrases cancellations the same way, so the agent scores 98%. Replaying 200 anonymised real cancellation messages drops it to 85%, revealing the gap.

Injected fault in the booking simulator

A pass is a feasible alternative or a justified handoff, not a confident confirmation of room 12.
Regression Testing for Agents
Replay a versioned evaluation set whenever prompts, models, tools or policies change. Compare outcomes on identical inputs and inspect newly failing traces. For stochastic behavior, repeat trials or quantify uncertainty rather than treating one favorable run as conclusive.

Keep a versioned set of cases (including past production failures) with fixed fixtures and success predicates. Replay it whenever the model, prompt, tool or policy changes. Because runs are stochastic, repeat each case several times and compare pass rates, not single outcomes. Newly failing cases deserve a trace review before anyone decides whether to block the change.

Example. Replay a fixed set of historical failures against a new tool version, then repeat stochastic cases to separate regressions from run-to-run variation.

Another example. After upgrading a search tool, one historical failure (a date-range query) starts passing and two previously stable cases now fail 4 of 5 trials. Trace review shows the new tool sorts by relevance instead of date.

Replay on every change
  1. 1Change landsnew tool version v3
  2. 2Replay golden setsame inputs, same fixtures
  3. 3Repeat stochastic cases5 trials each
  4. 4Diff outcomesnew failures listed
  5. 5Inspect tracesregression or noise?

A case that fails 1 of 5 times before and after is noise; one that now fails 5 of 5 is a regression.

Progress after a context reset
Insert a checkpoint during a long task and inspect which commitments and permissions survive compaction. Grade final external state as well as intermediate progress. Use separate trials for reliability estimates and keep the task fixture stable.

Long tasks get summarised or compacted to fit the context window, and the summary may drop commitments that only matter later. Test this by forcing a checkpoint mid-task, then inspecting what the resumed run still knows and what it does. Score intermediate progress separately from the final external state, and treat any permission lost across the reset as a failure, however good the output.

Example. The agent resumes with the file it needs but forgets that sending it requires approval. Completing the draft is progress, and unauthorized delivery fails the task.

Another example. A data-migration agent is reset after copying 3 of 5 tables. The resumed run must remember that table 4 needs a schema change first; if it copies table 4 directly, the run fails even though all five tables end up present.

Grading a resumed run

ItemBefore compactionAfter compactionGrade
Draft file referencekeptkeptprogress
Constraint: send needs approvalkeptlostinvariant at risk
Draft completedyespartial credit
Email sent without approvalyestask fails
Final external state outranks intermediate progress.

How it works

Step through the idea, or press Play.

Step 1 of 3

Initial state. One available room

Understand it

Worked example

Three runs of a booking assistant

  1. 1

    One available room

    Each trial starts from the same clean fixture. Define success as one valid reservation satisfying the customer constraints.

  2. 2

    Pass · pass · fail

    Different valid trajectories are allowed. A run that creates duplicate bookings fails even when its final message says “confirmed.”

  3. 3

    2 of 3 trials succeed

    Report observed success and uncertainty. If the underlying success chance were 0.8 and trials independent, three consecutive successes would have probability 0.512.

Reliability across repeated attempts

P(all k succeed)=pkP(\text{all }k\text{ succeed})=p^k
Assuming independent trials with constant success probability 0.8, all three succeed with probability 0.512. Shared outages or repeated hard cases break the independence assumption.

Follow the handoffs

Record constraints, costs and failure types alongside pass rates. Repeated trials estimate consistency, and category-level results reveal which tasks remain unreliable despite a good average.

From three trials to a reliability statement

QuantityValueNote
Observed passes2 of 3small sample, wide uncertainty
If true p = 0.8, P(3 of 3)0.8^3 = 0.512assumes independent trials
If true p = 0.8, P(at least 2 of 3)0.8963 x 0.8^2 x 0.2 + 0.512
Failed runduplicate bookingfailed despite final message
Three trials cannot pin down the true rate; report counts, not a percentage alone.

Summary

The whole topic in one minute.

The real task is a state change under constraints. A matching sentence can accompany an incorrect or unsafe external result.

Record constraints, costs and failure types alongside pass rates. Repeated trials estimate consistency, and category-level results reveal which tasks remain unreliable despite a good average.

Sources