Chapter 30 of 32 · ~22 min read & lab+80 XP
Chapter 30 · Agentic AI

Evaluating Agents: Trajectory Grading, Tool-Call Accuracy, pass^k & SWE-bench

Why 'vibes-based' testing breaks production agents: dual-axis Outcome + Trajectory grading, Tool-Call Precision/Recall, the brutal math of pass@k vs. pass^k, and building a 3-layer CI Eval Pyramid!

What Is It?

Agent Evaluation grades both final outcomes and intermediate tool trajectories, measuring production consistency with pass^k (all k runs succeed) alongside pass@k.

Why Is It Required?

An agent with 80% single-run accuracy only succeeds 5 times in a row 33% of the time (0.8⁵); trajectory evals expose brittle tool selection before users hit it.

Everyday Analogy: Judging a surgeon not just by whether the patient survived once, but by whether every checklist step succeeds reliably 100 surgeries in a row.
Why ML Engineers & Data Scientists Actually Need This

An agent with 80% single-run accuracy looks great on pass@5 (99.97%!) — but on pass^5 (5 consecutive reliable runs for an enterprise user), it drops to a shocking 32.8%!

ML / AI Engineer

Shipping prompt or tool-schema changes without an automated Trajectory + Outcome Eval Suite is flying blind — one tweak that fixes Bug A silently breaks 12 other flows.

Data Scientist

Tracking Tool-Call Precision/Recall, First-Try Schema Validity, and pass^k turns fuzzy agent quality into crisp, optimizable engineering metrics!

Interview & Debug Edge

Huge 2026 ML/AI Engineer interview question: 'Explain the difference between pass@k and pass^k for evaluating AI agents, and how do you grade an agent trajectory?'

Step 0 · Test Your Gut Before Any Math!

If an agent has single-run accuracy p=0.80p = 0.80, what is pass^5 (the probability it succeeds on ALL 5 consecutive user runs)?

What You Will Master in This Chapter
  • Grade agents on BOTH Final Outcome (DB/test assertions) and Intermediate Trajectory (tool selection, argument validity, step efficiency)
  • Contrast optimistic pass@k (≥ 1 success in kk tries) against enterprise reliability pass^k (ALL kk tries succeed!)
  • Build a 3-Layer Agent Eval Pyramid: fast deterministic unit checks → golden trajectory replays → calibrated LLM-as-a-Judge & human audits
  • Use mocked/recorded tool environments in CI so eval suites run deterministically in seconds for pennies
Plain-English Symbol Decoder · Click Any Symbol Before We Begin
1 / 3
pass@k=1−(1−p)k\text{pass@}k = 1 - (1 - p)^kSay aloud:“pass at k equals one minus one minus p to the k”
Plain-English Meaning
Probability that an agent succeeds at least once in kk independent attempts — measures upper-bound capability (e.g., SWE-bench with unit-test selection).
Everyday Example
At p=0.80,k=5p = 0.80, k = 5: pass@5 = 99.97%.
Story-First Intuition, Visual Diagrams & Interactive Walkthroughs

Grading an agent only on its final text reply is like grading a pilot only on whether the plane landed — ignoring that they flew through a thunderstorm and burned 3× the fuel! Trajectory + Outcome Evals grade both the destination and the flight path, while pass^k tests whether the pilot lands safely every single time!

1. Dual-Axis Grading: Trajectory + Final Outcome

Dual-Axis Agent Grading: Trajectory Quality + Final Outcome1. Trajectory Grade (How it got there)• Right tools selected? (Precision/Recall)• Valid JSON arguments on 1st try?• Step efficiency vs. optimal path?2. Outcome Grade (Did it solve it?)• Unit tests / DB state assertions pass?• Answer grounded in citations?• Zero policy or safety violations?
Agent Evaluation grades BOTH the Final Outcome (correctness) AND the intermediate Trajectory (did it call the right tools, pass valid arguments, and avoid redundant loops?)!

Unlike static QA models, agents take multi-step actions with side-effects. Always grade two axes:

  1. Outcome Grade (Deterministic Assertions): Did the final database state, edited git repo (pytest), or cited answer match ground truth?
  2. Trajectory Grade (Process Quality): Did the agent select the right tools (Tool Precision/Recall), emit valid JSON arguments on the first try, and finish near the optimal step count without looping?

2. The Brutal Math of `pass@k` vs. `pass^k`

pass@k (Optimistic Best-of-k) vs. pass^k (Production Consistency) for p = 0.80pass@5 (≥1 of 5 succeeds)99.97%pass^1 (Single-run accuracy)80.0%pass^5 (ALL 5 of 5 succeed!)32.8%
Critical Reliability Gap: pass@k asks if the agent succeeded at least ONCE in kk tries (looks great!), while pass^k asks if it succeeded ALL kk times in a row (what enterprise users experience!)

Because LLM agents are stochastic, running an eval once hides flakiness. Run each golden scenario k=3k = 3 to 55 times and report both:

  • pass@k (1 - (1 - p)^k): Can the agent solve it at all?
  • pass^k (p^k): Can customers trust it every time?

