Evaluating AI agents
I recently built a suite of agents that did research for users. A user asks a research question, and the agents go and read what is out there and come back with an answer and its sources. I have written up how that got built separately, and this post picks up where that one leaves off.
A base agent splits the question, task agents work the directions in parallel, and the base agent writes the answer from their summaries.
No ground truth to check against
I have built classification models before, and those come with a labelled test set you can measure against.
Research answers do not have that. Two good answers to the same question can look nothing alike, so there is nothing to compare against. The answer on its own is also not enough to judge - to know whether the references are any good you have to know what was out there to be found, so you end up reading the sources as well. Reviewing one answer meant reading the question, the answer and every reference the agent pulled.
Two options we dropped
We first looked at user ratings. We had thumbs up and down in the product, so the data was already there.
Sessions scoring 4 or below are 15% of all traffic and 41% of the rated set. Read the ratings as a sample of the product and the product looks worse than it is, and the middle of the distribution never shows up at all.
The numbers behind this chart
| Quality | Sessions | Rated | Rating rate |
|---|---|---|---|
| 1 | 8 | 4 | 50% |
| 2 | 18 | 8 | 44% |
| 3 | 40 | 12 | 30% |
| 4 | 80 | 12 | 15% |
| 5 | 130 | 9 | 7% |
| 6 | 180 | 7 | 4% |
| 7 | 210 | 6 | 3% |
| 8 | 180 | 9 | 5% |
| 9 | 110 | 11 | 10% |
| 10 | 44 | 9 | 20% |
Per 1,000 sessions. Figures illustrative, obfuscated from the real ones.
This made ratings a bad measure for us. The complaints were over represented, and we got almost nothing back from the sessions in the middle, which is where most of them were. A prompt change that moved an answer from good to mediocre would not have shown up in the rating numbers.
The second option was manual review, which is what we were already doing. It worked as a spot check, but we were changing prompts several times a day and there was no way to review by hand at that pace.
The judge, and what it scored
So I proposed using LLM-as-judge. With help from the PM, we came up with a series of criteria that the LLM could judge on. Six in the end, and they are not all graded the same way.
| Criterion | What the judge is asked | Produces | |
|---|---|---|---|
| 1 | Reference relevance | For each reference pulled, does it bear on the question | Yes or no each, 9 of 12 is 0.75 |
| 2 | Reference utilization | For each reference, does the answer draw on it | Yes or no each, then a ratio |
| 3 | Claim groundedness | For each substantive claim, is a reference supporting it | Yes or no each, then a ratio |
| 4 | Answer effectiveness | Does it resolve the question that was asked | One score, 1 to 3 |
| 5 | Absence of fluff | How much carries nothing the user did not have | One score, 1 to 3 |
| 6 | Answer structure | Can the user find the part they came for | One score, 1 to 3 |
The first three are counted and the last three are scored, and all the arithmetic happens in code rather than in the model.
We originally called the second one reference recall, which was the wrong name. Recall means "of the sources that existed, how many did you find", and to answer that we would have needed a reference set we never had. What we were actually measuring was how much of what the agent pulled the answer ended up using, so we renamed it utilization.
For the first three the judge never produces a score at all, only a yes or a no per item. The rest of the design:
| Decision | Why |
|---|---|
| Binary per item, ratio in code | Judging one reference yes or no is much easier than rating twelve of them at once, and code does the division |
| 3-Point scores, not 1 to 5 | With five levels almost everything came back as a 3 or a 4 |
| Reasoning before the score | Without this the model picks a number first and the reasoning follows it |
| An evidence quote with every score | A reviewer can check the quote without reading the whole trajectory, which is what made the validation below possible |
| No aggregate from the judge | Weights can change without re-running the judge, and a single number hides which of the six moved |
| Two calls, split by input size | Relevance and groundedness need the whole trajectory; the rest need only the question and the answer |
Call 1, the counting criteria
This call needs the whole trajectory, so it is a large input. None of the three questions can be answered without the references the agent pulled.
You are checking one research answer against the references the agent
pulled. Answer every question below yes or no. Do not score, do not rate,
and do not compute any ratios.
For each reference in the trajectory:
relevant does this reference bear on the question that was asked?
used does the answer draw on this reference?
For each substantive claim in the answer:
grounded is there a reference in the trajectory that supports it?
Return one object per question, with the quote that settles it:
{"id": "...", "check": "relevant|used|grounded", "answer": "yes|no",
"evidence": "<quote>"}
The ratios are computed from those objects in code.
Call 2, the scoring criteria
This call only needs the question and the answer, so the input is small.
You are scoring one research answer. For each criterion below, write the
reasoning first, then the score, then an evidence quote from the answer.
Do not produce an overall score.
Scores are 1, 2 or 3:
1 fails the criterion
2 partially meets it
3 meets it
## effectiveness
Does the answer resolve the question that was asked, including the parts
that were implied but not stated? An answer that is correct but addresses
a neighbouring question scores 1.
## fluff
Tally the sentences carrying no information the user did not already have:
restatements of the question, hedges, filler conclusions. Then score.
Fluent is not the same as informative, and length is not evidence of
either.
## structure
Could the user find the part they came for without reading the whole
thing?
Return one object per criterion:
{"criterion": "...", "reasoning": "...", "evidence": "<quote>", "score": 1|2|3}
Validating the judge against the team
We turned the criteria into a judge prompt and validated it by having the team review a sample of the verdicts. Around 100 answers, each marked pass or fail by someone on the team, compared against what the judge said.
| reviewer said | ||||
|---|---|---|---|---|
| pass | fail | all | ||
| judge said | pass | 66agree | 12too lenient | 78 |
| fail | 6too harsh | 16agree | 22 | |
| 72 | 28 | 100 | ||
100 sampled answers, each scored by the judge and by someone on the team. 72 of them passed, which is why raw agreement overstates how well the judge was doing. Figures illustrative, obfuscated from the real ones.
The overall agreement number looked fine. It looked worse once we split it by what the reviewer had said - the judge agreed with the team on nearly all the answers they passed, and on far fewer of the ones they failed. The judge was being too lenient.
Reading through the disagreements, the judge was favouring longer answers and well written ones. An answer that read well but was comfortably off the point would get through. This is a known failure mode of LLM judges.
Two things in the prompt above came out of that. We asked for the reasoning before the score, so the model is not picking a number and then justifying it. And the fluff criterion now asks for a count of the padded sentences before the score instead of an impression, since padding was the thing the judge was getting wrong.
The number we reported in v1 was raw agreement. Chance-corrected agreement accounts for that, and the gap was large - the sample above is 82% raw agreement and a kappa of 0.52. Reporting kappa instead was the next thing on my list and I did not get to it.
Running it on every change
I then set up an internal test suite using this eval that we ran for every prompt change. It ran in three layers.
| Suite | Examples | Runs on | Time | Cost |
|---|---|---|---|---|
| Smoke | 20 | Every commit | ~3 min | ~$5 |
| Regression | 100 | Every deploy | ~15 min | ~$25 |
| Adversarial | 30 | Questions built to break the agent, not sampled from what users ask |
Examples came out of production logs, with some synthetic ones for cases the logs did not cover.
We split it into layers because of cost and time. Putting the regression suite on every commit would have been five times the cost and 15 minutes of waiting per commit, so only the smoke suite runs there.
What it caught
Mostly small regressions from prompt changes. Rewording the base agent's planning instruction would drop the structure scores, and since we kept the scores per criterion we could see which one had moved instead of watching a single average wobble.
The repeated failure these tests surfaced was context blowing up during deep research, regularly pushing past 700k of our 1M window.
At a 10% fetch back rate the handles version gets about 6.6x the tool call history for the same context, and the fetched results it does pull back are the ones the answer actually leans on.
Figures illustrative, obfuscated from the real ones. The fetch back rate is a dial because we never measured ours.
The cause was clear from a trace. A lot of the tool results were large - fetched pages, PDFs - and once a result is in the history it stays there. Three task agents working their way through a question would put a few hundred thousand tokens of raw page text into the context.
Two things came out of this and both showed up in the scores. The agent had fewer back-and-forth loops to work with before compaction, and the answers got less reliable as the window filled up.
Compaction was already in the system, so that was what we used when a run filled up. Compaction drops information permanently, and what was filling the context here was raw page text we could keep somewhere else. So I decided to write tool results to text files in Cloudflare R2 and put a reference in the context instead, with a simple tool to fetch the full content when the agent needed it. That saved a lot of tokens without losing access to anything the agent had already read, and it left compaction for the runs that still filled up. The elision rule and the stub format are in the build post, along with the thresholds we settled on.
The tradeoff
The cost of this was an extra call whenever the agent wanted something out of its history, and that is latency the user pays for.
What we got was a much longer tool call history before compaction. I do not have before and after eval numbers on answer quality, so the extra runway is the only thing I can claim here. Whether it made the answers better is something I would want to measure and did not.
If I did this again I would build the eval suite first. v1 was lenient and I knew it was lenient, but once it existed every prompt change had a number attached to it, and the context problem showed up as a pattern across runs instead of a hunch. The next steps would have been chance-corrected agreement and a bigger validation sample.