AI in production
What does good AI agent testing in CI look like?
Your CI pipeline should test your code on every push. It should test the model only when you decide to pay for it.
Short answer
Effective AI agent testing in CI splits the work into tiers. On every commit, run fast unit tests with a scripted fake model that returns fixed tool calls, so routing, graph logic and guards are checked without paying for or waiting on a real LLM. Run routing evals and model-graded quality evals with real models on demand, before releases and model changes, and trace every run so failures point to a specific tool call.
On this page
01Why agents do not fit a normal test pipeline
A normal service has deterministic behavior: the same input gives the same output, so a unit test either passes or fails. An agent does not work that way. The model chooses which tool to call, with which arguments, and in what order. Run the same test twice and you may get two different paths. This is part of our larger guide, LLMOps for SaaS: keep AI features working in production.
Teams respond in one of two ways. Some skip automated tests and rely on manual checks, which means regressions reach users. Others call the real model in every CI run, which makes the pipeline slow, expensive and flaky, until people start ignoring red builds.
Neither works. The answer is to separate what is deterministic in your agent from what is not, and test each in the right place.
02What is actually deterministic in an agent
More of an agent is ordinary code than it looks. Around the model call sit:
- The graph or state machine that decides which node runs next.
- The router that picks which domain agent or tool set handles a request.
- The tool registry: which tools exist, which roles and channels may use them, and how arguments are validated.
- Guards that block leaked tool names, internal IDs or actions that have no matching tool.
- The code that turns API responses into context for the model.
- Retry, loop and duplicate-reply protections.
All of that can be tested like any other code, as long as you take the model out of the loop. That is what a scripted fake model is for.
03The three tiers of AI agent testing we use

| Tier | What it tests | Model used | When it runs | Typical failure it catches |
|---|---|---|---|---|
| Tier 1: unit | Graph logic, routing plumbing, tool permissions, guards | Scripted fake tool-calling model | Every push, in CI | A guard removed, a tool exposed to the wrong role, a broken state transition |
| Tier 2: routing evals | Whether real models pick the right agent and tool | Real model | On demand, before release or model change | A prompt edit that sends booking questions to the wrong agent |
| Tier 3: quality evals | Whether replies are correct, grounded and well formed | Real model, graded by a model and checked by people | On demand, before release or model change | Answers that are on route but wrong, vague or leaking internal fields |
The fake model in Tier 1 is not a mock of the whole agent. It is a stand-in for the language model only. You script its responses: for this test, it returns a call to the booking tool with these arguments, then a final message. The rest of the agent runs for real. LangChain documents this pattern directly: a generic fake chat model returns scripted messages, including tool calls, from an iterator, so agent tests run without API keys.
04How to build Tier 1

