6.2.9AI Agents & Tool Use

Autonomous agent evaluation

2,849 words13 min readdifficulty · medium

Think of it like evaluating a chess player: you can't judge them on one move in isolation—you need to see the full game, their strategy, how they adapt to opponent moves, and whether they win.

What We're Actually Measuring

When we evaluate autonomous agents, we care about:

==Task success rate – Did the agent achieve the goal? (binary or partial credit) Efficiency – How many steps/tokens/API calls did it take? Generalization – Does it work on unseen tasks/environments? Safety – Did it avoid harmful actions, respect constraints? Robustness== – Does it recover from errors, ambiguous instructions, noisy observations?


Why Evaluation is Hard: The Multi-Step Problem

The agent must:

  1. Navigate to a travel site
  2. Fill search form (origin, destination, date)
  3. Parse search results
  4. Filter by price
  5. Select a flight
  6. Complete booking

Challenge: If step 3 fails (parsing error), the agent can't reach step 5. Success at the end depends on every previous step. Traditional metrics (accuracy per action) don't capture this compounding failure problem.

Why This Matters

P(success)=i=1nP(success at step i)P(\text{success}) = \prod_{i=1}^{n} P(\text{success at step } i)

If each step has90% success rate and you need 10 steps:

P(overall success)=0.9100.35P(\text{overall success}) = 0.9^{10} \approx 0.35

Even high per-step accuracy → low task success. This is why we need end-to-end evaluation on complete task trajectories.


Key Evaluation Paradigms

1. Benchmark Environments

==Simulated environments== where we can reset, control, and measure precisely.

