Vocabulary for this course

The terms the chapters assume, in plain words. You can open this from any chapter.

baseline
The score you compare a change against, usually from the version already in use.
confidence interval
A range around a measured score that shows how much it could move if you tested a different sample.
embedding
A list of numbers that represents a piece of text, placed so texts with similar meaning sit close together.
exact match
A score of one only when an answer matches the expected text after ignoring case, punctuation and spacing, and zero otherwise.
golden set
A fixed list of questions with the answers or properties you will accept, used to compare changes.
groundedness
The share of claims made by a model that the sources you supplied actually support.
judge
A model asked to score or compare answers against a rubric, used when fixed rules cannot measure quality.
recall
The share of everything that should have been found that was actually found.
regression
A drop in quality against a result you had already accepted, caught by rerunning the same tests.
rubric
A written list of criteria with descriptions of what a good, acceptable or failing answer looks like.
semantic similarity
A score for how close two texts are in meaning, usually by comparing their embeddings.
threshold
The cut-off score at which you accept a result rather than reject it or send it for review.
token F1
A score that combines two overlap rates, one for covering the expected text and one for avoiding extra text, so both must be good.

Evaluating AI systems

Evaluating agents

An agent emits a path as well as an answer. Score the tool calls, the order and the stopping point, run each case more than once, and count the failure modes instead of hiding them in one pass rate.

Part 8 of 10

Advanced17 min readBack to Courses

The answer is only half the output

An agent produces two things: an answer and a path to it. The answer can be scored like any other output. The path — the tools it called, the arguments, the steps it took and the way it stopped — is the part a final-answer metric cannot see, and it is where most of the interesting failures live.

A right answer reached by guessing is a latent failure: the next input will not be so lucky. A wrong answer reached by a sensible path is often a retrieval or data problem rather than a reasoning one. Scoring only the answer collapses those two into the same red cell.

Trajectory evaluation separates them. You record every step, then ask questions about the record: did it search before answering, did it call the refund tool, did it stop inside the budget? Those are cheap checks and they explain a failure in a way a score never does.

Check the path with rules, not exact match

The obvious metric is exact match against a reference trajectory, and it is almost always the wrong one. Two correct paths can differ in the order of two independent lookups, or in whether the agent retried a failed call. Exact match fails both and rewards a memorised sequence.

Check properties instead. A required set — the tools that must appear somewhere. A forbidden set — the ones that must not. An order constraint — search before answer, draft before send. A budget — no more than six steps, no more than three calls to the paid API. Each is a rule you can explain to a reviewer.

Rules are not a judge and do not need to be. They catch the failures you already know about, cheaply, on every run. A model judge is for the residue: whether the path was reasonable, whether the agent gave up too early, whether a tool was chosen for a defensible reason.

A trajectory evaluator

from langsmith import evaluate

def trajectory_ok(run, example):
    calls = [step["name"] for step in run.outputs["trajectory"]]
    required = set(example.outputs["required_tools"])
    return {"key": "required_tools", "score": required <= set(calls)}

evaluate(agent, data="agent-cases", evaluators=[trajectory_ok])

Required, forbidden, ordered, bounded

Run the three recorded trajectories through the checks, then add a run that calls the refund tool and confirm the safety gate fails it even when the answer is right.

Output
Click "Run" to execute your code

Run it more than once

An agent is nondeterministic even at temperature zero, because the tools are. A search returns a different top result, an API times out, a model samples a different tool. One run tells you what happened once, not what the system does.

Run each case k times and report two numbers. pass@k is the chance that at least one run succeeds — useful for a task where a retry is acceptable. pass^k is the chance that all k succeed — the number that matters when a user sees every attempt and a failure has a cost.

The gap between them is consistency. A system with pass@5 of 0.95 and pass^5 of 0.55 succeeds eventually and fails often, which is exactly how an agent feels unreliable in production even when the demo works. Report the distribution of steps and cost too: a median of three steps with a tail of twenty is a different product from a flat four.

A forbidden action is a gate, not a score. One refund issued without approval fails the release even if the answer was perfect, because the damage is already done.

Count the failure modes

A single pass rate hides which failure you have. Count categories instead: wrong tool, wrong arguments, loop, gave up, claimed success without acting, and unsafe action. Each maps to a different fix — a tool description, a schema, a budget, a prompt, a verification step or a permission. Keep the taxonomy small enough that two people apply it the same way: six categories, not sixty.

Fixtures make the count stable. Replace every live tool with a deterministic fake that returns a recorded response, and record the calls it received. The evaluation then measures the agent rather than the weather, and a failure can be replayed exactly.

Keep one live smoke test outside the scored set. Fixtures tell you the logic is right; a live run tells you the integration still exists, and neither substitutes for the other. A fixture that never fails tests the happy path and nothing else, so add a timeout and a malformed response to the set.

pass@k is not pass^k

Compute both numbers for k equal to one, three and five. At five runs the pass@5 is perfect while pass^5 is one third, which is the consistency gap a single run hides.

Output
Click "Run" to execute your code

Check what you learned

One question at a time. A wrong answer explains itself — take another go.

Part 1 of 5

What does a trajectory add to an answer-only evaluation?