AI Agent Evaluation: A Three-Layer Framework from Contracts to Regression Testing

    Learn how to structure AI agent evaluation around version-controlled contracts, live execution tests, and trace-based regression checks. This guide covers the architecture, infrastructure choices, local setup, and a sample JSON contract, with an LLM judge for quality criteria that deterministic rules cannot easily assess.

    Evaluating AI agent behavior is a challenging part of AI engineering. Traditional software testing relies heavily on unit tests, often expecting identical outputs when the same inputs and conditions are repeated. Agents powered by large language models are nondeterministic: their responses can vary across runs.

    Agent evaluation must therefore go beyond checking whether the final answer is useful. It also needs to verify that the agent calls the right tools and follows its predefined constraints.

    No single evaluation method covers all of these requirements. A three-layer framework—built on open-source infrastructure and agent development frameworks—provides a structured way to evaluate behavior and support ongoing iteration.

    1. Designing the Three-Layer Evaluation Framework

    An effective evaluation system must balance control, realism, and cost. The following three layers create a repeatable feedback loop.

    Layer 1: Version-Controlled Contracts

    The first step is to establish a shared evaluation contract. Changes to prompts, model configuration, available tools, or evaluation rules can all cause agent behavior to drift.

    Representing these elements in a JSON contract and storing it in version control makes each evaluation run traceable to a specific configuration. It also gives teams a consistent basis for reviewing changes and comparing results across versions.

    The contract defines the intended operating conditions and assessment criteria. It does not make the model deterministic, but it makes the configuration under evaluation explicit.

    Layer 2: Live Execution Tests

    Live tests simulate real user interactions and run the agent multiple times to observe its behavior. These tests make actual calls to the language model and external tool APIs, such as a web search service.

    Using the rules defined in the contract, the evaluation system checks whether:

    • The agent invokes the required tools.
    • Tool arguments comply with the specified requirements.
    • The final response respects the constraints established by the context.

    Live testing exposes robustness issues under real network and model inference conditions. Repeated execution also helps reveal behavioral variation that a single run might miss.

    Layer 3: Trace-Based Regression Evaluation and an LLM Judge

    Live testing provides realistic results, but frequent calls to paid model APIs increase cost and execution time. The third layer uses stored traces and an LLM judge to make evaluation more efficient.

    Trace-based regression evaluation: Distributed tracing standards support recording model calls, tool requests, and responses during agent execution. Regression checks then load historical traces from storage and reapply evaluation rules rather than rerunning the agent against the live model.

    This reduces the cost and time required to reassess recorded behavior. It evaluates existing execution records rather than generating new agent behavior.

    LLM judge: Some quality dimensions, such as tone and logical coherence, are difficult to assess with hard-coded rules. A separate LLM judge can evaluate sampled responses from the stored traces, using a predefined prompt to assign scores.

    This adds a review mechanism for subjective criteria alongside deterministic checks. Trace-based rule evaluation avoids new agent inference calls; LLM-based judging still requires its own model calls.

    2. Technology Stack and Architecture

    Implementing this framework requires infrastructure for agent orchestration, evaluation, and the collection and storage of observability data.

    Agent Framework and Evaluation Engine

    Choose an agent development framework with native evaluation support. Frameworks that closely connect agent definitions with evaluation cases are well suited to rapid development and evaluation cycles.

    For long-running workflows with complex state transitions, a graph-based, stateful orchestration framework may be more appropriate—especially when workflows need frequent checkpoint-based pausing, replay, or branching.

    Trace Collection and Storage

    Use a backend compatible with distributed tracing standards to receive and store execution traces.

    Because trace data can be large, an open-source distributed file system or object storage service with S3-compatible access can serve as the persistence layer.

    Observability Stack

    Combine metrics collection, log aggregation, and visualization dashboards into a unified monitoring environment. Container orchestration tools can deploy these components locally for development.

    In this architecture, language model inference and the external web search API are the services that require paid external calls. The remaining infrastructure can be self-hosted locally in containers.

    3. Practical Setup: Infrastructure and Contracts

    Step 1: Start the Local Infrastructure

    Obtain the example project code, then start its monitoring, logging, tracing, and object storage services with Docker Compose. From the project directory, run:

    1. cd eval-driven-development
    2. docker compose -f infra/docker-compose.yml up -d

    Before starting the stack, populate the environment configuration file, .env, with the credentials required by external services. These include the model API key and the search API endpoint and token.

    The Compose configuration described here is intended for local development. Its visualization and storage services use default administrator credentials.

    Step 2: Define the Evaluation Contract

    A structured JSON contract drives the evaluation process. It identifies the agent, specifies its prompt and model configuration, and defines the evaluation rules.

    The following example illustrates the contract structure. The model identifier is illustrative.

    1. {
    2. "agent_id": "financial_market_headlines",
    3. "version": "1.0.0",
    4. "config": {
    5. "model": "gpt-4-turbo-variant",
    6. "prompt_template": "You are a financial news analysis assistant. Generate objective market headlines based on the input...",
    7. "tools": ["web_search_api"]
    8. },
    9. "evaluations": [
    10. {
    11. "type": "tool_call_check",
    12. "expect": "web_search_api",
    13. "criteria": "Must call the web search tool to obtain current information"
    14. },
    15. {
    16. "type": "llm_judge",
    17. "prompt": "Evaluate whether the response is objective and contains no subjective investment advice",
    18. "score_range": [0, 1]
    19. }
    20. ]
    21. }

    The contract has three main parts:

    • agent_id uniquely identifies the agent under evaluation.
    • config specifies the model, prompt template, and available tools, making the configuration explicit and versionable.
    • evaluations defines the assessment logic, combining a mandatory tool-call check with an LLM-based quality score.

    The tool-call rule checks whether the agent uses web search to obtain current information. The judge prompt assesses whether the resulting response remains objective and avoids subjective investment advice.

    Together, these checks evaluate both the agent’s execution behavior and the quality of its final answer.

    4. Conclusion

    A three-layer evaluation framework helps move AI agent development from intuition-driven iteration toward a more systematic engineering process.

    Version-controlled contracts establish a consistent configuration baseline. Live tests capture behavior under actual model and network conditions. Stored traces support faster, lower-cost regression checks, while an LLM judge assesses quality dimensions that deterministic rules cannot easily capture.

    Built around open standards and containerized infrastructure, this approach gives developers a flexible, controllable evaluation loop for maintaining and improving AI agents over time.