Try the interactive calculator below — watch how raising pp from 80% to 96% transforms pass^5 from 32.8% to 81.5%!

Formula Anatomy · Click Any Colored Piece to Decode It
Reliability Gap: pass@k vs. pass^k

Click each term to see why production teams optimize for consistency, not lucky cherry-picks.

pass@k (Peak Capability)

Probability of at least 1 win out of kk tries — approaches 100% rapidly as kk grows.

In our example: 99.97% at p=0.8, k=5
Put it together with real numbers: Benchmarks like SWE-bench (code with unit tests) and τ-bench (customer support with DB state assertions) prove that deterministic environment checks + pass^k are the gold standard for agents!
Animated Mini-Lab • 5.4

pass@k vs. pass^k Production Reliability Calculator

pass@5 (≥1 success)
100.0%
pass^5 (ALL 5 succeed!)
32.8%

3. The 3-Layer Agent Eval Pyramid (CI/CD Ready)

The 3-Layer Production Agent Evaluation PyramidTop: LLM-as-a-Judge + Human Audits (Weekly)Mid: End-to-End Trajectory & Golden-Set Replay (Every PR)Base: Fast Deterministic Code/Schema/Tool Unit Tests (Every Commit, $0)
Production Agent Eval Pyramid: fast deterministic Unit/Tool-Schema checks at the base, Trajectory & Golden-Set tests in the middle, and LLM-as-a-Judge + Human Audits at the top!

Don't run slow, expensive LLM-as-a-Judge calls on every commit! Structure your evals like a software testing pyramid:

  • Base (Every Commit, $0): Deterministic schema validation, policy gate unit tests, and mocked tool-dispatch tests.
  • Middle (Every PR): 30–100 Golden Trajectory Replays against recorded/sandboxed mock APIs (fast, reproducible, zero live side-effects!).
  • Top (Nightly / Pre-Release): Rubric-scored LLM-as-a-Judge (calibrated against human labels!) + weekly human error audits.
Pause & Check · Quick Intuition Pulse

Why should PR-level agent trajectory evals run against mocked/recorded tool environments instead of live production APIs?

“Wait, I'm Confused...” · Teacher Office Hours Q&A

The exact honest questions almost every beginner wonders — answered in plain English without hiding behind jargon.

Start small! 20–30 real, high-signal golden scenarios (covering happy paths, missing data, tool failures, and prompt-injection attempts) will immediately catch 90% of regressions — then grow the set every time you spot a live bug!

Interactive Visual Lab
Lab Challenge: Explore the 60 FPS Trajectory Grader and test pass@k vs. pass^k in the calculator.
Interactive Animation • 5.4 Deep Lab

Trajectory Step-by-Step Grader & pass^k Release Gate

Grade tool selection, argument schemas, final state assertions, and multi-run pass^k consistency.

Tool Precision
[Tool Precision]Called search_kb + get_invoice (2/2 expected) ✓
[Arg Validation]Zero Pydantic schema errors on 1st attempt ✓
[Outcome Assert]Exact refund = $49.00 matched DB ground truth ✓
[pass^5 Score]5/5 repeated runs passed → Ready for Production ✓
0%
Tool Precision
Intuition Takeaway: Evaluate agents on both Outcome and Trajectory, measure true production reliability with pass^k (not just pass@k), and run a 3-layer Eval Pyramid over deterministic mock environments in CI.
Where This Powers Real ML, Deep Learning & Generative AI

CI/CD Regression Gates for Prompt & Tool Changes

Blocks PR merges whenever Tool Precision, Outcome Pass Rate, or pass^3 drops below baseline on mocked golden trajectories.

Production NumPy & PyTorch Code Patterns
# Agent Reliability Metric: pass@k (at least 1 success) vs. pass^k (all k runs succeed)
def pass_at_k(p: float, k: int) -> float:
    """Probability that at least one of k independent trials succeeds."""
    return 1.0 - (1.0 - p) ** k

def pass_power_k(p: float, k: int) -> float:
    """Probability that ALL k consecutive production runs succeed (reliability)."""
    return p ** k

def tool_trajectory_f1(pred_tools: list[str], gold_tools: list[str]) -> float:
    pred, gold = set(pred_tools), set(gold_tools)
    tp = len(pred & gold)
    prec = tp / max(1, len(pred))
    rec = tp / max(1, len(gold))
    return 2 * prec * rec / max(1e-9, prec + rec)

p_single = 0.85
print(f"p={p_single:.0%} | pass@5={pass_at_k(p_single, 5):.1%} | pass^5={pass_power_k(p_single, 5):.1%}")
print(f"Tool Trajectory F1: {tool_trajectory_f1(['search', 'calc', 'format'], ['search', 'calc']):.2f}")
Common ML Interview Traps & Numerical Pitfalls
Trap #1: Reporting only pass@5 in a stakeholder review and claiming '99% accuracy' for an 80%-reliable agent.
Best Practice: Always report single-run pass^1 AND multi-run consistency pass^k alongside p95 cost and latency!
Chapter Mastery Check (+80 XP)
Score: 0 / 1
1What does pass^k measure that pass@k hides?

Apply What You Learned — Solve Matching Coding Problems