svish.dev

← All lessons · AI Agents · 10 min

Evaluating agents before you trust them

Build a tiny eval harness, catch a regression a prompt tweak introduced, and learn why "it worked when I tried it" isn't evidence.

You changed the prompt, the demo still works, you ship — and a week later support tickets say orders “can’t be found”. Agents fail in ways that unit tests don’t catch, because the behaviour isn’t fully determined by your code. The fix is the same one software always used: tests, adapted for fuzzy outputs. In the agent world they’re called evals.

The smallest useful harness

An eval is a list of inputs with checks on the output — not exact string matches (the wording may vary) but facts that must be present. Run the agent over all cases, report a pass rate, and print exactly what failed. This continues the agent from the previous lesson.

CASES = [
    ("where is order A100", ["shipped", "2 days"]),
    ("where is order B200", ["processing", "5 days"]),
    ("where is order Z999", ["couldn't find"]),
    ("tell me a joke", ["only help with orders"]),
]

def evaluate(agent):
    failures = []
    for question, must_contain in CASES:
        answer = agent(question)
        missing = [s for s in must_contain if s not in answer]
        if missing:
            failures.append((question, answer, missing))
    passed = len(CASES) - len(failures)
    print(f"{passed}/{len(CASES)} passed")
    for q, a, m in failures:
        print(f"  FAIL {q!r}: missing {m} in {a!r}")
    return passed / len(CASES)

evaluate(run_agent)
4/4 passed

Catching a regression

Now simulate a “harmless” change that lowercases the order ID before the lookup — the kind of tweak a prompt change can cause:

def buggy_model(messages):
    action = scripted_model(messages)
    if "tool" in action:
        action["args"]["order_id"] = action["args"]["order_id"].lower()
    return action

evaluate(lambda q: run_agent(q, model=buggy_model))
2/4 passed
  FAIL 'where is order A100': missing ['shipped', '2 days'] in "I couldn't find that order."
  FAIL 'where is order B200': missing ['processing', '5 days'] in "I couldn't find that order."

Notice the agent never crashed and its answers still sound fine — only the eval notices. Run it before every change and you ship regressions to nobody.

How real evals grow up

  • Cases come from reality. Every real failure becomes a new case. The set grows with the product.
  • Check facts, not phrasing. Use must-contain, structured outputs, or a second model as a grader — and spot-check the grader by hand.
  • Track a number over time. Pass rate per version, plus cost and latency, so you see trade-offs instead of arguing about vibes.
  • Test the tools separately. Deterministic tools get ordinary unit tests; evals are for the fuzzy part.

Exercises

  1. Add three more cases: a lowercase ID, a missing ID, and a request to cancel an order. Which fail?
  2. Add latency: time each agent(question) call and report the slowest. What would your budget be?
  3. Make the check stricter: require the answer not to contain “sorry” for valid orders.

Takeaways

  • “It worked when I tried it” isn’t evidence; a pass rate over many cases is.
  • Evals are cheap to start (a list and a loop) and pay for themselves on the first regression.
  • Reliability is a number you track, not a feeling.