Eval-Driven Development for AI Agents: Contracts, Traces and Judges
Treat evals as CI/CD for agents: version prompts as contracts, trace runs with OpenTelemetry and Tempo, then test with deterministic checks and an LLM judge.
This article is published in English.
Sources: **Eval-Driven Development: A Software Engineering Approach to Production-Grade AI Agents**
Most teams building agentic AI fall into the framework trap early. The search for the perfect orchestrator seems like the obvious first step, but heavy, abstract frameworks turn out not to be the answer, and some of them degrade quickly between releases. A code-review automation built with no framework at all showed how little is needed. What was missing was something borrowed from ordinary software engineering: evals, which work like CI/CD for agents.
Evals aren't one-size-fits-all, and they aren't only LLM-as-a-judge. Getting them right is the difference between a brittle toy and a production-grade system.
The stack here is deliberately open source and not tied to any one vendor's managed services. Pydantic AI is the agent framework, a lightweight, schema-first library that stays out of the way and treats evals as a first-class feature. Grafana Tempo with S3 storage holds the traces, in place of a managed observability platform, and AI-generated code queries and filters those traces for each kind of eval.
Why most agents don't survive production
The clearest sign of an agentic system that won't last isn't the model, the framework or the cleverness of its prompts. It's the absence of foundational engineering practice. If an agent has no structured tracing, no evals, no prompt versioning and no guardrails, it's a vibe-coded proof of concept with a high chance of failing.
Traditional software gets continuous quality from CI/CD pipelines, unit tests, integration tests and regression tests. In the non-deterministic world of agents, the usual fatal gap is a missing automated evaluation framework plus missing operational guardrails. Building mature agents means going back to first principles: open infrastructure and an Eval-Driven Development (EDD) workflow that can scale.
The production pipeline
1. The contract: version the prompt separately
Prompts and their related artifacts are the most important part of an agentic system, so they shouldn't be buried inside agent code. Code is just the body, which is fairly easy to stabilize and version, while prompts keep evolving as models improve.
The pipeline starts from a versioned contract that spells out what should run: the agent, the prompt, the model and the evaluation policy.
[
{
"agent_id": "financial_market_headlines",
"version": 1,
"agent_model": "openai:gpt-4",
"prompt": "What are today's major financial market headlines?",
"eval": {
"contains": ["market"],
"max_model_requests": 3,
"min_tool_calls": 1,
"max_tool_calls": 5,
"judge_rubric": "The answer should be a useful response to the user's financial markets question. It should summarize market-relevant information, avoid obviously unrelated content, avoid investment advice, and avoid claiming certainty beyond what the retrieved information supports."
}
}
]
The prompt and rubric are deliberately short here for demonstration purposes, since production prompts are normally long and detailed. The contract ties the prompt to an LLM-as-judge evaluation prompt, and also to non-LLM checks such as keyword matching with "contains" and minimum or maximum tool call counts.
2. The runtime: the execution engine
The agent runtime executes the contract. It calls the model, invokes external tools through MCP where needed and does the actual work.
The choice came down mostly to LangGraph versus Pydantic AI. Python isn't the only option, and even Rust has a library in Rig. But raw language speed barely matters next to the waiting time of LLM inference and network calls to MCP tools, so Python's large, mature AI ecosystem wins. Pydantic AI got the nod because of its first-class support for evals.
In production the runtime usually lands on Kubernetes. It's tempting to over-engineer by modeling every agent as a custom resource, but reconciliation loops for rapidly changing prompts will drain your velocity. Keep the runtime lean.
3. The observability layer: no blind spots
The runtime emits traces, logs, usage counters, model and tool calls, latency figures and errors, all captured with OpenTelemetry and kept in systems like Tempo, Loki and Prometheus. Grafana then shows what the system is doing in production.
4. The evaluation layer: CI/CD for AI
This is where it comes together. Execution traces from the observability layer flow straight into evaluation, where two kinds of tests run against real traces: deterministic rules and non-deterministic judgments.
The loop never stops: define, execute, observe, evaluate, improve, repeat.
Forcing determinism onto a non-deterministic system
Evaluations fall into two groups. Deterministic ones can be tested accurately with plain code. A deliberately simplistic example would be asking an LLM to add two numbers and checking the answer with a unit test.
For this use case the prompt asks for today's financial market news, which means the model should call the provided web search tool at least once. That part is deterministic and makes a useful test. And if the output has to contain certain strings, a "Contains" check can verify it.
Layer 1: live deterministic tests
The live suite executes today's agent against the versioned contract. Pydantic Evals ships with MaxToolCalls and a text Contains checker. Missing pieces like MinToolCalls are added as thin wrappers.
uv run python tests/unittest_eval_agent.py
The evaluators are assembled per case:
evaluators=[
*[Contains(value, case_sensitive=False) for value in case.eval.contains],
MaxModelRequests(case.eval.max_model_requests),
MinToolCalls(case.eval.min_tool_calls),
MaxToolCalls(case.eval.max_tool_calls),
]
Each case runs several times, because models are non-deterministic. The same model with identical prompt and settings may call the tool in one run and skip it in another. That's especially visible with cheaper, less capable models, and if any of, say, ten runs fail, it's a hint that the prompt needs more detail. A run with three repetitions looks like this:
(financial-agent2) alex@pop-os:/ssd/ai_works/financial_agent2$ uv run python tests/unittest_eval_agent.py
Running each eval case 3 time(s)
Evaluating task ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
Evaluation Summary: task
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Case ID ┃ Metrics ┃ Assertions ┃ Duration ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ financial_market_headlines_v1 [1/3] │ tool_calls: 1 │ ✔✔✔✔ │ 18.8s │
│ │ requests: 2 │ │ │
│ │ input_tokens: 1,325 │ │ │
│ │ output_tokens: 278 │ │ │
│ │ cost: 0.0564 │ │ │
├─────────────────────────────────────┼───────────────────────┼────────────┼──────────┤
│ financial_market_headlines_v1 [2/3] │ tool_calls: 1 │ ✔✔✔✔ │ 8.8s │
│ │ requests: 2 │ │ │
│ │ input_tokens: 1,195 │ │ │
│ │ output_tokens: 82 │ │ │
│ │ cost: 0.0408 │ │ │
├─────────────────────────────────────┼───────────────────────┼────────────┼──────────┤
│ financial_market_headlines_v1 [3/3] │ tool_calls: 1 │ ✔✔✔✔ │ 13.5s │
│ │ requests: 2 │ │ │
│ │ input_tokens: 1,292 │ │ │
│ │ output_tokens: 388 │ │ │
│ │ cost: 0.0620 │ │ │
├─────────────────────────────────────┼───────────────────────┼────────────┼──────────┤
│ Averages │ requests: 2.00 │ 100.0% ✔ │ 13.7s │
│ │ output_tokens: 249.3 │ │ │
│ │ tool_calls: 1.00 │ │ │
│ │ cost: 0.0531 │ │ │
│ │ input_tokens: 1,270.7 │ │ │
└─────────────────────────────────────┴───────────────────────┴────────────┴──────────┘
Layer 2: deterministic regression from traces
The second suite doesn't execute the agent again. It reads finished traces from Tempo:
uv run python tests/regression_eval_traces.py
It pulls out the final result, counts model and tool spans, finds the recorded contract and applies the same deterministic rules as before: contains, and tool called at least once. A recorded run might report:
Trace: ff5a53e3392dc26cd0a2890782be70ec
Eval case: financial_market_headlines v1
Status: PASS
Model requests: 2
Tool calls: 1
contains('market'): PASS
MaxModelRequests: PASS
MaxToolCalls: PASS
That's cheap and repeatable, since it re-evaluates evidence that's already been captured.
Layer 3: non-deterministic tests with an LLM judge
The contract also carries a rubric for testing the prompt. It's the same short contract again:
[
{
"agent_id": "financial_market_headlines",
"version": 1,
"agent_model": "openai:gpt-4",
"prompt": "What are today's major financial market headlines?",
"eval": {
"contains": ["market"],
"max_model_requests": 3,
"min_tool_calls": 1,
"max_tool_calls": 5,
"judge_rubric": "The answer should be a useful response to the user's financial markets question. It should summarize market-relevant information, avoid obviously unrelated content, avoid investment advice, and avoid claiming certainty beyond what the retrieved information supports."
}
}
]
Because the agent itself runs on GPT-4, the judge needs a stronger model, and GPT-5 fills that role here. It decides whether the response was useful and relevant, whether it overstated what the retrieved material supports and whether it slipped into investment advice.
Breaking the rubric into several levels offers another route. Simple checks of the NLP sort can go to weaker models or even small self-hosted ones, and a set of such weak tests can add up to something close to the higher-level judgment above. Which is better depends on the use case and how the tests are designed.
For more depth, the survey paper "A Survey on LLM-as-a-Judge" (arXiv 2411.15594) is a good read. Depending on the use case, you'll eventually need systems that judge the judge, using human feedback or other means.
The suite loads the same stored final result and runs Pydantic Evals LLMJudge with the contract's rubric:
LLMJudge(
rubric=case.eval_case.eval.judge_rubric,
model=args.judge_model,
include_input=True,
score={"evaluation_name": "judge_score", "include_reason": True},
assertion={"evaluation_name": "judge_pass", "include_reason": True},
)
Here's a classic failure caught by the judge, caused by a short and vague prompt. Instead of calling the tool and summarizing results, the model replied with a message telling the user to check financial news outlets.
uv run python tests/regression_llm_judge_traces.py --sample-percent 50
Trace selection: fetched=1 sampled=1 judging=1 lookback_minutes=1440 sample_percent=50 max_traces=5
Trace case: trace_id=3891f0b8432c9bbcb00e5e8adce1600b agent_id=financial_market_headlines prompt_version=1 answer_chars=207
Judging 1 trace(s) with openai:gpt-5.4
Evaluating task ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
Evaluation Summary: task
┏━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Case ID ┃ Inputs ┃ Outputs ┃ Scores ┃ Assertions ┃ Duration ┃
┡━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩
│ financial_market_he… │ {'trace_id': │ Today's major │ judge_score: 0.000 │ judge_pass: ✗ │ 469µs │
│ │ '3891f0b8432c9bbcb00 │ financial market │ Reason: The │ Reason: The │ │
│ │ e5e8adce1600b', │ headlines can be │ response does not │ response does not │ │
│ │ 'agent_id': │ found on major │ summarize any actual │ summarize any │ │
│ │ 'financial_market_he │ business and finance │ market headlines or │ actual market │ │
│ │ adlines', │ news outlets │ provide │ headlines or │ │
│ │ 'prompt_version': 1, │ including CNBC, │ market-relevant │ provide │ │
│ │ 'agent_model': │ Yahoo Finance, │ information; it only │ market-relevant │ │
│ │ 'openai:gpt-4', │ Reuters, and │ redirects the user │ information; it │ │
│ │ 'judge_model': │ Bloomberg. For more │ to news websites. It │ only redirects the │ │
│ │ 'openai:gpt-5.4', │ specific stories, │ avoids investment │ user to news │ │
│ │ 'prompt': "What are │ please visit their │ advice, but it is │ websites. It avoids │ │
│ │ today's major │ websites. │ not a useful answer │ investment advice, │ │
│ │ financial market │ │ to the user's │ but it is not a │ │
│ │ headlines?"} │ │ question. │ useful answer to │ │
│ │ │ │ │ the user's │ │
│ │ │ │ │ question. │ │
│ │ │ │ │ │ │
│ │ │ │ │ │ │
├──────────────────────┼──────────────────────┼──────────────────────┼──────────────────────┼─────────────────────┼──────────┤
│ Averages │ │ │ judge_score: 0.000 │ 0.0% ✔ │ 469µs │
└──────────────────────┴──────────────────────┴──────────────────────┴──────────────────────┴─────────────────────┴──────────┘
A second failure case appears below. In this one the judge may have misjudged, or the rubric may be too vague, because the model did use the search MCP and got decent results.
uv run python tests/regression_llm_judge_traces.py --sample-percent 10 --lookback-minutes 30
Trace selection: fetched=1 sampled=1 judging=1 lookback_minutes=30 sample_percent=10 max_traces=5
Trace case: trace_id=38fa3a54134d8818c7d7a5afbf50967e agent_id=financial_market_headlines prompt_version=1 answer_chars=654
Judging 1 trace(s) with openai:gpt-5.4
Evaluating task ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
Evaluation Summary: task
┏━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Case ID ┃ Inputs ┃ Outputs ┃ Scores ┃ Assertions ┃ Duration ┃
┡━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩
│ financial_market_… │ {'trace_id': │ Here are today's │ judge_score: 0.450 │ judge_pass: ✗ │ 441µs │
│ │ '38fa3a54134d8818c │ major financial │ Reason: The │ Reason: The │ │
│ │ 7d7a5afbf50967e', │ market headlines: │ response is │ response is │ │
│ │ 'agent_id': │ │ market-related and │ market-related │ │
│ │ 'financial_market_ │ 1. Wall Street's │ avoids investment │ and avoids │ │
│ │ headlines', │ riskiest trades │ advice, but it │ investment │ │
│ │ 'prompt_version': │ are suddenly back │ mostly lists │ advice, but it │ │
│ │ 1, 'agent_model': │ on top: Chart of │ article headlines │ mostly lists │ │
│ │ 'openai:gpt-4', │ the Day - Yahoo │ and links rather │ article headlines │ │
│ │ 'judge_model': │ Finance │ than providing a │ and links rather │ │
│ │ 'openai:gpt-5.4', │ [Link](https://fi │ useful summary of │ than providing a │ │
│ │ 'prompt': "What │ nance.yahoo.com/) │ the key financial │ useful summary of │ │
│ │ are today's major │ 2. S&P 500 │ market │ the key financial │ │
│ │ financial market │ notches │ developments. │ market │ │
│ │ headlines?"} │ record-high close │ │ developments. │ │
│ │ │ as rate-hike │ │ │ │
│ │ │ worries ease - │ │ │ │
│ │ │ Reuters │ │ │ │
│ │ │ [Link](https://ww │ │ │ │
│ │ │ w.reuters.com/mar │ │ │ │
│ │ │ kets/us/) │ │ │ │
│ │ │ 3. Treasury │ │ │ │
│ │ │ yields rise as │ │ │ │
│ │ │ U.S. threatens │ │ │ │
│ │ │ Iran with more │ │ │ │
│ │ │ economic │ │ │ │
│ │ │ sanctions - CNBC │ │ │ │
│ │ │ [Link](https://ww │ │ │ │
│ │ │ w.cnbc.com/) │ │ │ │
│ │ │ 4. Latest stock │ │ │ │
│ │ │ market, financial │ │ │ │
│ │ │ and business news │ │ │ │
│ │ │ - MarketWatch │ │ │ │
│ │ │ [Link](https://ww │ │ │ │
│ │ │ w.marketwatch.com │ │ │ │
│ │ │ /) │ │ │ │
│ │ │ 5. Latest finance │ │ │ │
│ │ │ and stock market │ │ │ │
│ │ │ news covering the │ │ │ │
│ │ │ Dow, S&P 500, │ │ │ │
│ │ │ banking, │ │ │ │
│ │ │ investing and │ │ │ │
│ │ │ regulation - WSJ │ │ │ │
│ │ │ [Link](https://ww │ │ │ │
│ │ │ w.wsj.com/finance │ │ │ │
│ │ │ ) │ │ │ │
├────────────────────┼────────────────────┼───────────────────┼────────────────────┼───────────────────┼──────────┤
│ Averages │ │ │ judge_score: 0.450 │ 0.0% ✔ │ 441µs │
└────────────────────┴────────────────────┴───────────────────┴────────────────────┴───────────────────┴──────────┘mar
Running this kind of test on every trace can get too expensive and slow. Random sampling is a better option. Where the product offers a way to collect user feedback, the trace ID can lead straight to the components in the flow that went wrong, and only those get tested. Commercial products like LangSmith and Arize Phoenix cover this, but an S3 backend plus this stack gives the same capability, and a docker compose setup for it exists.
After the initial unit tests, it's clear that the prompt and rubric both need an update, and the contract moves to version 2:
{
"id": "financial_market_headlines",
"version": 2,
"agent": "websearch",
"prompt": "Use the web-search tool to find and verify today's major financial-market headlines. Report the 3 to 5 most consequential developments across equities, rates, currencies, commodities, or macroeconomic policy. For each item, state what happened, identify the affected market or region, explain briefly why it matters, and name the source with a link when available. Include the relevant date and units for numerical claims. Cross-check any surprising index level, percentage move, policy decision, or economic release against a second reliable source; if it cannot be verified, omit it or clearly label it as unconfirmed. State when the information was current, distinguish facts from developing reports or interpretation, and say when reliable current information is insufficient. Do not invent facts, present stale information as today's news, or give personalized investment advice.",
"contains": ["market"],
"max_model_requests": 4,
"min_tool_calls": 1,
"max_tool_calls": 7,
"judge_rubric": "The response should provide 3 to 5 current, consequential financial-market developments based on web research. Each item should identify what happened, the affected market or region, why it matters, and its source, preferably with a link. Numerical claims should include meaningful dates and units; surprising figures should be corroborated by a second reliable source or explicitly marked unconfirmed. The answer should state when the information was current, distinguish verified facts from developing reports or interpretation, and acknowledge insufficient evidence rather than inventing details. It must stay relevant, avoid stale news presented as current, avoid unsupported certainty, and avoid personalized investment advice. A polished but uncited answer containing an implausible or unverifiable market figure should fail."
},
From pattern to release pipeline
When every trace points back to its contract, a release pipeline can pick different kinds of evidence at each stage, which says more than a lone pass rate. A release should be scored on several dimensions:
- whether the task succeeded
- how good the output is semantically
- whether tools were used correctly
- safety and policy compliance
- cost in requests and tokens
- latency and reliability
Further reading
Anthropic's engineering blog has a post on how evals for AI agents work, at https://www.anthropic.com/engineering/demystifying-evals-for-ai-agents, which covers the broader thinking.