CI/CD for AI Agents: Test Decisions, Not Just Code
From the publisher’s feed, collected in the ZeroLabs newsroom.
A practical pipeline for testing agent behavior, releasing it safely, and learning from production failures.Your pull request changes three lines in a prompt. The application builds. Unit tests pass. Integration tests pass. The container reaches production without an error.Then the support agent starts refunding orders that should have been escalated.Nothing in the normal pipeline caught it because the code still worked. The request reached the model, the model called a valid tool, and the API returned 200 OK. The failure was in the agent's behavior: it chose the wrong action.This is the main difference between CI/CD for an API and CI/CD for an AI agent. An API pipeline proves that software behaves according to a defined contract. An agent pipeline must also measure decisions that can vary from one run to the next.That does not mean replacing normal software tests. It means adding another layer around them.What normal CI/CD already does wellConsider a backend endpoint:POST /refundinput: order ID + reasonoutput: refund record or a defined errorWe know how to test this. A useful pipeline might:Run unit tests for refund rules.Run integration tests against a database and payment sandbox.Check the API schema.Scan dependencies and the container image.Build one immutable artifact.Deploy it gradually and watch errors and latency.Given the same database state and input, we expect the same status code and response shape.Keep all of this for an agent. Its API, storage, authentication, tool adapters, and deployment still need ordinary tests. But those checks cannot answer the new question: did the agent make a good decision?Here is the difference at a glance:The release unit is bigger than the codeAn agent’s behavior usually depends on several parts:Treat these parts as one behavior bundle. Version them together for every candidate release.A release record does not need to be complicated. It can start as JSON:{ "release": "support-agent-2026-09-04.2", "code_commit": "8c3f1e2", "prompt_version": "refund-policy-v7", "model": "provider/model-version", "temperature": 0.1, "tool_schema_version": "support-tools-v4", "knowledge_snapshot": "policies-2026-09-04", "max_steps": 8, "timeout_seconds": 30}Now a bad production run can be tied to the exact prompt, model, tools, data, and limits that produced it. Without this record, “roll back the agent” is an unclear instruction. You may roll back the code while leaving the changed prompt or model in place.CI needs recorded scenariosLive systems are poor test fixtures. Customer state changes, documents are updated, and external APIs return different data. If the world changes between runs, you cannot tell whether a score moved because the agent changed or because its inputs did.The fix is to build a small scenario bank. Each scenario contains:the task given to the agent;recorded responses for every tool it may call;the expected outcome;evidence the agent should use;unsafe or irrelevant actions it should avoid;a step, latency, or cost budget.For the refund agent, one scenario could look like this:name: damaged_item_above_auto_refund_limittask: customer_message: "The monitor arrived with a cracked screen." order_id: "order-1042"recorded_tools: get_order: total_usd: 899 delivered_days_ago: 2 get_refund_policy: automatic_refund_limit_usd: 200 damaged_item_action: escalateexpected: outcome: escalate_to_human required_evidence: - order total is above automatic refund limit - policy requires escalation forbidden_actions: - issue_refund max_tool_calls: 4During CI, replace the live tools with replay tools that return this recorded data. The agent should not know it is in a test. It receives the same tool names and response shapes it would see in production.One detail matters: keep expected away from the agent. Only the grader should see it. If the answer key enters the prompt or retrieval context, a high score only proves the agent can repeat the answer it was shown.Grade the result and the pathAn agent can reach the right answer for the wrong reason. Imagine that the refund agent escalates every order above $500 without reading the policy. It passes the scenario above, but it has not learned the real rule. A later policy change will expose the shortcut.That is why agent CI should grade two things:Outcome: Did the agent choose the correct answer or action?Trajectory: Did it use the right evidence and stay within its limits?Start with deterministic checks whenever possible:PASS outcome is escalate_to_humanPASS get_refund_policy was calledPASS issue_refund was not calledPASS tool calls PASS estimated cost These checks are cheap, repeatable, and easy to explain when they fail.Use an LLM judge only for properties that need judgment, such as whether an explanation is clear or whether a response addresses the customer’s concern. Give the judge a narrow rubric and store its comments, but do not let one judge score decide the release by itself. Judge models can vary too.Do not hide everything behind one scoreSuppose version A passes 92% of scenarios and version B passes 94%. Version B looks better until you notice that it doubled cost and occasionally attempts a write action outside policy.Track separate release dimensions:Some gates should be absolute. A forbidden payment or deletion action should block the release even when the average quality score improves.Also run variable scenarios more than once. A single pass tells you what happened once. It does not tell you how often the agent succeeds.A practical pull-request pipelineYou do not need hundreds of cases on day one. Start with ten to twenty cases that cover the important paths and the failures you fear most.A useful CI pipeline runs in this order:1. Lint and type-check2. Unit-test deterministic code3. Test tool adapters and schemas4. Replay the fast scenario suite5. Compare candidate metrics with the current baseline6. Run slower or model-based evaluation for risky changes7. Save the behavior bundle and evaluation reportRun the fast, deterministic suite on every pull request. You can reserve larger or more expensive evaluations for changes to prompts, models, tools, retrieval, or safety policy.The report should make regressions easy to inspect. Show which scenarios changed, which gate failed, the tool trajectory, token and cost totals, and the candidate’s bundle versions. A single red score with no evidence sends the team back to manual guesswork.Passing CI should not mean full deploymentA scenario bank only covers cases you already know. Production will find the missing ones.Release the candidate to a constrained canary first: a small, controlled share of real traffic that limits damage if the new version is wrong. Depending on the agent, that might mean:internal users only;1% of eligible conversations;read-only tools;a small set of low-risk actions;human approval before any write;tighter step and spending limits.Compare the canary with the current version. Watch task success, escalation rate, forbidden actions, tool errors, latency, cost, and user corrections. Keep the previous behavior bundle ready for rollback.The blast radius should match your confidence. A summarization agent can usually take a larger canary than an agent that changes account permissions.Store traces you can actually investigateHTTP metrics are still useful, but 200 OK does not mean the agent did the right thing. For each run, record enough information to reconstruct the decision:behavior bundle version;scenario, request, or session ID;model and prompt version;tools called, arguments, and results;outcome;policy decisions and human approvals;tokens, latency, and estimated cost;user correction, escalation, or rollback signal.Apply access controls and retention limits. Redact secrets and personal data before storing traces or turning them into test scenarios. Evaluation data can become a second copy of production data if you treat it carelessly.Turn production misses into regression testsThe scenario bank should grow from real failures, not only imagined edge cases.When the agent makes a meaningful mistake:Save the trace and confirm what should have happened.Remove secrets and unnecessary customer data.Replace live tool calls with recorded responses.Write an answer key and safety limits.Reproduce the failure against the released bundle.Fix the agent and keep the scenario in CI permanently.This is the same habit that makes an ordinary test suite valuable: a bug should be paid for once. After the fix, the pipeline remembers it.The minimum useful versionIf all of this feels like too much, build the first version in this order:Version the prompt, model, tools, and budgets with the code.Record five real tasks whose correct outcomes you know.Replay tool responses instead of calling live systems.Check outcome, required evidence, forbidden actions, and step count.Compare every candidate with the released baseline.Deploy to a read-only or human-approved canary.Turn the next production miss into scenario number six.That is enough to stop deciding whether a prompt change “feels better.”The complete delivery loop is:Change → replay → evaluate → compare → canary → observe → record → repeatNormal CI/CD still ships the application. The added agent pipeline gives you evidence that the behavior inside it is ready to ship too.CI/CD for AI Agents: Test Decisions, Not Just Code was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.