Library

Volume 2 · AI Evaluation Frameworks

Notebook
Sign in

Section 59

Agent Evaluation (Task Completion Rate, Tool Selection Accuracy, Recovery Rate, Trajectory Evaluation)

1,098 words · about 5 min

59.1 Why Agent Evaluation Is a Different Problem Than Single-Turn LLM Evaluation

A single LLM call has one input and one output to score. An agent produces a trajectory — a sequence of reasoning steps, tool calls, intermediate observations, and a final outcome. Evaluating an agent means evaluating the whole path, not just the destination: two agents can reach the same correct final answer through very different quality of process (one efficient and safe, one wasteful and one step from a costly error), and that difference matters operationally even when the “final answer” metric looks identical.

59.2 Agent-Specific Metrics

Metric Description How to Measure
Task completion rate % of tasks successfully completed Automated check against expected outcome + human review
Step efficiency Average steps to complete task vs. optimal Trace/log analysis
Tool selection accuracy Did the agent pick the right tool for each step? Trace analysis against expected tool sequence
Tool call success rate % of tool calls that executed without error Log analysis
Plan quality Was the plan logical, minimal, and well-ordered? LLM-as-judge over the trace
Recovery rate % of errors the agent successfully recovered from Log/trace analysis
Safety compliance % of actions that passed guardrails Automated policy check
Trajectory similarity How closely the path matches an expert/reference trajectory Sequence alignment vs. reference trace

59.3 Trajectory Evaluation in Practice

class AgentEvaluator:
    def evaluate_task(self, task, agent_trace, expected_outcome):
        return {
            "task_completed": self._check_completion(agent_trace, expected_outcome),
            "steps_taken": len(agent_trace.steps),
            "optimal_steps": self._compute_optimal(task),
            "tools_correct": self._evaluate_tool_choices(agent_trace),
            "safety_violations": self._check_safety(agent_trace),
            "cost": self._compute_cost(agent_trace),
            "latency": agent_trace.total_time,
            "reasoning_quality": self._llm_judge_reasoning(agent_trace),
            "recovery_events": self._count_recoveries(agent_trace),
        }

    def _llm_judge_reasoning(self, trace):
        """Use a separate LLM to evaluate the agent's reasoning quality."""
        prompt = f"""Evaluate the quality of this agent's reasoning trajectory:

        Task: {trace.task}
        Steps taken: {trace.steps}
        Outcome: {trace.outcome}

        Score 1-5 on:
        1. Logical coherence (did each step follow sensibly from the last?)
        2. Efficiency (minimal unnecessary steps or redundant tool calls?)
        3. Error handling (did it detect and recover from failures gracefully?)
        4. Tool usage appropriateness (right tool, right arguments, right order?)
        """
        return llm.evaluate(prompt)

    def _count_recoveries(self, trace):
        """A 'recovery event' is: tool call failed/returned unexpected result
        → agent detected it → agent adjusted approach → task still succeeded."""
        recoveries = 0
        for i, step in enumerate(trace.steps):
            if step.is_error and i + 1 < len(trace.steps):
                if trace.steps[i + 1].adjusted_strategy:
                    recoveries += 1
        return recoveries

59.4 Trajectory Evaluation Approaches Compared

Approach Description Strength Weakness
Outcome-only Score only the final answer/result Simple, cheap Blind to inefficiency, near-misses, unsafe intermediate actions
Reference trajectory matching Compare step sequence to an expert-authored reference path Precise, catches inefficiency Requires authored references for every task variant; penalizes valid alternate paths
LLM-as-judge over full trace A judge model scores the whole trajectory holistically Flexible, no reference needed, catches reasoning quality Judge biases (Section 61), higher eval cost
Rubric-based step scoring Each step type has an explicit pass/fail rubric (tool chosen correctly? arguments valid? guardrail respected?) Deterministic, auditable, fast Needs rubric maintenance per tool/task type

Architect’s recommendation: Combine outcome-based scoring (did the task succeed — the metric stakeholders care about) with rubric-based step scoring for safety-critical or expensive tool calls (deterministic, auditable, catches near-misses), and reserve LLM-as-judge trajectory scoring for holistic reasoning-quality sampling rather than as the sole gate — it’s valuable signal but shouldn’t be the only defense given its known biases.

59.5 Recovery Rate as a First-Class Metric

Real agent failures in production are dominated not by “the agent never makes an error” (impossible at scale) but by “the agent doesn’t notice or recover from an error.” A high recovery rate — the agent detecting a failed tool call, unexpected data, or a dead-end plan and adjusting — is often a better predictor of production reliability than raw task-completion rate measured only on clean, well-behaved test cases. Evaluation datasets should deliberately inject failure conditions (a tool returns an error, an API times out, retrieved data is empty or contradictory) to measure recovery behavior directly, not just hope it emerges from happy-path testing.

Interview Q&A — Section 59

Q1: Two agents both complete a task successfully. How do you determine which one is actually better? A: Task completion alone is insufficient — I’d compare the full trajectories on step efficiency (did one take 3 steps and the other 11 for the same result?), tool selection accuracy (did one pick the minimal correct tool set while the other flailed through several wrong tools first?), cost and latency (directly tied to step count and tool calls), and safety compliance (did either take an action that violated a guardrail even though the final outcome was fine — a near-miss that’s a warning sign for future runs). I’d also check recovery events: an agent that hit an error and cleanly recovered demonstrates more robust behavior than one that got lucky and never encountered a hiccup, even if both “succeeded” on this particular run.

Q2: How do you evaluate an agent’s ability to recover from errors, given that error scenarios are rare in normal test traffic? A: I deliberately construct an adversarial evaluation set that injects failure conditions — tool calls that return errors, timeouts, empty or contradictory retrieved data, malformed API responses — rather than relying on organically encountering them in happy-path tests. For each injected failure, I measure whether the agent detects the failure (doesn’t silently proceed with bad data), what strategy it falls back to, and whether the task still completes correctly or degrades gracefully (e.g., asks for clarification, escalates to a human) rather than either hallucinating a result or looping indefinitely. Recovery rate on this adversarial set becomes a tracked metric in the regression gate (Section 62), since it’s a strong leading indicator of production reliability that a purely happy-path golden dataset would never reveal.

Q3: Why is LLM-as-judge alone insufficient for agent trajectory evaluation, and what do you pair it with? A: An LLM judge scoring a whole trajectory is flexible and needs no authored reference path, but it inherits the biases covered in Section 61 (favoring verbose/confident-sounding reasoning, potential self-preference, inconsistency across runs) and it’s relatively expensive to run over full traces at scale. I pair it with deterministic rubric-based step scoring for anything safety- or cost-critical — e.g., “was this tool call’s arguments schema-valid,” “did this action require and receive human approval,” “was this within budget/guardrail limits” — which is fast, auditable, and immune to judge bias. The LLM judge is then reserved for the harder-to-formalize dimension: was the overall reasoning coherent and efficient, sampled periodically rather than gating every single run.