Agent Evaluation in Practice: Building a Three-Layer Quality Verification System

    Evaluating AI agents with simple keyword checks often misses real task failures. This article explains how to build a three-layer quality verification system for AI agents: live-run evaluation of actual execution behavior, trace-based regression on recorded runs, and model-assisted judgment for semantic quality. It covers defining a versioned quality contract, designing test cases for edge conditions, separating behavior checks from result checks, calibrating model-based scoring with human-labeled samples, building reusable evaluation infrastructure, and integrating quality gates into a continuous delivery pipeline with proper data governance. Readers will learn how to turn subjective quality impressions into a repeatable, evidence-backed engineering practice.

    1. Why Agents Need Evaluation Beyond Keyword Checks

    Suppose a user asks: “What are today’s top financial market headlines? Give me five items with links to the original reports.”

    The agent calls a search tool and returns five results containing words like “financial,” “market,” and “news.” On the surface, the answer has the right count, the right keywords, and links included. On closer inspection, however, two of the items are just news-section descriptions, and all the links point to homepages or aggregation pages rather than specific reports.

    An answer like this can pass simple string checks while failing the actual task: finding today’s important events, distilling the facts, and providing verifiable evidence.

    The problem is not that keyword checks are useless — it is that they can only prove certain formal conditions hold. They cannot prove timeliness, relevance, or credibility. On the other hand, relying entirely on model-based judgment carries its own risks: scores can be swayed by writing style, context length, and the judge’s prompt, and they add cost and uncertainty.

    Agent evaluation should therefore split responsibilities:

    • Use deterministic rules to check structure, counts, tool calls, and explicit constraints.
    • Use execution traces to check behavioral paths and evidence relationships.
    • Use model-assisted judgment for relevance, completeness, and informational value.

    These three types of checks complement each other, turning “looks correct” into “verifiably meets the task requirements.”

    2. Define the Quality Contract Before the Implementation

    2.1 A contract is more than a prompt

    A quality contract is a centralized description of the task goal, inputs and outputs, behavioral boundaries, and acceptance rules. It should be version-controlled so that every evaluation run can be tied to an explicit configuration instead of a developer’s memory.

    For a news-retrieval task, the contract should include at minimum:

    • Task identifier and contract version.
    • Prompt template and its version.
    • Model configuration reference.
    • Allowed tool types.
    • Output fields and data types.
    • Time range, count requirements, and source requirements.
    • Hard-failure conditions.
    • Semantic scoring dimensions.
    • Evaluation samples and expected behavior.

    Here is an illustrative custom configuration structure, not tied to any specific product interface:

    1. Contract version: 3
    2. Task type: financial news retrieval
    3. Input:
    4. User question
    5. Reference time
    6. Business timezone
    7. Output:
    8. News list
    9. Title
    10. Publication time
    11. Event summary
    12. Original report URL
    13. Source notes
    14. Retrieval-insufficiency statement
    15. Hard rules:
    16. Must perform external retrieval
    17. Must not count section pages as news events
    18. Every news item must be linked to evidence
    19. Must explicitly state when verifiable results are insufficient
    20. Semantic dimensions:
    21. Topic relevance
    22. Event importance
    23. Summary faithfulness
    24. Information coverage

    Note that “today” must be converted into an explicit time window. Otherwise, the machine’s timezone, the user’s timezone, and report publication times may disagree, causing the same news item to be judged differently across runs.

    2.2 Decide which rules can be relaxed

    Count requirements and evidence requirements can conflict. For example, the user asks for five news items, but retrieval can only find three reports that meet the conditions.

    In that case, truthfulness should take priority — the agent should not pad the count with section pages, stale news, or duplicate events. The contract should make this explicit: returning fewer results with an explanation of the shortfall is allowed; fabricating facts, times, or sources is not.

    This priority design matters. A rule set without priorities may push the agent to sacrifice substantive quality in order to satisfy surface-level formatting.

    3. Layer One: Live-Run Evaluation to Verify Actual Execution

    Live-run evaluation actually invokes the agent and its dependencies, observing how it behaves in the current environment. This layer covers the interactions between model output, tool calls, external data, and exception handling.

    3.1 Test cases should cover both normal paths and edge conditions

    Don’t prepare only one “normal question” sample. At minimum, consider:

    • Normal scenario: enough same-day reports exist.
    • Insufficient results: few reports fall within the time window.
    • Duplicates: multiple pages describe the same event.
    • Time boundaries: a report sits right at the edge of the window.
    • Missing source data: a page has no reliable publication time.
    • Tool failures: search times out or returns incomplete data.
    • Conflicting information: sources describe the same event inconsistently.
    • Malicious content: page text contains instructions trying to redirect the agent’s task.

    For open-ended tasks, the expected result should not be a fixed answer but a set of invariants — for example, “the same event must not be counted twice” or “if publication time cannot be confirmed, the agent must not claim the item belongs to today.”

    3.2 Separate behavior checks from result checks

    Behavior checks focus on the execution process:

    • Whether the search tool was actually called.
    • Whether report content was fetched when needed.
    • Whether the tool-call budget was exceeded.
    • Whether allowed recovery strategies were used after tool failures.
    • Whether external content was mistakenly treated as system instructions.

    Result checks focus on the final output:

    • Whether all fields are complete.
    • Whether the news items fall within the target time window.
    • Whether each summary has corresponding evidence.
    • Whether the links point to specific reports.
    • Whether there are duplicate events or unsupported conclusions.

    One caveat: calling tools correctly does not mean the answer is correct, and a plausible answer does not prove compliant tool usage. Both must be recorded independently.

    3.3 Run multiple times to observe stability

    Agents are typically non-deterministic. A single run cannot distinguish stable capability from accidental success.

    You can run the same case repeatedly and track the pass rate, failure types, and resource consumption. The basic pass-rate calculation is:

    1. Pass rate = runs meeting all hard acceptance conditions / total runs

    With a small sample, this ratio should not be treated as a precise long-term reliability estimate. Report the sample size alongside the rate, add confidence intervals when needed, and break results down by scenario so that overall averages don’t mask persistent failures in a specific task type.

    Under cost constraints, use stratified sampling: keep baseline coverage for ordinary cases and increase repetitions for high-risk cases and historically failing cases.

    4. Layer Two: Trace-Based Regression to Re-Examine Past Executions

    4.1 Why you need to keep trace records

    Live-run evaluation depends on external tools and models, which is costly, and the underlying data changes over time. From the final answer alone, it is often hard to tell whether a failure occurred during retrieval, filtering, summarization, or output formatting.

    You therefore need to record key execution nodes:

    • User input and the task time window.
    • Contract version, prompt version, and model configuration.
    • Tool names and categories, call parameters, and status.
    • Return-result summaries or controlled snapshots of raw content.
    • The final answer and structured fields.
    • Latency, retry counts, and token usage.
    • Rule-check results and failure reasons.

    Records should let you link “news item — evidence snippet — tool return result,” not just store a stream of disconnected log lines.

    4.2 You can find rule defects without invoking models

    The core idea of trace regression is: re-run deterministic checks against saved execution data, without regenerating answers.

    For example, after a team adds the rule “section pages must not be counted as news items,” they can scan historical records to see how many past answers violated this requirement — no need to re-access the web.

    The indicative logic is:

    1. For each historical run record:
    2. Read the task time window for that run
    3. Check the output structure
    4. Check news publication times
    5. Check for duplicate events
    6. Check whether evidence links are complete
    7. Check saved page-type information
    8. Output failed rules and associated evidence

    This method is well suited to evaluating rule changes, counting historical defects, and validating fix directions.

    But it has clear boundaries: it can only check what was recorded. If page content or page type was not saved, you cannot reliably determine from the URL alone whether a page is a specific report. Trace regression also cannot predict what a new model or new prompt would produce, because it does not re-run the agent.

    4.3 Distinguish historical standards from current standards

    Historical records should store the contract version in effect at the time. Regression reports should state which rule set is used:

    • Re-check under the original contract: did the run meet the requirements at the time?
    • Re-evaluate under the new contract: what is the gap between historical answers and the new standard?

    The two results must not be conflated. Otherwise, tightened rules may be misread as sudden system degradation.

    5. Layer Three: Model-Assisted Judgment for Semantic Quality

    Some quality issues are hard to encode fully as deterministic rules. A report may satisfy the time requirement without being an important news event; a summary may read fluently while overstating the source’s conclusions.

    Model-assisted judging is well suited to checking:

    • Whether news items are relevant to financial market topics.
    • Whether events carry enough informational value.
    • Whether summaries are faithful to the evidence.
    • Whether multiple results cover distinct important events.
    • Whether the answer clearly separates facts from uncertain information.

    5.1 Give the judge evidence, not just the answer

    If the judge sees only the final answer, it may mistake fluent phrasing for high quality. A more reliable input includes the user question, the time window, the candidate answer, evidence snippets, and explicit scoring criteria.

    Scoring results should include:

    • Per-dimension scores.
    • A verdict of pass, fail, or insufficient evidence.
    • The flagged items.
    • Evidence citations supporting the judgment.
    • A short rationale for human review.

    “Insufficient evidence” must not be collapsed into either “correct” or “incorrect.” Keeping it as a separate state helps distinguish generation problems from evaluation-data gaps.

    5.2 Calibrate scores with human-labeled samples

    The judge itself needs evaluation. Select representative answers, have humans label them against a unified standard, and compare the model’s verdicts with the human results.

    Focus on two error types: low-quality answers being passed, and qualified answers being rejected. Thresholds should be set based on business risk, not on an uncalibrated fixed score.

    Model-assisted scoring is a supplementary signal and should never override hard rules. For example, if the answer contains an unsupported factual claim about a news event, it should fail acceptance even if the overall expression scores high.

    6. Build General Evaluation Infrastructure

    A local development environment can consist of:

    • Agent runtime service: executes tasks and produces structured results.
    • Evaluation executor: loads contracts, runs tests, and aggregates reports.
    • Trace collection service: gathers call chains and execution events.
    • Object storage: holds large evidence snapshots and evaluation artifacts.
    • Metrics store: records pass rates, failure distributions, latency, and cost.
    • Logging service: retains runtime errors and diagnostics.
    • Visualization interface: shows trends and supports drilling into failure samples.

    These components can be started through container orchestration. Development and production environments should be configured separately; default accounts, test keys, or public access settings must never be promoted directly into production.

    Model and search capabilities may depend on external services, so “the infrastructure runs locally” does not mean “the entire evaluation is offline.” For offline regression, save the necessary data in advance after permission and compliance checks.

    7. Bring Evaluation into the CI/CD Pipeline

    Different checks should run at different stages, so that every change doesn’t trigger an expensive full test suite.

    At code-commit time, prioritize contract validation, deterministic checks, and historical trace regression. At release-candidate time, run repeated live evaluations on representative cases. After release, apply controlled sampling to real traffic for semantic scoring and human review.

    Release gates should distinguish three signal types:

    • Hard failures: fabricated facts, violated constraints, missing evidence.
    • Quality regressions: drops in relevance, coverage, or stability.
    • Resource anomalies: notable increases in latency, retries, or usage.

    Quality and cost should be tracked separately. Don’t reduce necessary retrieval to cut costs, and don’t use unlimited retries to mask unstable task performance.

    Beyond a fixed benchmark set, maintain a rolling sample set that converts production failures into new test cases — while preventing the team from over-optimizing for known questions only.

    8. Security and Data Governance Cannot Be Skipped

    Trace data may contain user inputs, business information, web content, and credential clues. Before recording, apply field-level masking and never store authentication tokens.

    Also clarify:

    • Data retention periods and deletion policies.
    • Access permissions for evaluation staff.
    • The retention scope of evidence snapshots.
    • Restrictions on sending sensitive content to judge models.
    • Audit requirements for the judging process itself.

    External web pages are untrusted input. Whether used for answer generation or model scoring, page text must be treated as isolated evidence material. Its embedded instructions must never change task rules, leak data, or control tool calls.

    9. Conclusion: Turn Quality Judgment into an Engineering Loop

    The three layers each solve different problems: live-run evaluation verifies how the system currently executes tasks; trace regression explains historical behavior and re-checks rules; model-assisted judgment supplements assessments of relevance, faithfulness, and informational value.

    An effective system is not a pile of more scoring tools but a clear loop: define the quality contract, collect execution evidence, combine rule-based and semantic judgments, locate root causes, and convert fixes into regression tests.

    Starting from a single news-retrieval task, as long as you can explain “why it passed, why it failed, and on what evidence,” agent quality control has moved from subjective impressions toward a repeatable, traceable engineering practice.