Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 62

Measuring Agent Quality: Completion & Accuracy

Recommended resources

Introduction

In our last lesson, we designed the "battlefield" for our agent: a representative evaluation dataset. This gives us a standardized set of tasks to consistently test against. Now that we have the what, we need to define the how—how do we measure success and failure? Simply knowing an agent passed or failed a task isn't enough; as engineers, we need to understand why.

This lesson focuses on how to define and calculate key metrics for agent quality, including task completion rate and accuracy. We will move beyond these high-level indicators to a more granular, diagnostic set of metrics that align with an agent's internal "observe-think-act" loop. Your background in reliability engineering will be useful here, as we'll see that the principles governing complex distributed systems apply directly to the sequential steps of an agent's workflow. We will explore a framework for classifying metrics, learn how to calculate them, and discuss how to automate the evaluation of more subjective qualities like the soundness of an agent's plan.


The Sobering Math of Agent Reliability

Before diving into specific metrics, it's crucial to understand why granular, per-step measurement is non-negotiable for building reliable agents. A common mistake is to focus only on the final task outcome while ignoring the fragility of the multi-step process that produces it.

This is a classic problem in systems reliability, sometimes known as Lusser's Law. It states that the total reliability of a system with components in series is the product of the individual component reliabilities. An agent executing a multi-step plan is a perfect example of such a system.

The Math That's Killing Your AI Agent | Towards Data Science

This article from Towards Data Science provides a stark and essential framing for why per-step accuracy is so critical. It directly connects agent performance to the mathematics of compound probability.

Read the introduction and the section "The Calculation Vendors Skip." Pay close attention to the calculation demonstrating how an agent with 85% per-step accuracy has only a ~20% success rate on a 10-step task.

As the article makes clear, an agent that seems "pretty good" on individual steps can be mathematically guaranteed to fail on most complex, real-world tasks. An overall Task Completion Rate of 20% is a failing grade. This single metric tells us we have a problem, but it doesn't tell us where the failures are occurring. To debug and improve the system, we need metrics that illuminate the entire execution trajectory.


A Framework for Agent Metrics: Goal, Plan, Act

To structure our metrics in a way that provides diagnostic value, we can map them to the core phases of an agent's operation: formulating a Goal, creating a Plan, and taking Action.

This Venn diagram provides a useful model for categorizing agent quality metrics across the Goal, Plan, and Act phases. We will use this as a framework for our discussion.

This "GPA" framework helps us move from evaluating just the final outcome (the Goal) to assessing the quality of the reasoning and execution process (the Plan and the Act).


1. Goal Metrics: Was the Final Outcome Correct?

These metrics evaluate the end result of the agent's work. They are the most fundamental measure of performance.

  • Task Completion Rate (TCR): This is the most basic metric. It is the percentage of tasks in your evaluation suite that the agent completes successfully.

    A task is "successful" if it meets all the success criteria you defined in your evaluation dataset (as we discussed in the previous lesson). While simple, this is your top-line KPI.

  • Accuracy and Factuality: Completion is binary, but accuracy is a matter of degree. An agent might complete a task but provide an answer that is subtly incorrect, incomplete, or contains hallucinations. Measuring factuality requires a more sophisticated approach than a simple pass/fail check. A robust method involves a multi-step process.

Stanford CME295 Transformers & LLMs | Autumn 2025 | Lecture 8 - LLM Evaluation

This section of a Stanford lecture on LLM Evaluation provides a clear, structured methodology for quantifying the factuality of a text output.

Watch the segment on the factuality dimension. The lecturer breaks down the process into three key steps: Decomposing the output into a list of atomic facts. Checking each fact individually (often using RAG or web search). Aggregating the results, potentially with weights for importance.

This decompositional approach is a powerful pattern. Instead of asking "Is this paragraph factual?", you ask a series of smaller, verifiable questions. This turns a complex, subjective assessment into a quantifiable metric. The final score is often an aggregation, like a weighted average of the correctness of each atomic fact.

