Lesson 7.1: Evaluating agents: outcomes and trajectories
Learn how to evaluate an agent: build a task set, grade outcomes and trajectories, size the test, measure consistency across runs and read the results honestly.
By the end of this lesson you will be able to build a set of test tasks for an agent, grade both what the agent achieved and how it got there, choose between code, model and human graders, work out how many tasks you need before a pass rate means anything, and measure whether the agent is consistent from run to run. You will work out that a 90 per cent pass rate on 50 tasks carries a margin of about 8.3 points either way, that 200 tasks narrow it to 4.2 and 400 to 2.9, and that an agent which passes a task 90 per cent of the time on any single run passes it on all five of five runs only 59 per cent of the time. You should have read Lessons 5.1 to 6.4 and, ideally, Lesson 6.1 of the AI Engineering track on evaluation. No code is needed. The mathematics is a square root, a percentage and powers.
Module 6 ended with a design decision. Module 7 turns to a harder question: how do you know the agent you built is any good, and that it stays good? An ordinary program is tested by running it and comparing its output with the expected output. An agent is harder to test for three reasons. It takes many steps, so there is a path to judge as well as an answer. It chooses its own path, so two runs of the same task may differ. And its answers are often free text, which cannot be compared to an expected string. Without a proper way to evaluate, every change is a guess. With one, you can improve an agent steadily and know when you have made it worse.
Two things to judge: the outcome and the trajectory
The outcome is what the agent achieved. Did the refund get issued correctly? Is the report accurate? Was the ticket routed to the right team? The outcome is the thing the user cares about, and it is the primary measure.
The trajectory is the path the agent took: the sequence of tool calls, the arguments, the results and the decisions. Two agents can reach the same outcome by very different paths, and the path matters for four reasons.
Efficiency. One path takes 6 steps and ₹3, another takes 25 steps and ₹18.
Safety. An agent may have reached the right answer by trying a forbidden action that happened to be blocked, or by reading data it should not have.
Luck. An agent can stumble on the right answer by a poor route that will fail next time.
Diagnosis. When an outcome is wrong, the trajectory shows where it went wrong.
A good evaluation looks at both. Outcome grading tells you whether the agent works. Trajectory grading tells you whether it works for the right reasons, at a sensible cost and without breaking rules.
What to grade in an outcome
Outcomes are easiest to grade when the task has a checkable result. For many agent tasks you can state the check in code:
The refund of ₹2,400 exists in the payments table with the right order ID.
The ticket was assigned to the billing team.
The file was created and contains the required three sections.
The email draft mentions the order number and the policy name.
Checks of this kind, which look at the state of the world after the run, are the most reliable, since they do not depend on how the agent describes what it did. An agent may say "I issued the refund" without having done so. Always check the world, not the agent's account of it.
Where no code check exists, such as the quality of a summary or the tone of a reply, you need a rubric: a short list of criteria, each judged yes or no. "Does the reply state the refund amount? Does it name the policy? Does it avoid blaming the customer? Is it under 120 words?" A rubric turns a vague judgment into several clear ones, and it is the basis for either a model grader or a human.
What to grade in a trajectory
Trajectory checks are about the steps. Useful ones include:
Check · What it asks · ExampleRequired steps · Did it do what had to be done? · It looked up the order before refunding
Forbidden steps · Did it do anything it must not? · It never called the delete tool
Order · Did things happen in a sensible order? · Verified identity before showing account data
Efficiency · How many steps, calls and tokens? · At most 10 steps and ₹5
Errors · How many tool errors and retries? · No more than one failed call
Recovery · When something failed, did it respond well? · After a timeout it retried, then reported honestly
Be careful not to over-specify the path. If you demand one exact sequence, you punish agents that find an equally good route, and you stop improvement. Grade the things that must be true of any good path, such as required steps, forbidden steps and a step budget. Do not grade every detail.
Building the task set
The task set is the foundation. A weak set gives false confidence, and a good one is worth more than any fancy method.
Use real tasks. Take actual requests from users, logs or the people who will use the agent. Invented tasks tend to be too clean and too like each other.
Cover the spread. Include the common cases, the hard cases, the unusual cases and the cases where the right answer is to refuse or hand back. A set made only of easy, typical tasks will show a high score and tell you little.
Include traps. Add tasks designed to catch known failures: an ambiguous request, a missing record, a user who asks for something outside policy, a tool that returns an error, a document that contains an injected instruction. Lesson 7.3 covers the last.
Write down the expected result for each task, or the checks that define success, before you run the agent. If you decide after seeing the answer, you will be tempted to accept whatever it did.
Make the environment repeatable. The agent acts on a world: databases, files, a web. For tests, use a copy of the world that starts the same every time, so that one run does not change the next. A test that refunds an order must not leave that order refunded for the next test. Use a sandbox, and reset it between runs.
Keep a few tasks hidden. If you tune the agent on the same tasks you test it on, the score will rise without the agent really improving. Hold back a portion that you do not look at while improving, and use it to check at the end.
Grow the set over time. Every real failure in production becomes a new task. The set then becomes a record of what has gone wrong, and the agent can never quietly make the same mistake again.
Choosing graders
Grader · How it works · Strength · WeaknessCode · A program checks the state or the output against rules · Fast, cheap, exact, repeatable · Only for things that can be checked mechanically
A model · A language model applies a rubric to the output or trajectory · Handles free text at scale · Can be biased, inconsistent or fooled. Must be checked against humans
A human · A person judges · Best on subtle quality · Slow, costly and varies between people
Use code wherever you can, a model for the rest and humans to check the model and to settle hard cases. The model grader needs particular care. Test it by having humans grade a sample of 50 to 100 outputs and measuring how often the model agrees. If it agrees 90 per cent of the time, you can use it; if 65 per cent, fix the rubric first. Give the model grader a clear rubric with yes or no questions, the task, the output and, where relevant, the trajectory, and ask it to explain its reasoning before giving a verdict. Beware of known biases, such as favouring longer answers.
How many tasks do you need?
A pass rate from a handful of tasks is a noisy number. If an agent passes 9 of 10, the true rate could easily be 70 or 98 per cent. The more tasks, the tighter the estimate. A simple formula gives the margin. If the observed pass rate is p and you have n independent tasks, an approximate 95 per cent margin of error is 1.96 × √(p(1 − p) ÷ n).
For p = 0.9:
With n = 50, the margin is 1.96 × √(0.9 × 0.1 ÷ 50) = 1.96 × √0.0018 = 1.96 × 0.0424 = 0.083, or 8.3 percentage points. A 90 per cent score means the true rate is somewhere from about 82 to 98 per cent.
With n = 200, it is 1.96 × √0.00045 = 0.042, or 4.2 points.
With n = 400, it is 0.029, or 2.9 points.
Note that quadrupling the tasks only halves the margin. This matters when you compare two versions. Suppose version A scores 88 per cent and version B scores 91 per cent on 100 tasks. The difference of 3 points is smaller than the margin on either score, which is about 6 points. You cannot tell which is better. To detect a 3-point difference reliably, you need hundreds of tasks, or you must run both versions on the same tasks and look at the tasks on which they differ, which is a more sensitive comparison.
Predict first: an agent passes 90 per cent of 50 test tasks. A change is made and it now passes 94 per cent of the same 50. Is the new version better? How wide is the uncertainty on each score? Think before reading on.
The margin on each score is about 8 points, so 90 and 94 per cent overlap heavily. The change of two tasks out of fifty is within noise. The honest conclusion is "possibly better, not proven". To settle it you would add more tasks, or look at the specific tasks that changed: if four tasks went from fail to pass and none from pass to fail, that is more convincing than the totals suggest.
Consistency: the same task, many runs
An agent is not deterministic. Run it twice on the same task and you may get two different paths and two different results. So a single run per task hides an important fact: how often it succeeds on that task. Measure it by running each task several times.
Two numbers are useful.
Pass at k asks whether the agent succeeds at least once in k tries. If the chance on one try is p, then pass at k is 1 − (1 − p)ᵏ. This suits cases where you can try again, such as generating code that you then test.
All k of k, sometimes called pass to the k, asks whether the agent succeeds on every one of k tries. It is pᵏ. This is the right measure when the agent must be dependable, such as a customer-facing agent that handles the same kind of request all day.
For p = 0.9:
On one run it passes 90 per cent.
At least once in three tries: 1 − 0.1³ = 99.9 per cent.
All three of three: 0.9³ = 72.9 per cent.
All five of five: 0.9⁵ = 59.0 per cent.
The two measures tell opposite stories. An agent that is right 90 times in 100 looks nearly perfect if you can try three times and keep the best, and disappointing if every run must be right. Which is relevant depends on how the agent is used. For anything customer-facing or high-stakes, the all-of-k number is the honest one, and it falls quickly as k grows. A test that runs each task only once flatters the agent.
In practice you will find that tasks are not equal. Some always pass, some always fail and a few flip. The flipping tasks are the most informative: they are where the agent is on the edge, and where changes to the instructions, the tools or the model will show up first. Look at the per-task results across runs, not only the average.
Reading the results
A single score is a starting point. Break the results down.
By kind of task. An overall 88 per cent may hide 98 per cent on routine tasks and 60 per cent on the hard ones. Report by category.
By failure type. Sort failures into causes: wrong tool chosen, wrong argument, misread result, gave up early, looped, ignored an instruction, invented a fact. The most common cause is where to work first. A fix to the most common failure is worth more than polishing the rest.
By cost and time. Record steps, tokens, cost and elapsed time per task. An agent that passes 95 per cent at ₹4 a task and one that passes 96 per cent at ₹12 are not equivalent.
By safety. Count forbidden actions attempted, even if blocked. An agent that tries to delete a record 3 times in 100 runs is a risk even if the guard stops it.
Against a baseline. Always compare with something: the last version, a simple workflow, or a human. A score has meaning only relative to what else you could have done, as Lesson 6.4 argued.
Evaluation as a habit
Evaluation is not a one-off test before launch. It runs whenever anything changes.
Run it on every change to the instructions, tools, model or settings, and block a release that makes the scores worse.
Run it on a schedule against the live system, since models, data and the outside world change. A model provider may update a model, and behaviour can shift without any change from you.
Sample real traffic. Take a few real runs a day, grade them and add the failures to the test set. Lesson 8.2 covers tracing, which makes this possible.
Keep a log of results over time so that you can see trends and the effect of each change.
Three worked examples
Example 1: a refund agent
A team builds 80 test tasks from real refund requests: 50 routine, 20 hard, 10 traps such as a request for a refund outside the policy window. Each task has a code check: the payments table must show the right refund, or no refund for the trap tasks. Trajectory checks require a lookup before a refund, forbid calling the delete tool and cap steps at 10. Each task runs three times. The agent passes 92 per cent on a single run, but passes all three runs on only 79 per cent of tasks. The margin on 80 tasks is about 6 points. The failures cluster: 60 per cent are on the 10 traps, where the agent refunds when it should refuse. The team fixes the instructions for that case and the all-three rate rises to 88 per cent.
Example 2: a model grader checked against people
A research agent writes summaries that are hard to check by code. The team writes a five-question rubric and asks a model to grade 300 outputs. Before trusting it, two people grade 60 of the same outputs. The model agrees with the people on 83 per cent of rubric answers. Disagreements are mostly on one question, "does the summary avoid unsupported claims?", where the model is lenient. The team rewrites that question with an example of an unsupported claim, and agreement rises to 91 per cent. They then use the model for scale and have people check 20 outputs a week.
Example 3: the right answer, the wrong path
A scheduling agent books the correct meeting for every task in a test set, a perfect outcome score. The trajectory review finds that in 12 per cent of runs it first tried to read the calendars of people who were not in the meeting, and a permission check blocked it. The outcomes were fine, and the behaviour was a privacy risk waiting for a gap in the permissions. The team adds a trajectory check that fails any run which attempts an out-of-scope read, and fixes the instruction that led to it.
A checklist for evaluating an agent
1. Define success for each task as a check on the world, or as a rubric.
2. Build 50 or more real tasks covering common, hard, unusual and trap cases. Hold some back.
3. Write the checks before you run the agent.
4. Make the environment repeatable and reset it between runs.
5. Add trajectory checks: required steps, forbidden steps, order and a budget. Do not over-specify.
6. Choose graders: code first, a model checked against people for the rest, people for hard cases.
7. Run each task several times and report both best-of-k and all-of-k.
8. Report the margin of error, and compare versions on the same tasks.
9. Break results down by kind, failure type, cost and safety.
10. Run on every change and on a schedule. Add real failures to the set.
Common mistakes
Grading only the answer. The path shows cost, luck and risk.
Trusting the agent's own account. Check the state of the world.
Too few tasks. Fifty tasks give a margin of about 8 points.
Reading small differences as real. Two tasks in fifty is noise.
One run per task. It hides inconsistency, and all-of-k falls fast.
Easy, invented tasks. Use real and hard ones, with traps.
Tuning on the test set. Keep some tasks hidden.
An unchecked model grader. Compare it with human grades.
Over-specifying the path. Grade what must be true of any good path.
Testing once. Models, data and the world change. Test continuously.
Key takeaways
Evaluate both the outcome, what was achieved, and the trajectory, how it got there. Check the state of the world, not the agent's claim.
Build the task set from real cases, with hard cases and traps, with expected results written first, in a repeatable environment, with some tasks held back.
Use code graders where possible, a model with a clear rubric where not, and people to check the model.
Sample size matters. A 90 per cent pass rate has a margin of 8.3 points on 50 tasks, 4.2 on 200 and 2.9 on 400.
Agents are inconsistent. A 90 per cent agent passes at least once in three runs 99.9 per cent of the time and all three runs only 72.9 per cent of the time. Use all-of-k when dependability matters.
Break results down by kind, failure cause, cost and safety, and compare with a baseline.
Evaluate on every change and on a schedule, and turn real failures into new tasks.
Check yourself
1. What is the difference between an outcome and a trajectory?
The outcome is what the agent achieved. The trajectory is the path of steps and tool calls it took to get there.
2. Why check the state of the world and not the agent's report?
An agent can say it did something that it did not do. The state of the world, such as the payments table, shows what actually happened.
3. An agent passes 80 of 100 tasks. Roughly what is the margin of error?
1.96 × √(0.8 × 0.2 ÷ 100) = 1.96 × 0.04 = 0.078, about 7.8 points either way.
4. An agent passes a task 80 per cent of the time on a single run. What is the chance it passes all 4 of 4 runs?
0.8⁴ = 0.41, about 41 per cent.
5. Why is a model grader checked against human grades?
A model grader can be biased, lenient or inconsistent. Measuring its agreement with people shows whether it can be trusted and where the rubric needs work.
6. Why keep some tasks hidden from the people improving the agent?
If you tune the agent on the tasks you test it on, the score rises without real improvement. Hidden tasks give an honest check.
Try this
Set aside ninety minutes.
1. Pick a task your agent does. Write ten real examples, including three hard ones and two traps.
2. For each, write the check on the world or the rubric that defines success, before running anything.
3. Write the trajectory rules: required steps, forbidden steps and a step and cost budget.
4. Run the agent three times on each task. Record outcomes and cost.
5. Compute the single-run pass rate, at-least-once and all-three, and use the simulator to see the margin of error with ten tasks. Work out how many tasks you need for a margin of 5 points.
6. Sort every failure into a cause and find the most common one.
7. Write which three further tasks you will add from the failures, and when you will rerun the set.
A good result is a small evaluation suite: tasks, checks, trajectory rules, a run script or procedure, and a results table by kind and failure cause. Lesson 7.2 turns from measuring behaviour to limiting it: guardrails, permissions and approvals.
Tags: Agentic AI Agent evaluation Testing Trajectories Reliability