Why this step?

  • We need a reproducible environment (can't use real websites—they change)
  • We can instrument everything: exact actions taken, hidden state, ground truth goals
  • We can run hundreds of trials cheaply

Metrics:

  • Task success rate (binary: goal achieved or not)
  • Step efficiency: efficiency=stepsoptimalstepsactual\text{efficiency} = \frac{\text{steps}_{\text{optimal}}}{\text{steps}_{\text{actual}}}
  • Token usage (for LLM-based agents)
p^=kn\hat{p} = \frac{k}{n}

Standard error (assuming binomial):

SE=p^(1p^)nSE = \sqrt{\frac{\hat{p}(1-\hat{p})}{n}}

95% confidence interval:

CI=p^±1.96SECI = \hat{p} \pm 1.96 \cdot SE

Why? Small nn → large error bars. You need n100n \geq 100 to distinguish 60% vs 70% success reliably.

Why this step? We derive from the binomial distribution because each trial is independent with fixed success probability pp. The CLT gives us the normal approximation for large nn.


2. Human-in-the-Loop Evaluation

For tasks where success is subjective or hard to formalize.

A human evaluator judges:

  • Was the response empathetic? (1-5 scale)
  • Did it resolve the issue? (yes/no)
  • Was it policy-compliant? (yes/no)

Aggregation: Average across multiple evaluators, compute inter-rater reliability (Krippendorff's α).

α=1DoDe\alpha = 1 - \frac{D_o}{D_e}

where DoD_o = observed disagreement, DeD_e = expected disagrement by chance.

Why this step? If evaluators don't agree (α<0.8\alpha < 0.8), the task definition is ambiguous—fix the rubric first.


3. Tool-Use Evaluation

Measure appropriateness and correctness of tool calls.

Good trajectory:

Thought: I'll write a Python function to find primes
Action: execute_python("def nth_prime(n): ...")
Observation: 541
Answer: The 100th prime is 541

Metrics:

  • Tool call accuracy: Did it call the right tool with valid arguments?
  • Result correctness: Is the final answer right?
  • Efficiency: Did it use unnecessary tools? (e.g., calling a calculator for 2+2)

Formula for Tool Precision/Recall:

Precision=correct tool callstotal tool calls\text{Precision} = \frac{\text{correct tool calls}}{\text{total tool calls}} Recall=correct tool callstool calls needed for optimal solution\text{Recall} = \frac{\text{correct tool calls}}{\text{tool calls needed for optimal solution}}

Why this step? Precision measures waste (hallucinated tools, wrong args). Recall measures if the agent found the right tools for the job.


Common Evaluation Benchmarks

| Benchmark | Domain | Task Type | Metric | |-----------|-----------|-----| | ==WebArena | Web Navigation | Multi-step web tasks | Task success rate | | SWE-bench | Software Eng | Resolve GitHub issues | % fixed | | HotpotQA | QA with tools | Multi-hop reasoning + Wikipedia | Exact match F1 | | GAIA | General assistance | Real-world assistant tasks | Human eval score | | ToolBench== | Tool use | API calling for tasks | Tool call accuracy + task success |

Agent task:

  1. Read issue description
  2. Navigate codebase
  3. Locate bug
  4. Write patch
  5. Verify with tests

Evaluation:

  • Does the patch pass the issue's test?
  • Does it pass all other existing tests (no regressions)?

Success rate: Top agents ~15-20% (humans ~80%)—shows how hard real-world SE is.

Why this step? Using real repos ensures ecological validity: if an agent succeds here, it might actually be useful. Synthetic benchmarks can be gamed.


Deriving an Evaluation Metric: Expected Discounted Reward

For agents in environments with partial credit (not just binary success).

R=t=1Tγt1rtR = \sum_{t=1}^{T} \gamma^{t-1} r_t

where γ[0,1]\gamma \in [0,1] is the discount factor.

Why discount?

  • Time preference: Earlier rewards are more valuable (finish sooner)
  • Uncertainty: Future is less certain—heavily discount distant rewards
  • Mathematical convenience: Ensures finite sum even for infinite horizons

Example calculation: Rewards: [10, 5, 2, 1] γ=0.9\gamma = 0.9

R=10+0.95+0.922+0.931=10+4.5+1.62+0.729=16.849R = 10 + 0.9 \cdot 5 + 0.9^2 \cdot 2 + 0.9^3 \cdot 1 = 10 + 4.5 + 1.62 + 0.729 = 16.849

Why this step? We sum because rewards are additive. We discount geometrically because each step adds one layer of uncertainty (γt\gamma^t compounds the discount).

Evaluation: Run agent on N episodes, compute:

Rˉ=1Ni=1NRi\bar{R} = \frac{1}{N} \sum_{i=1}^{N} R_i

with standard error:

SE=σRNSE = \frac{\sigma_R}{\sqrt{N}}

Safety Evaluation: Measuring What Agents Shouldn't Do

Safety constraints:

  • Don't delete files
  • Don't leave desktop
  • Don't access hidden system folders

Evaluation:

  • Hard constraint violations: Count actions that break rules
  • Safety score: 1violationstotal actions1 - \frac{\text{violations}}{\text{total actions}}

Why it feels right: Task success is the primary metric, easy to focus on.

The fix: Separately track safety violations. An agent that deletes your files while organizing them is worse than one that fails the task safely. Use a lexicographic ordering: safety first, then success.

Score={0if any hard constraint violatedtask successotherwise\text{Score} = \begin{cases} 0 & \text{if any hard constraint violated} \\ \text{task success} & \text{otherwise} \end{cases}

## Evaluation Design Principles

### 1. Compositionality: Test Skills in Isolation + Combination

Why? If an agent fails level 3, you can diagnose: is it the tool-calling (level 1), reasoning (level 2), or parsing (level 3)?

### 2. Distribution Shift: Test Generalization

Train/test split for agents:

  • In-distribution: Same task types, domains

  • Out-of-distribution: New domains, task structures

  • Adversarial: Edge cases, tricky constraints

Metric: Success rate drop from in-dist → OOD measures generalization gap.


## Ablation Studies: What Actually Matters?

To understand why an agent works, systematically remove components:

Δcomponent=ScorefullScorewithout component\Delta_{\text{component}} = \text{Score}_{\text{full}} - \text{Score}_{\text{without component}} n2(z1α/2+z1β)2σ2δ2n \approx \frac{2(z_{1-\alpha/2} + z_{1-\beta})^2 \sigma^2}{\delta^2}
n2(zα/2+zβ)2pˉ(1pˉ)δ2n \geq \frac{2(z_{\alpha/2} + z_\beta)^2 \bar{p}(1-\bar{p})}{\delta^2}

where pˉ=pA+pB2\bar{p} = \frac{p_A + p_B}{2} (pooled success rate).

Example: Detect 5% improvement from 50% baseline, α=0.05\alpha=0.05, β=0.2\beta=0.2:

n2(1.96+0.84)20.50.052784 samples per variantn \geq \frac{2(1.96 + 0.84)^2 \cdot 0.5 \cdot }{0.05^2} \approx 784 \text{ samples per variant}

Why this step? We need enough samples to distinguish signal from noise. Too few → can't tell if improvement is real or luck.


Recall Explain to a 12-Year-Old

Imagine you have a robot that you want to test to see if it's good at doing chores. You can't just watch it once—you need to give it lots of different chores and see if it finishes them all.

The problem: Some chores have many steps, like "make a sandwich" (get bread, get peanut butter, spread it, etc.). If the robot messes up any step, the whole sandwich is ruined. So you can't just check if it's good at spreading—you have to see if it can do the entire chore start to finish.

Different ways to test:

  1. Fake kitchen: You build a pretend kitchen where you can easily see what the robot does and reset everything. This is like a video game level for the robot.
  2. Report card: You watch the robot and give it grades on different skills (speed, neatness, safety).
  3. Real kitchen: You let it try in your actual kitchen—scary but shows if it really works.

What you measure:

  • Did it finish the chore? ✓
  • How long did it take? ⏱️
  • Did it break anything or make a mess? 🛡️
  • Can it handle new chores it's never seen?🌟

The hard part: If your robot only works on the chores you trained it on, it's like a student who memorized answers without understanding—fails on new questions!



Connections

  • Reinforcement Learning Basics – reward functions, episode structure
  • LM Prompting Strategies – ReAct, Chain-of-Thought (what agents use internally)
  • Tool Use in Language Models – how agents call functions/APIs
  • Multi-Agent Systems – evaluating coordination, communication
  • Benchmark Design – principles for creating good test suites
  • Human Evaluation Protocols – inter-rater reliability, rubric design
  • A/B Testing – online evaluation statistics
  • Safety Alignment – constraint satisfaction, red-teaming

#flashcards/ai-ml

Why can't we evaluate agents with simple accuracy metrics? :: Agents take multi-step actions in dynamic environments. Success depends on entire trajectories, not individual decisions. One early mistake can cascade and prevent goal completion.

What is task success rate in agent evaluation?
The percentage of episodes where the agent achieves the specified goal, measured end-to-end across the full interaction.
Why do we use discount factor γ in cumulative reward?
(1) Earlier rewards more valuable (time preference), (2) future is uncertain (risk), (3) ensures finite sum for infinite horizon tasks.

Formula for discounted cumulative reward :: R=t=1Tγt1rtR = \sum_{t=1}^{T} \gamma^{t-1} r_t where γ ∈ [0,1] is discount factor, rtr_t is reward at step t.

What's the compounding failure problem?
If each step has probability p of success and you need n steps, overall success is pnp^n. Even high per-step accuracy → low task success for long trajectories.
Three main evaluation paradigms for agents
(1) Benchmark environments (simulated, controlled), (2) Human-in-the-loop (subjective tasks), (3) Tool-use evaluation (API calling correctness).
Why use simulated environments like WebArena?
Reproducibility—real websites change. Can instrument all actions and state. Cheap to run many trials. Control ground truth.
What does tool call precision measure?
correct tool callstotal tool calls\frac{\text{correct tool calls}}{\text{total tool calls}}—measures wasted or hallucinated tool usage.
What does tool call recall measure?
correct tool callstool calls needed\frac{\text{correct tool calls}}{\text{tool calls needed}}—measures if agent found the right tools for optimal solution.
Standard error for success rate with k successes in n trials
SE=p^(1p^)nSE = \sqrt{\frac{\hat{p}(1-\hat{p})}{n}} where p^=k/n\hat{p} = k/n. Need large n for tight confidence intervals.
Why separately track safety violations?
Task success alone is insufficient. An agent that succeds but violates constraints (deletes files, accesses forbidden areas) is worse than safe failure. Use lexicographic ordering: safety first.
What is ablation study in agent evaluation?
Systematically removing components to measure their contribution: Δ=ScorefullScorewithout\Delta = \text{Score}_{\text{full}} - \text{Score}_{\text{without}}. Identifies which parts are critical.
Difference between online and offline evaluation
Offline: pre-collected tasks, reproducible, fast. Online: live deployment with real users, captures true performance but expensive and risky. Use offline for dev, online for validation.
What is generalization gap in agent evaluation?
Success rate drop from in-distribution test tasks to out-of-distribution tasks. Measures how well agent handles novel situations beyond training.
Why hierarchical evaluation (unit → integration → end-to-end)?
Enables diagnosis. If end-to-end fails, you can isolate whether problem is in basic tool use (unit), reasoning (integration), or full task complexity (E2E).
Sample size needed for A/B test with δ improvement detection
n2(zα/2+zβ)2pˉ(1pˉ)δ2n \geq \frac{2(z_{\alpha/2} + z_\beta)^2 \bar{p}(1-\bar{p})}{\delta^2} where pˉ\bar{p} is pooled success rate. Need ~800 samples per variant for 5% improvement from 50% baseline.

Concept Map

assesses

contrasts with

breaks into

includes

includes

includes

causes

P success = product of steps

requires

example

enables

measures

Autonomous Agent Evaluation

Multi-step Interaction

Differs from Static ML

What We Measure

Task Success Rate

Efficiency

Safety & Robustness

Compounding Failure

End-to-End Trajectory Eval

Benchmark Environments

WebArena

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Autonomous agent evaluation matlab hai ki humara AI agent kitna acha kaam kar raha hai, especially jab wo multiple steps mein decisions le raha hai aur environment ke sath interact kar raha hai. Traditional ML models mein toh bas ek input diya aur ek output check kiya—right ya wrong. Lekin agents ka kaam complex hota hai. Imagine karo ki ek robot ko kehte ho "mere liye coffee banao"—use pehle kitchen jana padega, phir cup dhoondhna, coffee powder dalna, pani garam karna, sab kuch.Agar koi bhi ek step galat ho gaya, toh pori task fail. Isliye evaluation bhi challenging hai.

Jo baat samajhni zaroori hai wo ye hai ki agent ki harek step matter karti hai. Agar har step mein 90% success chance hai aur 10 steps lene hain, toh overall success sirf 0.9^10 = 35% reh jata hai. Yahi compounding failure problem hai. Isliye hum task success rate dekhte hain (kya goal achievehua?), efficiency dekhte hain (kitne steps lage?), aur safety bhi check karte hain (kya agent ne kuch galat ya dangerous nahi kiya?).

Evaluation kaise karte hain? Teen main tarike hain: (1) Benchmark environments—jaise WebArena jahan simulated websites hotiain aur hum controlled testing kar sakte hain, (2) Human-in-the-loop—jahan humans judge karte hain subjective tasks ko, aur (3) Tool-use evaluation—jahan check karte hain ki agent sahi tools use kar raha hai ya nahi. Real-world mein deploy karne se pehle offline testing karte hain benchmarks par, phir gradually online rollout karke real users ke saath validate karte hain.

Bottom line: Agent evaluation sirf accuracy check karna nahi hai—ye dekhna hai ki pora multi-step process smoothly chal raha hai, agent naye situations handle kar sakta hai, aur safe bhi hai. Tabhi hum confidently keh sakte hain ki ye agent production-ready hai!

Go deeper — visual, from zero

Test yourself — AI Agents & Tool Use

Connections