Skip to content
Playbooks

Playbook · AI engineering

Write your first agent eval

A tool-neutral method for testing an AI agent: choose the tasks, collect real examples with the answers you expect, define passing, run it on every change and grow the set from failures.

6 min read

The short version

  • An eval is a set of example inputs, the result you expect for each, and a way to check the agent's result against it.
  • Twenty real examples with clear expected results, run on every change, tell you more than a large set that nobody runs.
  • When the agent gets something wrong in real use, add that input to the set with the correct result before you fix anything.

At the end of this playbook you will have a small test set for your agent, a written rule for what counts as passing, and the habit of running it before any change ships. A first version takes two or three days for one engineer working with one person who knows the job the agent does. After that it takes minutes to run and a little time each week to maintain.

An eval is a set of example inputs, the result you expect for each, and a way to check the agent's result against it. Nothing more. It answers the question a demo cannot: did the last change make the agent better or worse at the work it exists to do. The method below does not depend on any framework. A spreadsheet and a short script are enough to start.

Before you start

  • An agent that runs. It can be rough. You need something you can call with an input and get a result from, without clicking through a screen.
  • A written purpose. One or two sentences on what the agent is for and who uses it. If you cannot write them, stop and settle that first.
  • Real inputs. Logs, tickets, emails or requests of the kind the agent will face, with personal details removed where the test does not need them.
  • A domain expert. The person who does this work by hand today, for a few hours. They decide what a correct answer is. The engineer does not.
  • A place to keep the set. A file under version control, beside the agent's code and prompts, so the examples change in step with the agent.

The steps

  1. Pick the tasks the agent must do

    Write down the three to five tasks the agent exists for, each as one sentence with a clear input and a clear result. For example: given a customer email, find the order and say where it is. Add the things it must never do, such as answering outside its subject or acting without confirmation. Leave out everything that is only nice to have. Output: a task list of half a page that the expert agrees with.

  2. Collect real examples

    For each task, pull ten to twenty real inputs. Take the ordinary cases first, since they are most of the work. Then add the awkward ones: the request with missing information, the one that mixes two questions, the one the agent should decline. Do not write examples from imagination unless you have no real ones yet. Invented inputs are tidier than real ones and hide the problems. Output: thirty to sixty inputs, each tagged with its task.

  3. Write the answer you expect for each

    Sit with the expert and record the correct result for every input. Be specific about what you will check. For some tasks it is an exact value, such as an order number or a category. For others it is a set of facts the answer must contain and a set it must not. For an agent that takes actions, record the action you expect and its details, not only the final message. Output: every example has an expected result and a note on how to check it.

  4. Decide what passing means

    Choose the check for each task. Use an exact comparison wherever the answer is a value. Where the answer is prose, use a short list of yes or no questions, answered by a person or by a second model whose verdicts you have compared with a person's on a sample. Then set the bar for the whole set before you look at any results. Some examples must always pass, such as the things the agent must never do. For the rest, set a threshold and write down why. Output: a one-page pass rule.

  5. Run it and record the baseline

    Write a script that sends every input to the agent, applies the checks and prints which examples passed and which failed. An agent can give a different answer to the same input, so run each example several times and record how often it passes. Read the failures one by one. Some will be the agent's fault. Some will be a bad example or a bad check. Fix the set first. Output: a first score for each task and a list of known failures.

  6. Run it on every change

    From now on, no change to the prompt, the tools, the model or the data behind the agent ships without a run. Compare the result with the last one, example by example. A change that fixes three cases and breaks two is a trade, and someone should make it on purpose. Keep the results of each run with the date and what changed. Output: a run for every change and a history of scores.

  7. Add each failure you find in use

    When the agent gets something wrong in real use, add that input to the set with the correct result before you fix anything. Confirm that the new example fails. Then make the fix and confirm that it passes. Review the set with the expert every month or so and retire examples that no longer reflect the work. Output: a set that grows from real failures.

A change that fixes three cases and breaks two is a trade, and comparing run with run, example by example, is how you see it.
Start with twenty real examples and let every failure found in use add one more.

Other traps

  • Checking only the final answer. An agent can reach the right answer by the wrong route, such as calling a tool it should not have. Check the steps that matter as well as the result.
  • Tuning to the set. If you adjust the prompt until every example passes, the score stops telling you about new inputs. Hold some examples back and look at them only now and then.
  • Trusting a judge you have not checked. If a second model grades the answers, compare its verdicts with a person's first, and again whenever you change its instructions.
  • Letting the expert drop out. The set records what correct means. When the work changes, only the person who does it will notice that an expected answer is out of date.
  • One number for everything. An overall score hides which task got worse. Report results for each task.
  • Testing on clean data. If the examples come from tidy records and the agent will meet messy ones, the score flatters it. The data the agent reads is part of what you are testing.

You are done when

  • The agent's tasks and the things it must never do are written down and agreed with the expert.
  • Every task has at least ten real examples, including awkward ones.
  • Every example has an expected result and a stated way to check it.
  • The pass rule was written before the first run.
  • One command runs the whole set and reports results for each task.
  • A baseline score is recorded with its date.
  • The set runs before every change to the prompt, the tools, the model or the data.
  • The last failure found in use is now an example in the set.
  • The set has an owner and a date for its next review.

An eval is the first piece of engineering discipline an agent needs, and it is easy to leave until later. Write it before the next change, not after the next failure. If you want help building the agent itself, see AI engineering.

Know someone with the same problem? Pass it on.

A test for every change

How a team knows an agent still works after it is changed: real examples, run before any change ships. The technical name is an eval.

ExampleA made-up wholesale company's delivery agent and twenty of its past requests.

Step 5 of 5

It ships, and the set grows

When the run meets the pass rule written beforehand, the change goes live. Whatever the agent later gets wrong in real use is added to the set with the correct result.

In this example

All twenty pass and the change goes live. Later the agent misses the second question in a customer's email. That email becomes example twenty-one.

Is this your problem too?

Say what you need in one tap and tell us how to reach you.

What do you need?

Add a line about it (optional)

Get the next one by email.

New pieces, when we have something worth your time. No schedule to fill.

Info in. IQ out.

Put your information to work.

Book a callEmail us