AI Agent Evals and Observability: How to Test Non-Deterministic Systems (2026)
BlogAI Agent Evals and Observability: How to Test Non-Deterministic Systems (2026)
Agentic AIAI Engineering

AI Agent Evals and Observability: How to Test Non-Deterministic Systems (2026)

Inventiple TeamNovember 15, 20268 min read

Traditional software tests assume that the same input gives the same output. Language-model systems break that assumption. The same prompt can produce different wording, a changed model version can shift behaviour overnight, and an agent that chooses its own tool calls can take a different path every time.

That does not mean you cannot test them. It means you test distributions and behaviours, not single outputs. And it means you need enough visibility into production to see problems before users report them.

Trend summaries for 2026 point out that observability platforms made debugging agents tractable, and that production reliability, not raw capability, is now the main challenge. This guide shows a practical way to get there: evals first, tracing second, monitoring third.

Why "it looked fine in the demo" is not a test

A demo is a handful of hand-picked successes. Production is thousands of messy inputs. Without evals:

  • You cannot tell whether a prompt tweak helped or hurt.
  • A model upgrade becomes a leap of faith.
  • Regressions are found by customers.
  • Arguments about quality are won by whoever is most confident.

With evals, quality becomes a number you can track and a gate you can enforce.

The eval loop

The eval loop

The loop matters more than any single tool. Every production failure should become a permanent test case.

Step 1: Build your first eval set

Start small and real.

  1. Collect 50 to 100 inputs from real usage, support tickets, or realistic synthetic cases written with domain experts.
  2. Cover the tail: include empty inputs, ambiguous requests, adversarial prompts, long documents and tool failures.
  3. Write expected outcomes. For some tasks this is an exact answer. For others it is a rubric ("cites a source", "refuses to share personal data", "asks a clarifying question").
  4. Label difficulty so you can see whether regressions are in easy or hard cases.
  5. Version the set in your repository like code.

Step 2: Choose the right kind of check

Not every check needs a model to grade it. Use the cheapest reliable method:

  • Deterministic: Output is valid JSON matching a schema; refund amount equals the policy table (Cost / reliability: Cheap, very reliable)
  • Rule-based: Contains required disclaimer; no banned phrases; every claim has a citation id (Cost / reliability: Cheap, reliable)
  • Retrieval metrics: Was the right document in the top-k? (see our RAG failures post) (Cost / reliability: Cheap, reliable)
  • Trajectory: Agent called the expected tools in an acceptable order and stayed under step limits (Cost / reliability: Cheap to moderate)
  • LLM-as-judge: A model grades helpfulness or faithfulness against a rubric (Cost / reliability: Moderate; needs calibration)
  • Human review: Experts grade a sample (Cost / reliability: Expensive, the ground truth)

Calibrate any LLM judge against human labels on a sample before trusting it, and re-check when you change the judge model. Judges can be biased toward longer or more confident-sounding answers.

Step 3: A minimal eval harness

Here is a small, framework-agnostic example in Python. The point is the structure, which you can adapt to pytest, a CI job or an eval library.

import json, statistics
from dataclasses import dataclass

@dataclass
class Case:
id: str
input: str
must_include: list[str]
must_not_include: list[str]
max_tool_calls: int = 5

def run_agent(text: str) -> dict:
"""Call your agent. Return answer, tool_calls, cost, latency."""
...

def grade(case: Case, out: dict) -> dict:
answer = out["answer"].lower()
return {
"has_required": all(s.lower() in answer for s in case.must_include),
"no_forbidden": not any(s.lower() in answer for s in case.must_not_include),
"within_budget": len(out["tool_calls"]) <= case.max_tool_calls,
}

def evaluate(cases: list[Case]) -> dict:
results = []
for c in cases:
out = run_agent(c.input)
checks = grade(c, out)
results.append({"id": c.id, "pass": all(checks.values()), "cost": out["cost"],
"latency": out["latency"], **checks})
return {
"pass_rate": sum(r["pass"] for r in results) / len(results),
"p50_latency": statistics.median(r["latency"] for r in results),
"avg_cost": statistics.mean(r["cost"] for r in results),
"failures": [r["id"] for r in results if not r["pass"]],
}

if __name__ == "__main__":
cases = [Case(**c) for c in json.load(open("evals/cases.json"))]
report = evaluate(cases)
print(json.dumps(report, indent=2))
assert report["pass_rate"] >= 0.90, "Eval gate failed" # CI gate

Because outputs vary, run each case several times for important flows and look at the pass rate, not one lucky run.

Step 4: Gate changes in CI

