Lesson 2 of 5 · Evaluating Agents
Task Success Metrics
Measure AI agent success: check the final state, compute success rate, pass@k and pass^k, grade answers with an LLM judge and track cost. With runnable Python.
- 7 min read
- Advanced
- Reviewed
- Judge success by the final state of the world, not the agent's claims
- Compute success rate, pass@k and pass^k from repeated runs
- Grade open-ended outputs with a rubric and an LLM judge
- Track cost, steps, time and other supporting metrics
Did it actually work?
The most important question about an agent is whether it achieved what the user wanted. The trap is believing what the agent says.
Check the outcome, not the claim
For tasks that change things (bookings, refunds, records), the strongest check compares the final state of the test environment with the state a correct run would leave:
# 1) Judge the OUTCOME (the final state of the world), not what the agent says it did
agent_reply = "Done! Booking B12 is cancelled and your 120 EUR refund is on its way."
expected = {"booking_B12": "cancelled", "refund_B12": 120.0, "emails_sent": 1}
final = {"booking_B12": "cancelled", "refund_B12": 0.0, "emails_sent": 1}
diffs = [f"{k}: expected {expected[k]}, got {final.get(k)}" for k in expected if final.get(k) != expected[k]]
print("Agent said:", agent_reply)
print("State check:", "PASS" if not diffs else "FAIL -> " + "; ".join(diffs))
# 2) Run every task several times and summarise (True = the state check passed)
results = {
"change seat": [True, True, True, True],
"cancel booking": [True, False, True, True],
"refund (policy)": [False, True, True, False],
"update address": [True, True, True, True],
"split payment": [False, False, False, False],
"rebook flight": [True, True, False, True],
}
cost_per_run = 0.04 # euros, average for this agent
trials = [r for runs in results.values() for r in runs]
k = 4
print(f"\nSuccess rate per run: {sum(trials) / len(trials):.0%} ({sum(trials)}/{len(trials)})")
print(f"pass@{k} (solved at least once): {sum(any(r) for r in results.values()) / len(results):.0%}")
print(f"pass^{k} (solved all {k} times): {sum(all(r) for r in results.values()) / len(results):.0%}")
print(f"Cost per successful run: {cost_per_run * len(trials) / sum(trials):.3f} EUR")The agent said the refund was on its way; the state shows no refund was made. A grader that read the agent's reply would have passed it. The state check didn't.
Success over repeated runs
The second half of the demo ran each of six tasks four times. Three numbers describe the results, and each answers a different question:
- Success rate per run (67%): on a random attempt, how often does the agent succeed?
- pass@k (83%): what share of tasks did it solve at least once in k tries? This measures what the agent can do.
- pass^k (33%): what share of tasks did it solve in all k tries? This measures what it does reliably.
The gap between them is the story: this agent can solve five of the six tasks, but only does two of them every time. For a customer-facing agent, pass^k is the number to watch.
Grading open-ended outputs
Some results have no exact state to compare: a reply, a summary, a report. Use a rubric of specific yes-or-no criteria, graded by code where possible and by a model where not:
import json
import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY from the environment
JUDGE_PROMPT = """You are grading a customer-support agent's final reply.
Task the customer gave: {task}
Facts from the system (the truth): {facts}
Agent's reply: {reply}
Score each item 1 (yes) or 0 (no):
- correct: every fact in the reply matches the system facts
- complete: the reply answers everything the customer asked
- policy: the reply makes no promises the facts don't support
Answer with JSON only: {{"correct": 0 or 1, "complete": 0 or 1, "policy": 0 or 1, "reason": "one sentence"}}"""
def judge(task, facts, reply):
response = client.messages.create(
model="MODEL_NAME", # often a strong model, different from the agent's
max_tokens=200,
messages=[{"role": "user", "content": JUDGE_PROMPT.format(task=task, facts=facts, reply=reply)}],
)
return json.loads(response.content[0].text)Make judges trustworthy:
- Give them the facts (here, the true system data), so they check correctness instead of guessing.
- Use narrow yes-or-no criteria, not “rate the quality from 1 to 10”.
- Calibrate: have people grade a sample too, and check that the judge agrees with them.
Supporting metrics
Success isn't everything. Track these alongside it:
| Metric | Why it matters |
|---|---|
| Cost per task and cost per successful task | Failures cost money too; the demo's agent spends 0.06 euros per success |
| Steps per task | More steps mean more cost, more time and more chances to fail |
| Time to complete | Users notice slow agents |
| Tool error rate | Often the first sign of a broken integration |
| Escalation rate | How often the agent hands over to a person, and whether that was right |
| Safety violations | Forbidden actions attempted, policies broken; should be zero |
Common mistakes
Compute the two numbers that describe an agent's reliability: can it do the task at all, and can it do it every time?
runs = {"task A": [True, True, True], "task B": [True, False, True], "task C": [False, False, False]}
# pass@3 = share of tasks solved in AT LEAST ONE of their 3 runs
# pass^3 = share of tasks solved in ALL 3 of their runs
# Print them as percentages with no decimals, like: pass@3 50% pass^3 25%
An agent's pass@5 is 90% but its pass^5 is 40%. What does this tell you?
Summary
- Judge task success by the final state or a pre-written rubric, never by the agent's own claims.
- Success rate per run, pass@k (at least once) and pass^k (every time) answer different questions; user-facing agents need pass^k.
- Grade open-ended outputs with narrow rubrics, using LLM judges that are given the facts and calibrated against people.
- Track cost per success, steps, time, tool errors, escalations and safety violations.
Next: trajectory evaluation, checking how the agent reached its result.
Finished reading? Tick it off to track your progress.