Velamuvi AIAcademy

Lesson 1 of 5 · Evaluating Agents

Why Agents Are Hard to Test

Why testing AI agents is harder than testing code: random outputs, compounding errors, many valid paths and side effects, and what evaluation must measure.

  • 7 min read
  • Advanced
  • Reviewed
In this lesson you will learn
  • Explain why agent tests can't be written like ordinary unit tests
  • Show how small per-step error rates compound over long tasks
  • Explain why one test run can't tell you how reliable an agent is
  • List what an agent evaluation needs to measure

Testing something that changes its mind

Ordinary code is easy to test: the same input gives the same output, so one passing test means it works. Agents break almost every assumption that makes that true.

What makes agents hard to test:

  • Randomness. The same prompt can produce different replies, different tool calls and different results from run to run.
  • Many steps. An agent may make ten or fifty decisions in one task. Each is a chance to go wrong, and errors early on change everything after.
  • Many valid paths. Two agents can solve the same task with different tool calls in a different order. Both may be fine, so you can't just compare against one “correct” sequence.
  • Side effects. Agents book, send, refund and delete. Tests must run in a sandbox with fake or test versions of those tools, and the outcome to check is the state they leave behind.
  • A changing world. Tools return different data tomorrow, APIs change, and model providers update models. A test that passed last month may fail today without a single change to your code.
  • Open-ended answers. “Write a helpful reply” has no single right output, so some checks need a rubric and a judge.

Small errors compound

Suppose an agent gets each step right 95% of the time. That sounds reliable. But a task only succeeds if every step does:

Try it yourselfPython
import random

# 1) Small error rates compound over many steps
print("Chance an agent gets EVERY step right")
print(f"{'per step':>8}" + "".join(f"{h:>10}" for h in ["1 step", "5 steps", "10 steps", "20 steps"]))
for p in (0.99, 0.95, 0.90):
    print(f"{p:>8.0%}" + "".join(f"{p ** n:>10.0%}" for n in (1, 5, 10, 20)))

# 2) The same agent, the same test, different results
def run_agent(rng, steps=8, p=0.95):
    """A stand-in agent: each step succeeds with probability p."""
    return all(rng.random() < p for _ in range(steps))

rng = random.Random(7)
print("\nPass rate of the SAME agent, measured in 5 batches of 10 runs:")
for batch in range(1, 6):
    passes = sum(run_agent(rng) for _ in range(10))
    print(f"  batch {batch}: {passes}/10")
total = sum(run_agent(rng) for _ in range(1000))
print(f"Over 1,000 runs: {total / 1000:.0%} (expected {0.95 ** 8:.0%})")

At 95% per step, a 10-step task succeeds only 60% of the time, and a 20-step task only about a third of the time. Long tasks need very reliable steps, or ways to recover from mistakes (see the Planning and Reasoning course).

The second half of the demo is the reason evaluations need many runs. The same agent, on the same task, passed 7, 8, 3, 7 and 7 times out of 10. Had you run it once, or even ten times, you might have concluded it was excellent, or terrible. Over 1,000 runs, the true rate of about two in three emerges.

What an agent evaluation measures

A good evaluation looks at the agent from several angles, which the rest of this course covers one by one:

QuestionWhat to measureLesson
Did it achieve the goal?Task success, judged by the final state or a rubric2
Can it do it every time?Success across repeated runs2
Did it get there the right way?The trajectory: which tools, in what order, with what arguments3
What did it cost, and how long did it take?Tokens, money, time, number of steps2 and 4
What happens in production?Traces, errors, user feedback4
Did the latest change make it worse?A test suite run on every change5

Common mistakes

Practice exercise

Work out how long a task can get before compounding errors push its success rate below what you need.

Your solutionPython
p = 0.97            # chance each step succeeds
target = 0.80       # we need the whole task to succeed at least 80% of the time

# Find the largest number of steps n for which p ** n is still at least target.
# Print:  Up to <n> steps
Knowledge check

An agent passed a test once. What can you conclude?

Summary

  • Agents are hard to test because of randomness, many steps, many valid paths, side effects, a changing world and open-ended answers.
  • Per-step errors compound: 95% per step gives about 60% over 10 steps.
  • One run proves little: run tasks many times and report rates.
  • Evaluate success, consistency, trajectory, cost and time, production behaviour and regressions.

Next: task success metrics.

Finished reading? Tick it off to track your progress.