- 01
Script the model turn by turn.
For each test, define the exact sequence of model outputs: a tool call, then an answer, or a tool call that should be blocked.
- 02
Run the real graph.
Let your actual routing, nodes, tool registry and guards process those outputs.
- 03
Assert on behavior, not text.
Check which node ran, which tool was called, with which arguments, under which role. Check that a forbidden tool call was refused.
- 04
Test the guards with hostile outputs.
Script the fake model to return an internal ID, a tool name in the reply, or a call to a tool that does not exist. The guard should catch it.
- 05
Test every role and channel.
If cleaners and owners have different tool sets, script the same request for each and assert on the difference.
- 06
Keep fixtures fresh per test.
A scripted iterator that is shared across tests runs out and causes confusing failures.
- 07
Make it fast.
Tier 1 should finish in the time people are willing to wait for a pull request check.
05How to run Tiers 2 and 3
Real-model evals need a dataset of representative requests with expected routes or reference answers, and graders for each. Code-based graders work for routing: did the model pick the expected agent and tool? Model-based graders work for quality, but they need calibration against human judgment, and their prompts should be reviewed like code.
Run these tiers when something changes that affects the model's behavior: a prompt edit, a new tool, a model upgrade. Pin the dataset version in the pipeline so a dataset update does not silently change what "passing" means. Anthropic's guidance on agent evals adds a useful distinction: capability evals tell you how far the agent has to go, while regression evals should stay near a full pass rate, and a drop means something broke.
06Trace everything
Tiered tests catch most regressions, but production will still find new ones. When it does, you need traces that show the exact sequence of model calls and tool calls for that conversation. Log by subsystem, redact customer data and tokens before logs are shared, and turn every production bug into a new Tier 1 or Tier 2 case once you understand it.
For more on how agents fail once real users arrive, see why AI agents fail in production.
07What we see in production
We build and run the AI operations assistant inside an established short-term rental operations platform, used by property owners, cleaner managers and cleaners across web, mobile, SMS, Slack and voice. The assistant acts only through the client's existing backend APIs, exposed as a tightly defined tool registry, with tools allowlisted per role and per channel. In shared property channels a decision node decides whether the AI should answer at all. Guards stop tool names, IDs and internal fields from appearing in replies.
That design gave us a lot of deterministic code worth testing, so we built testing in tiers. Tier 1 unit tests use a scripted fake tool-calling model and run on every push in CI, checking graph logic, routing plumbing and guards without paying for or waiting on a real model. Tier 2 routing evals and Tier 3 model-graded quality evals use real models and run on demand. Agent behavior is traced in an LLM observability tool and in cloud logs by subsystem, and a runbook requires redacting customer data and tokens before logs are shared.
The traces paid for themselves. In a log-verified QA review, 6 of 7 reported bugs were confirmed with root causes traced to exact tool calls, which fed the fixes that followed. The client reported that the app and AI agent were live, and the same tiers now run whenever the assistant moves to a newer model or gains a new channel.
Frequently asked questions
What is a scripted fake model in agent testing?
It is a stand-in for the language model only, not a mock of the whole agent. You script its responses for each test, such as a call to the booking tool with set arguments and then a final message. The real graph, router, tool registry and guards process those outputs, so the tests run without API keys.
Should CI call the real model on every push?
No. Calling the real model in every CI run makes the pipeline slow, expensive and flaky, until people start ignoring red builds. Run fast Tier 1 unit tests with a fake model on every push, and run routing and quality evals with real models on demand, before releases and model changes.
How do you grade routing and quality evals?
Code-based graders work for routing: did the model pick the expected agent and tool? Model-based graders work for quality, but they need calibration against human judgment, and their prompts should be reviewed like code. Pin the dataset version in the pipeline so a dataset update does not silently change what passing means.
What should happen when production finds a new bug?
Use traces to see the exact sequence of model calls and tool calls for that conversation, with customer data and tokens redacted before logs are shared. Once you understand the bug, turn it into a new Tier 1 or Tier 2 case, so the same regression cannot return unnoticed.
How Datics helps
Datics specializes in brownfield AI: bringing production AI into the product you already operate, without forcing a rebuild.
Related work
Case studies from our projects on the same subject.
CleanHaus
Real Estate & Hospitality · Turnover operations SaaS
Hosts and cleaners manage rental turnovers in chat, within each person's permissions
Owners, managers and cleaners all talk in one property chat. Now an AI there acts for each of them, only within that person's role.
Cosmic AI
Financial Services · Multi-agent investing assistant
Retail investors go from research to a confirmed order in one conversation
Investors juggled data, news and a separate broker. Now agents research and prepare each trade in chat, and nothing is placed until they confirm.
SovrenAI
B2B Software · Enterprise Builder, an AI internal app builder
Internal apps built on company data, with a person confirming every guessed join
An agent writing queries over unknown schemas can join the wrong tables; here every guessed join waits for a person to approve it.
More on AI in production
AI in production
LLMOps for SaaS: keep AI features working in production
LLMOps for product teams: evaluation gates, prompt and model versioning, tracing, regression checks, cost per task, kill switches and model upgrades.
AI in production
AI agent monitoring: catch regressions in production
AI agent monitoring for live SaaS products: what to trace on every run, which user signals to watch, how to score traces and when to roll a change back.
AI in production
Why add an AI kill switch to every feature and agent?
An AI kill switch lets you disable or degrade an AI feature in seconds, without a release. Here is how we design kill switches and safe fallbacks.
AI in production
How can prompt management put domain experts in control?
Prompt management lets domain teams refine AI prompts and scoring rules after launch, while engineering keeps the pipeline, guardrails and staging step.
AI in production
Which AI pricing model works when every answer costs money?
Build an AI pricing model from cost per action: decide which plans trigger expensive AI work and how often, then enforce limits on the server.
AI in production
How do you approach AI model testing on messy real data?
AI model testing for document and data extraction: build messy test sets early, compare AI output with human entry and turn each failure into a regression case.
Your customers already expect AI from your product.
Let us make it real without rebuilding what already works.
