Evaluate both the outcome and the actions used to reach it
Agent evaluation checks both the final outcome and the trajectory that produced it: observations, decisions, tool choices, argument accuracy, permissions, unnecessary steps, recovery, safety, cost, and stopping behavior. A correct final answer is not a successful run if the agent reached it through unsafe or wasteful actions.
What You Will Learn
- Evaluate both task outcome and the trajectory used to reach it.
- Choose deterministic checks, human review, and calibrated model judges appropriately.
- Separate headline success from safe-success.
- Turn production incidents into representative regression cases.
Evaluate the journey as well as the destination
A final answer can be correct even when the agent chose the wrong tool, used invalid arguments, accessed an unauthorized resource, repeated needless steps, or recovered unsafely. A scenario suite should therefore define the expected outcome, allowed actions, important forbidden actions, and the trace evidence required for success.
Deterministic evaluators are strongest for clear facts such as numeric limits, schema conformance, tool sequence, and citations. Human reviewers handle nuanced high-risk judgment. Model judges can scale rubric-based review, but must be calibrated against human labels and monitored for bias or instability. Public benchmarks are signals, not replacements for application-specific cases.
What to evaluate in an agent run
Test the complete trajectory against explicit criteria
Build versioned scenario suites from realistic tasks, failures, edge cases, and adversarial inputs, with allowed actions and explicit success conditions.
Record the observable trajectory: decisions, tool calls and arguments, results, approvals, errors, latency, cost, and final output.
Score task success, tool correctness, unnecessary steps, recovery behavior, and policy or safety compliance separately.
Use deterministic checks where rules are clear, human review for nuanced high-risk cases, and model judges only with calibrated rubrics and caveats.
Compare releases on the same scenarios, inspect critical traces, and convert production incidents into regression cases.
Instructional figure
Evaluate every important point in the trajectory
Where can an agent fail even when the final answer looks correct?
Worked Example: Task success can hide unsafe trajectories
A fixed offline suite contains 20 representative cases. Seventeen end with the correct task result.
- Task-success rate = 17 ÷ 20 = 0.85 = 85%.
- Trace review finds policy violations in 2 of those 17 otherwise successful runs.
- Runs that are both successful and free of those violations = 17 − 2 = 15.
- Safe-success rate = 15 ÷ 20 = 0.75 = 75%.
What the result means: Reporting only 85% would hide two unsafe paths. The 75% safe-success rate better describes deployable behavior.
Choosing an evaluator
A Realistic Example: Testing a refund agent
Cases include a valid refund, an order owned by another user, a duplicate request, a tool timeout, and a prompt injection hidden in ticket text. The agent must succeed safely in each case.
Read the Mechanism in Code
Use the label and note to understand what this block represents before reading each line.
score = {
"task_success": task_success(trace),
"tool_accuracy": tool_and_argument_score(trace),
"unnecessary_steps": count_redundant_actions(trace),
"safe_recovery": recovery_score(trace),
"policy_violations": count_policy_violations(trace),
}
assert trace.stops_within(max_steps=8)
assert trace.did_not_repeat(completed_refund)Hands-On Runnable Python Lab: Separate Raw Success from Safe Success
Six synthetic runs cost $0.02 each. Four complete the task, but one of those violates policy. Three therefore count as safe successes. The fixtures are illustrative results, not measurements of a commercial agent.
- Represent each run with separate task_ok and policy_ok flags.
- Count raw successes without conflating them with compliance.
- Count the intersection of success and compliance.
- Divide total attempt cost by safe successes and apply a zero-policy-violation release gate.
An unsafe success must not count as a safe success
A check means pass; a cross means fail. Only runs passing both columns count toward safe success. All six attempted runs contribute to cost.
runs = [
{"id": 1, "task_ok": True, "policy_ok": True, "cost": 0.02},
{"id": 2, "task_ok": True, "policy_ok": False, "cost": 0.02},
{"id": 3, "task_ok": False, "policy_ok": True, "cost": 0.02},
{"id": 4, "task_ok": True, "policy_ok": True, "cost": 0.02},
{"id": 5, "task_ok": False, "policy_ok": True, "cost": 0.02},
{"id": 6, "task_ok": True, "policy_ok": True, "cost": 0.02},
]
n = len(runs)
raw = sum(run["task_ok"] for run in runs)
safe = sum(run["task_ok"] and run["policy_ok"] for run in runs)
violations = sum(not run["policy_ok"] for run in runs)
total_cost = sum(run["cost"] for run in runs)
for run in runs:
print(run["id"], "safe success:", run["task_ok"] and run["policy_ok"])
print(f"raw success: {raw}/{n} = {raw / n:.1%}")
print(f"safe success: {safe}/{n} = {safe / n:.1%}")
print(f"total cost: USD {total_cost:.2f}")
if safe:
print(f"cost per safe success: USD {total_cost / safe:.2f}")
else:
print("cost per safe success: undefined (zero safe successes)")
print("policy gate:", "PASS" if violations == 0 else "BLOCK")
1 safe success: True
2 safe success: False
3 safe success: False
4 safe success: True
5 safe success: False
6 safe success: True
raw success: 4/6 = 66.7%
safe success: 3/6 = 50.0%
total cost: USD 0.12
cost per safe success: USD 0.04
policy gate: BLOCKWhat This Run Shows
- Run 2 contributes to raw success but not safe success; it also blocks the release gate.
- Runs 3 and 5 are policy-compliant failures, distinct from unsafe behavior.
- The denominator and all-attempt cost make the operational metric reproducible.
Use the aggregate metrics to compare candidates, then inspect failed trajectories to understand causes. A lower score may originate in retrieval, a tool contract, planning or evaluation itself.
From the Exercise to an Application
Experiment: Make run 2 policy-compliant while keeping everything else unchanged.
Safe success rises to 4/6 and cost per safe success falls to $0.03. The policy gate passes, but other predeclared quality or latency gates may still fail.
Summary / Key Takeaways
- Agent evaluation must score both the final outcome and the trajectory used to reach it.
- Useful trajectory metrics include tool selection, argument correctness, unnecessary actions, recovery, policy compliance, latency, cost, and stopping behavior.
- Deterministic evaluators are best for clear rules, human review is valuable for nuanced high-risk judgments, and model judges need calibrated rubrics and validation.
- A high task-success average can hide unsafe trajectories, unauthorized actions, or rare critical failures.
- Evaluation sets should contain realistic tasks, edge cases, adversarial inputs, expected actions, and explicit success conditions.
- Public benchmarks are useful signals but may be contaminated or mismatched to the application’s real environment.
- Production failures should be converted into regression cases and rerun before future releases.
Verified Further Reading
These primary research papers and current official specifications support the concepts and implementation guidance in this lesson. The explanations, analogies, exercises, and code above remain original teaching material.
AgentBench: Evaluating LLMs as Agents
Multi-environment benchmark covering agent reasoning and decision-making in interactive tasks.
AgentDojo: A Dynamic Environment to Evaluate Prompt Injection Attacks and Defenses for LLM Agents
Research benchmark for tool-using agents exposed to untrusted external content and prompt-injection attacks.
OSWorld: Benchmarking Multimodal Agents for Open-Ended Tasks in Real Computer Environments
Research benchmark for agents operating real desktop applications through visual and accessibility interfaces.