How to Evaluate an AI Agent: A Practical Guide to Evals

Build an eval for your AI feature or agent: collect realistic cases, choose code checks or a model judge, grade outcomes and tool calls, and read the score honestly.

Short answer: an eval is a repeatable test for an AI feature. It has three parts: a set of realistic inputs, a script that runs your app on each one, and a grader that scores each output. Run it before and after every change to a prompt, model or tool, and you replace “it seems better” with a number you can trust. For agents, grade the outcome the user cares about, and check the steps the agent took on the way.

Why AI features need evals

Traditional tests check that code returns an exact value. Model output varies, so the same prompt can pass on Monday and fail on Tuesday, and a small prompt change can fix one case while breaking three others. Without an eval you only find out from users. With one, every change gets a score before it ships.

Step 1: Collect the inputs

Use the most realistic source you have, in this order:

  1. Real traffic. Logs or transcripts of what users actually send. Remove personal data first.
  2. Things that went wrong. Bug reports, support tickets and the cases someone complained about. These are the most valuable.
  3. Hand-written cases. Ask the people who know the domain for ten examples, including the hard ones.
  4. Synthetic variations of those real examples, to fill gaps. Do not invent cases from nothing; they come out too easy.

Start with 15 to 100 cases. Fewer than 15 and one flaky case swings the score; far more and nobody reviews them. Read every case before you use it.

Step 2: Decide how to grade

  • Code checks where the answer is objective: valid JSON, the right category, a number in range, the expected tool called. Cheap, fast and exact.
  • A model as judge for qualities like correctness, tone or completeness. Give the judge a short rubric with pass and fail examples, ask for a verdict plus a reason, and spot-check its grades against your own.
  • Human review for a sample, especially early on, to confirm the automated grades mean what you think.

Grade outcomes, not wording. “Did the reply give the correct refund window?” is a good check; “does the reply match this exact sentence?” fails good answers.

Step 3: Evaluating agents

An agent takes several steps and calls tools, so grade at two levels:

  • Outcome: did the task get done? The ticket was created with the right fields, the answer is correct, the file contains the fix.
  • Trajectory: did it get there safely? It called the right tools, never called a forbidden one, did not loop, and stayed within a step and cost budget.

Tools with real side effects, such as sending email or writing to a database, should be replaced with test versions during evals. Record the calls the agent makes and grade those instead.

Step 4: A minimal eval runner

This Python script runs a support assistant on each case and uses Claude as a judge with a simple rubric. Replace answer() with a call to your real app.

import json
import anthropic

client = anthropic.Anthropic()
MODEL = "claude-opus-5-5"

CASES = [
    {"input": "Can I get a refund after 3 weeks?", "expect": "Refunds are within 2 weeks; politely say no and offer help."},
    {"input": "Can I pay in installments?", "expect": "Yes, 3 monthly payments."},
]

def answer(question: str) -> str:
    """Your app. Replace with the real entry point."""
    response = client.messages.create(
        model=MODEL,
        max_tokens=512,
        system="You are the support assistant for an online course. Answer briefly.",
        messages=[{"role": "user", "content": question}],
    )
    return "".join(b.text for b in response.content if b.type == "text")

def judge(question: str, expect: str, reply: str) -> dict:
    rubric = (
        "Grade the reply. PASS only if it is consistent with the expected behaviour "
        "and contains no invented facts. Respond with JSON: "
        '{"verdict": "PASS" or "FAIL", "reason": "one sentence"}'
    )
    response = client.messages.create(
        model=MODEL,
        max_tokens=200,
        system=rubric,
        messages=[{"role": "user", "content": f"Question: {question}\nExpected: {expect}\nReply: {reply}"}],
    )
    text = "".join(b.text for b in response.content if b.type == "text")
    return json.loads(text[text.find("{"): text.rfind("}") + 1])

passed = 0
for case in CASES:
    reply = answer(case["input"])
    grade = judge(case["input"], case["expect"], reply)
    passed += grade["verdict"] == "PASS"
    print(grade["verdict"], "|", case["input"], "|", grade["reason"])

print(f"{passed}/{len(CASES)} passed")

Save every run’s inputs, outputs, grades, token usage and cost to a file, so you can compare runs and read the failures, not just the score.

Step 5: Read the number honestly

  • Run each case more than once. Model output varies, so one run can mislead. With 25 cases run twice, a pass rate is only accurate to roughly ±14 percentage points; small differences between two prompts are noise.
  • Keep a held-out set. If you tune a prompt against the same cases you measure on, you will overfit. Keep some cases aside and check them only at the end.
  • Watch cost and latency too. A prompt that scores two points higher but doubles the tokens may not be worth it.
  • Check for truncation. If a response stopped at max_tokens, the grade reflects the limit, not the model.

When a case fails, our prompt debugging checklist helps find out why before you change the wording.

Make it part of shipping

Run the eval on every prompt, model or tool change, and in CI for anything that reaches users. Add each new production failure as a case. Over time the eval becomes the most valuable asset in your AI feature: it is what lets you upgrade models and change prompts with confidence. Building these quality gates is week 4 of the live cohort and the self-paced course.

FAQ

What is an LLM eval?

A repeatable test for a feature that uses a language model: a set of inputs, a way to run your app on each, and a grader that scores the outputs, so you can measure whether a change made things better or worse.

How many test cases do I need?

Start with 15 to 100 realistic cases. Fewer makes the score jumpy; many more is fine later, but only if someone still reads the failures.

Can I use Claude to grade Claude?

Yes, a model-as-judge works well for qualities that code cannot check, if you give it a clear rubric, ask for a reason with each verdict, and compare a sample of its grades with your own.

How do I evaluate an AI agent?

Grade the final outcome the user cares about, and separately check the trajectory: which tools were called, whether any forbidden action happened, and whether it stayed within a step and cost budget. Replace tools that have side effects with test versions.

How often should I run evals?

On every change to a prompt, model, tool or retrieval setup, and before every release of the feature.

Start building your AI product

Five weeks from now you could have a working AI product with real users. Join the next live cohort, or start the self-paced course today.

Join the live cohortStart self-paced today