Treat prompts, model versions, tool definitions and retrieval settings as code that must pass evals:

  • Run a fast subset on every pull request.
  • Run the full set nightly and before releases.
  • Fail the build when pass rate, cost per task or latency cross agreed thresholds.
  • Post a short diff of failures to the pull request so reviewers see which cases changed.

Step 5: Trace every run

Trace every run

Evals tell you whether a change is safe. Traces tell you why a specific run went wrong. For each agent run, record a structured trace:

{
"trace_id": "tr_4c81",
"timestamp": "2026-10-31T10:22:05Z",
"user_id_hash": "u_9a3f",
"app_version": "2026.10.3",
"model": "model-name-and-version",
"prompt_version": "support-v14",
"steps": [
{"type": "retrieval", "query": "refund policy", "doc_ids": ["kb_12", "kb_77"], "latency_ms": 180},
{"type": "llm", "input_tokens": 2310, "output_tokens": 190, "latency_ms": 1450},
{"type": "tool_call", "name": "orders.lookup", "status": "ok", "latency_ms": 220},
{"type": "llm", "input_tokens": 2800, "output_tokens": 160, "latency_ms": 1100}
],
"final_answer_id": "ans_551",
"cost_usd": 0.0123,
"outcome": {"user_feedback": "thumbs_down", "escalated_to_human": true}
}

What to capture: prompt and model versions, retrieved document ids, each tool call with arguments (hashed or redacted if sensitive), token counts, latency per step, total cost, and user feedback.

Standards help. OpenTelemetry has been developing conventions for generative AI telemetry. Using open standards keeps you from being locked into a single vendor's format. Check current status before committing.

Privacy. Traces often contain personal data. Redact at the source, set retention limits, and restrict access.

Step 6: Monitor what matters in production

Monitor what matters in production



Pick a short list of signals and put an owner on them:

  • Task success rate (sampled and automated): Direct quality measure
  • Escalation and "thumbs-down" rate: Early warning from real users
  • Cost per task and tokens per task: Detects loops and prompt bloat
  • Latency p50 / p95: User experience
  • Tool error rate and retries: Broken integrations
  • Guardrail trigger rate: Attack attempts or prompt drift
  • Retrieval hit rate (for RAG): Stale or missing knowledge

Set alerts on changes, not just thresholds. A jump in cost per task after a deploy is a clearer signal than a static limit.

Online evaluation helps here: score a random sample of live traces automatically, and send low scores to a human review queue. Feed what reviewers find back into the eval set.

Rollout plan for a small team

  • 1: Define success criteria; collect the first 50 cases; deterministic checks only
  • 2: Add tracing to every run; store traces with redaction
  • 3: Add trajectory and rule checks; wire evals into CI as a soft gate
  • 4: Add an LLM judge (calibrated) for fuzzy criteria; make the CI gate hard
  • 5+: Production sampling, dashboards, weekly review of failures into the eval set

You do not need a large platform to start. A JSON file of cases, a script and structured logs get you most of the value.

Common pitfalls

  • Testing only the final answer and ignoring tool use, cost and step count.
  • A static eval set that never grows with production failures.
  • Trusting an uncalibrated LLM judge.
  • Logging everything including sensitive data with no retention policy.
  • No baseline. Always record current performance before changing anything.
  • Treating evals as a one-time project instead of a habit.

Key takeaways

  • Test behaviours and pass rates, not single outputs.
  • Start with 50 to 100 real cases and cheap deterministic checks.
  • Gate prompt, model and tool changes in CI like any other code.
  • Trace every run with versions, retrieved documents, tool calls, cost and feedback.
  • Close the loop: every production failure becomes a permanent test.

Need help making your agent testable?

We build evaluation harnesses, tracing and guardrails into every production AI engagement. Book a Free 45-Min AI/MVP Architecture Review, or read how we approach MCP and agentic AI.

Frequently asked questions

What is an eval in AI? An automated test that measures whether an AI system's behaviour meets defined criteria, usually run over a set of representative inputs.

How many eval cases do I need? Start with 50 to 100 realistic cases and grow the set with every production failure. Quality of coverage matters more than raw count.

Can I use an LLM to grade another LLM? Yes, with care. Calibrate the judge against human labels, use clear rubrics and re-check when models change.

What is the difference between evals and observability? Evals test behaviour before release on known cases. Observability shows what is happening in production on real traffic. You need both.

Do I need a special platform for LLM observability? Not at first. Structured traces and a dashboard can be built on standard tools. Dedicated platforms add convenience as volume grows.

Related reading: Agentic AI Guardrails and Hallucination Prevention · RAG Pipeline Production Failures · Building Enterprise AI Agents

Share

Ready to Start Your Project?

Let's discuss how we can bring your vision to life with AI-powered solutions.

Let's Talk