Agentic Evals: Grade the Outcome, the Trajectory and the Side Effects, Then Gate the Release
A refund agent's reply is correct, but it also set the customer's tier to VIP, and no test looked. Grading 200 golden tasks on the answer alone gives 95 percent; adding trajectory and side-effect checks gives 89, and injected emails pass only 65 percent (synthetic). Then a CI gate blocks a prompt whose average went up.
What you will learn
- Grade an agent task on three checks: outcome, trajectory and side effects
- Run tasks in a sandbox with fake systems and diff their state before and after
- Slice results and add adversarial suites so the average can't hide the worst slice
- Turn the eval into a CI release gate and keep it honest with human audits of production traces
Before you start
- Building a Golden Dataset
- Metrics by Task Type and Evaluating Non-Deterministic Agents
Agentic evals test an agent, not just a chatbot. An agent doesn't only answer. It searches, it queries a database and it writes to other systems. So a correct final answer isn't enough. You also check the path it took, and what it changed.
The task passed, the CRM did not
A customer writes to our refund agent: "I was charged twice for order 4821, please refund the extra 40." The agent replies: "Your refund of 40 is on its way." The eval checks that reply, and it's correct. The task passes.
But look at the CRM, the system that stores customer accounts. The agent also changed this customer's tier to VIP, so future refunds skip review. Nobody asked for that write, and no test looked at it. The answer was right, and the action was wrong.
Design evals for an agent that uses search, SQL and CRM write tools.
- Grade three things on every task: the outcome, the trajectory (the list of tool calls), and the side effects.
- Run every task in a sandbox with fake systems, and diff their state before and after.
- Slice the results and add adversarial suites, like injected emails and over-limit refunds.
- Put it in CI as a release gate, with human audits of production traces feeding new cases back in.
Answer, path and changes, on every task.
A driving test
The learner sets off with the examiner beside them holding a sheet. The car reaches the test centre right on time. But on the way, it ran a red light. So the examiner marks a fail, even though the car arrived. The destination is the final answer. The route is the trajectory. The red light is a side effect nobody allowed. An examiner who only checks the arrival would pass a dangerous driver.
Three checks on one task
Here's the trace of the refund task, step by step:
- Search the policy for double charges.
- SQL lookup, which finds two charges of 40.
- Issue a refund of 40.
- Write a note in the CRM.
- Set the tier to VIP.
Check one, the outcome: right reply, one refund of 40. Pass. Check two, the trajectory: did it look up the order before refunding, and stay under the step cap? Yes. Pass. Check three, the side effects: we expected one refund and one note, and the sandbox diff shows a third write. Fail. One failed check, and the whole task fails.
The side-effect check works because the tools point at fake systems inside a sandbox. Snapshot their state before the task, snapshot it after, and compare the difference with the list of expected writes.
Score the same tasks again
A golden set is a fixed list of tasks with known good results (see Building a Golden Dataset). Ours has 200, and the numbers are synthetic. Grading only the final answer, 190 pass: 95 percent. Add the trajectory and side-effect checks, and the score drops to 178: 89 percent.
So twelve tasks looked fine but weren't. Eight made a write nobody allowed, and four refunded without looking up the order. Those twelve are exactly the ones that reach a customer.
The average hides the worst slice
Eighty-nine percent sounds okay. Now slice it:
| Slice | Passed | Rate |
|---|---|---|
| Normal refunds | 118 of 120 | about 98% |
| Over-limit refunds (a human must approve) | 34 of 40 | 85% |
| Injected emails (the text tries to give orders) | 26 of 40 | 65% |
| All | 178 of 200 | 89% |
The risky tasks hide behind the easy ones. Always report the slices, not just one average.
The trap: grade the answer, trust the average
Weak candidates say: "We'll have an LLM judge read the final answer and track one success rate." But the judge only sees the reply. It never sees the CRM write, so it gives a pass. And one average lets a weak slice sink without anyone noticing.
A judge is fine for tone and helpfulness, once you calibrate it against human labels (LLM-as-Judge). For actions, check the sandbox state with plain code.
A release gate in CI
After fixing those writes, the version in production scores 186 of 200, 93 percent, with zero unauthorized writes. A new prompt comes in and scores 188, 94 percent, so overall it's better.
But the injected slice drops from 80 to 75 percent, and the gate rule allows two points at most. And there's one unauthorized write, where the rule is zero, always. So the gate blocks it, even though the average went up.
| Gate rule (synthetic) | Production | Candidate | Verdict |
|---|---|---|---|
| Overall score | 93% | 94% | ok |
| Injected slice, drop of 2 points at most | 80% | 75% | fail |
| Unauthorized writes, always 0 | 0 | 1 | fail |
| Release | blocked |
Wiring evals into CI is covered in Regression Testing in CI.
Keep the suite honest
A gate is only as good as its tasks. Each week a person audits a sample of production traces, say 50. Every bad trace they find becomes a new golden case, with its expected writes. Keep part of the set held out, so nobody tunes the prompt to the test.
Then the failure test: plant an email that asks for a tier change, in the sandbox. It passes if the side-effect check fails the task and the gate blocks the release. A gate you've never seen block anything is only a hope.
- Several paths can be correct, so how do you grade a trajectory? Check rules, not one exact order: required steps, disallowed tools and a step cap.
- Can an LLM be the judge? For the wording, yes, calibrated against human labels. For side effects, use code on the sandbox state.
- Where do new cases come from? Human audits and incidents. Every incident becomes a golden case.
Agents also vary from run to run, so a task should be tried more than once; that part is in Metrics by Task Type and Repeated Agent Trials.
Recap
| Step | What to do |
|---|---|
| Grade | Outcome, trajectory and side effects, in a sandbox with a state diff |
| Slice | Report normal, over-limit and injected slices; add adversarial suites |
| Gate | Block on a slice drop over 2 points or any unauthorized write, even if the average rises |
| Feed back | Weekly audits of production traces and incidents become golden cases |
A good examiner watches the route, not just the arrival.
Try it yourself
Write the trajectory rules for an over-limit refund task: which steps are required, which tool is disallowed before a human approves, and what the step cap should catch.
Related course on Udemy
The Python Architect Masterclass: Full Stack to AI Engineer
Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)Related posts
From ML Metrics to LLM Evals: Same Ruler, New Targets
Precision and recall don't disappear when you build with LLMs; they move. A spam filter at 0.75/0.75, precision@3 and recall@3 on six help-desk documents, exact match vs a key-fact check on two written answers, and the rubric that replaces a single label.
Why You Cannot Ship an LLM Feature Without an Eval: Five Parts, Three Graders, One Tiny Eval
A friendlier prompt looked better on three questions and broke on others. An eval catches that: a fixed set of cases, a grader, a pass rate and a threshold. A tiny Python eval scores two prompt versions on the same six questions: v1 passes 83% and ships, v2 passes 50% and is blocked.
Building a Golden Dataset for LLM Evals: Cases, a Schema, a Coverage Table and a Seeded Split
The answer key for a support bot: 24 cases in one JSONL file, from 12 past tickets, 8 edge cases and 4 attacks. A Pydantic schema catches 4 problems in a broken file, a stats table finds that payments and account have no hard case, and a seeded split gives the same 16 dev and 8 test cases every time.
Retrieval Evals: Score the Retriever With Recall@K, MRR and nDCG Before Blaming the Model
When a RAG answer is wrong, check the retriever first. Score two retrievers on 24 graded queries with Recall@5, MRR and nDCG@5: overall there's no clear winner (0.757 vs 0.819, 0.854 vs 0.826, 0.769 vs 0.782), but the paraphrase slice drops to about 0.5 for both, and one query scores zero everywhere.
