Module 9 · Lesson 1 · 15 min read

How do we evaluate AI agents?

Evaluating AI Agents

Introduction

Evaluating an AI agent is harder than evaluating a model that answers a single question, because the agent executes a series of steps, calls tools and changes the state of the world around it. In this lesson we learn how to build an evaluation test set, how to define the success criterion for each case, and why we must repeat the experiment more than once.

Learning objectives

  • Explain why evaluating an agent differs from evaluating a single answer from a language model
  • Build an evaluation test set (Evaluation Set) with normal, edge and adversarial cases
  • Distinguish between evaluating the final outcome and evaluating the trajectory
  • Write a simple automated evaluator in Python that repeats each case several times

Why is it hard to evaluate an agent?

When we evaluate a language model on a translation task, for example, we give it a text and compare the output with a reference. An AI agent, however, works in a loop: it reads the task, plans, calls a tool, reads the result, then decides the next step. This means there is more than one thing worth measuring:

  • Final outcome: Was the task actually completed? Was the correct ticket created? Is the computed number correct?
  • Trajectory: Did the agent use the appropriate tools in a reasonable order? Did it call a tool that is not allowed along the way?
  • Cost: How many steps, how many model calls and how much time did it need?
  • Reliability: Does it succeed in the same way if we repeat the experiment?

An agent may reach the correct result through a dangerous path, such as deleting a file and then recreating it, and it may follow an excellent path and then make a mistake in the last step. So a single metric is not enough.

Test tasksEval SetRun the agentRunTracingTracesMetricsSuccess · Latency · CostImprove
The evaluation cycle: a fixed set of tasks, a logged run, metrics, then improvement and re-measurement on the same set.

Building the evaluation test set

The evaluation set is a list of cases, each with: an input (the user's request and the initial state of the environment) and a success criterion written in advance. The golden rule: write the success criterion before you see the agent's outputs, so that you do not adjust the definition to fit what happened.

We recommend three categories of cases:

  1. Normal cases (Happy Path): clear requests in which the agent should always succeed.
  2. Edge cases: missing information, tools that return an error, an ambiguous request that needs a clarifying question.
  3. Adversarial cases (Adversarial): texts that try to trick the agent, such as instructions hidden inside a document (we will study them in the prompt injection lesson).

Start small: twenty carefully written cases are better than a thousand random cases nobody knows what they test.

Types of success criteria

  • Exact match: suitable for numbers and identifiers.
  • Environment state check: Did the database end up in the required state? This is stronger than checking the answer text.
  • Written rules (Rubric): a list of conditions checked by a human or another model, such as "cited the source" and "did not promise what it cannot do".

Practical example: a room-booking agent

Suppose an agent at a university books lecture rooms. It has two tools: check_room and book_room. One evaluation case might look like this: "Book a room that holds forty students on Sunday at ten o'clock". The success criterion: exactly one booking for a room with a capacity of forty or more at that time, and book_room not called before check_room. Notice that the criterion checks the outcome and the trajectory together.

The following code is a simplified evaluator (Evaluation Harness) in Python without any external libraries. The agent here is a mock function that simulates the behavior; what matters is the structure of the evaluation:

python
import random

def fake_agent(task, seed):
    # A mock agent: succeeds most of the time and sometimes fails, to simulate non-determinism
    rng = random.Random(seed)
    steps = ["check_room", "book_room"]
    if rng.random() < 0.2:
        steps = ["book_room"]  # wrong trajectory: booking without checking
    return {"steps": steps, "booked_capacity": 40}

CASES = [
    {"id": "c1", "task": "A room for forty students", "min_capacity": 40},
    {"id": "c2", "task": "A room for thirty students", "min_capacity": 30},
]

def passed(case, out):
    ok_result = out["booked_capacity"] >= case["min_capacity"]
    ok_path = out["steps"][:1] == ["check_room"]
    return ok_result and ok_path

def evaluate(trials=5):
    for case in CASES:
        wins = sum(passed(case, fake_agent(case["task"], s)) for s in range(trials))
        print(case["id"], f"{wins}/{trials}")

evaluate()

Notice that we repeat each case five times. Agents built on language models are often non-deterministic, and a case succeeding once does not mean it will succeed tomorrow.

From evaluation to improvement

Evaluation is not a final exam but a continuous loop: you run the set, read the failing cases, classify the cause of failure (ambiguous instructions, a poorly described tool, missing information in memory), make changes, then rerun the whole set to make sure you have not broken a case that used to pass. This is called regression testing. Keep every real failure case from users and add it to the set after removing personal data from it.

Anthropic's guide "Building effective agents" recommends starting with the simplest possible solution and increasing complexity only when measurement shows that this improves the results, and that is impossible without an evaluation set.

Summary

Evaluating an agent requires measuring the final outcome, the trajectory, the cost and the reliability together. A good evaluation set is small at first, carefully written, and includes normal, edge and adversarial cases. The success criterion is written before seeing the outputs, and checking the environment state is preferred over checking the text. And because agents are non-deterministic, we repeat each case several times and rerun the whole set after every change.

Terms

TermEnglishDefinition
Evaluation test setEvaluation SetA list of cases, each with an input and a success criterion defined in advance
TrajectoryTrajectoryThe sequence of steps and tool calls the agent executed
RubricRubricA written list of conditions used to judge an open-ended output
Judge modelLLM-as-a-JudgeUsing a language model to assess the quality of another model's outputs
Regression testingRegression TestingRerunning all the tests to make sure a change has not broken what used to work
Evaluation harnessEvaluation HarnessA program that runs the cases, applies the criteria and collects the results

Review questions

  1. Why is checking the final outcome alone not enough when evaluating an agent that uses tools?
  2. What is the difference between normal, edge and adversarial cases? Give an example of each for a room-booking agent.
  3. Why do we write the success criterion before running the agent?
  4. What is the benefit of repeating the same case several times?

References