Other key Goal metrics shown in the "Agent GPA" diagram include Answer Relevance (does the answer actually address the user's intent?) and Groundedness (is the answer based on provided source documents, especially in RAG scenarios?).


2. Process Metrics: Was the Path to the Goal Correct?

While Goal metrics tell you if the agent succeeded, Plan and Act metrics tell you how it succeeded or failed. This is where you find the actionable insights needed for engineering improvements.

This diagram shows how a "Metrics Engine" is just one part of an "Evaluation Core." A "Behavioral Analyser" is needed to assess process-level qualities like reasoning and tool selection.

Plan Metrics

These metrics assess the quality of the agent's reasoning before it takes action. For a plan-then-execute agent, this means evaluating the generated plan itself.

  • Plan Quality: Is the plan logical? Is it efficient? Does it use the correct tools? This is inherently subjective and a perfect candidate for the LLM-as-a-judge pattern. We create a rubric and use a powerful LLM to score the agent's plan against it.

  • Tool Selection (in planning): Did the plan include the correct set of tools for the job? This can be evaluated as a precision/recall problem on the set of chosen tools versus the "golden" set of tools required for the task.

Act Metrics

These metrics evaluate the agent's execution of its plan.

  • Plan Adherence: Did the agent actually follow the steps in its plan?
  • Tool Calling: This is a critical one for the service-fulfillment agents you aim to build. We can break this down further:
    • Tool Selection Accuracy: Did the agent pick the right tool at the right time?
    • Parameter Correctness: Did the agent call the tool with the correct, well-formed arguments? A common failure mode is hallucinating parameter values or formatting them incorrectly.
    • Execution Efficiency: How many steps/turns did it take? What was the token cost? What was the end-to-end latency? These are crucial operational metrics for production systems.

Automating Subjective Metrics: The LLM-as-a-Judge Pattern

Many of the most important metrics, especially for the "Plan" phase, are not easily calculated with simple code. Assessing "Plan Quality" or "Answer Relevance" requires a nuanced understanding of language and intent. The LLM-as-a-judge pattern automates this by leveraging a powerful model (like GPT-4 or Claude 3.5 Sonnet) as the evaluator.

The core idea is to create a detailed prompt that includes:

  1. Role and Context: "You are an expert evaluator..."
  2. Evaluation Criteria: A precise rubric defining what constitutes good vs. poor performance.
  3. The Artifact to be Judged: The agent's plan, response, or full trace.
  4. Instructions: A request for a structured output (e.g., a JSON object with a score and a rationale).

Using LLM-as-a-Judge to Evaluate Agent Outputs

This tutorial provides an excellent, practical guide to implementing the LLM-as-a-judge pattern, with a focus on designing the criteria and prompts that make it work reliably.

First, read the section "Designing Effective Evaluation Criteria." This explains how to define task-specific criteria and structure scoring systems. Then, read the section "Prompt Engineering for LLM Judges" to understand the key components of a good judge prompt.

The article also provides Python code examples for creating judges for specific metrics like tool selection and planning quality, which serve as excellent starting points for your own evaluation harness.

A Word of Caution: Biases in LLM Judges

While powerful, the LLM-as-a-judge pattern is not a silver bullet. The judge model itself is an LLM and is subject to the same types of biases and failure modes. As a systems architect, you must be aware of these to build a reliable evaluation pipeline.

Stanford CME295 Transformers & LLMs | Autumn 2025 | Lecture 8 - LLM Evaluation

This part of the Stanford lecture lucidly explains the common biases that affect LLM judges and suggests practical mitigation strategies.

Watch the segment covering the biases of LLM-as-a-judge. Focus on understanding the following three major biases: Position Bias: The model may prefer the first answer it sees. Verbosity Bias: The model may prefer longer, more detailed answers, even if they are less correct. Self-Enhancement Bias: The model tends to prefer answers generated by itself or a model from the same family. The lecturer also provides remedies, such as swapping the order of responses to check for position bias and using a different, often more powerful, model for the judge role.


From Metrics to Diagnosis: A Hierarchy of Failure Modes

The true power of this granular metric framework is its diagnostic capability. When the top-level Task Completion Rate drops, you can drill down into the process metrics to pinpoint the root cause. It's helpful to think of a hierarchy of potential failures, starting from the tool interaction and moving to the final synthesis.

This corresponds directly to a debugging workflow an engineer would follow:

  1. Tool Prediction Errors: Did the agent choose the right tool?
    • Metric: Tool Selection Accuracy.
    • Failure Modes: Chose the wrong tool, hallucinated a non-existent tool, failed to use a tool when one was needed.
  2. Tool Call Errors: Did the agent use the chosen tool correctly?
    • Metric: Parameter Correctness, Tool Execution Success Rate.
    • Failure Modes: Extracted incorrect arguments, tool itself failed with an error (a bug in the tool code), tool returned an empty or unhelpful response.
  3. Synthesis Errors: Did the agent correctly interpret the tool's output?
    • Metric: Groundedness, Factuality.
    • Failure Modes: The tool returned the correct data, but the agent ignored it, misinterpreted it, or hallucinated information when generating the final response.

By instrumenting your agent to log the necessary data at each of these stages, you can calculate metrics that map directly to these failure modes, turning a vague "the agent is failing" problem into a precise "the agent's parameter extraction accuracy for the search_database tool dropped by 15%" diagnosis.


Conclusion

In this lesson, we've established a robust framework for measuring agent quality that goes far beyond simple pass/fail scores. By defining and calculating metrics across the Goal, Plan, and Act phases, we can build a rich, multi-dimensional picture of our agent's performance.

Key Takeaways:

  • Agent reliability follows the math of compound probability: Small, per-step errors multiply to cause large-scale task failures. This necessitates measuring process quality, not just final outcomes.
  • A structured metric framework (like Goal, Plan, Act) is essential for diagnosis: It helps you pinpoint why an agent is failing, not just that it is failing.
  • Key metrics include:
    • Goal: Task Completion Rate, Accuracy, Factuality, Relevance.
    • Plan: Plan Quality, Logical Consistency.
    • Act: Tool Selection Accuracy, Parameter Correctness, Plan Adherence, Execution Efficiency (cost, latency).
  • The LLM-as-a-judge pattern is a powerful tool for automating subjective evaluations, but it must be used with an awareness of its inherent biases (position, verbosity, self-enhancement).

Preview of the Next Lesson:

To calculate all these detailed metrics, we need data. Lots of it. Our entire evaluation framework rests on our ability to capture a complete, structured, and replayable record of everything the agent does. In the next lesson, we will focus on how to implement structured logging that captures a full, replayable trace of an agent's execution. This is the foundational data layer upon which our metrics, dashboards, and debugging tools will be built.