Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 10 min read

Versioning, Testing and Rollback: Treating AI Agents Like Production Software

In one sentence: An AI agent is a bundle of instructions, knowledge, tools and a model, so it needs the three habits that keep production software safe: version everything, test before every release and make rollback a r

Versioning, Testing and Rollback: Treating AI Agents Like Production Software

In one sentence: An AI agent is a bundle of instructions, knowledge, tools and a model, so it needs the three habits that keep production software safe: version everything, test before every release and make rollback a routine, rehearsed operation.

Software engineers learned decades ago that the code you ship is a risk and that the cure is discipline: version control, automated tests and the ability to undo a bad release. AI agents are now arriving in enterprises without that inheritance. Their instructions live in text boxes, their knowledge changes quietly and their models are updated by someone else. This post explains how to bring production discipline to agents. We use the STAR format (Situation, Task, Action, Result) to show what goes wrong, what to put in place and how to know it is working.

The Change Nobody Made

Consider a member-owned lender we’ll call Harbor Credit Union. As in our earlier posts, this is a composite scenario, not a customer case, but the pattern is familiar.

Harbor runs an agent that answers members’ questions about loan applications: where a request stands, which documents are missing and what happens next. It has run well for months. Then, one Monday, members begin to complain that the agent is telling them their applications are β€œunder final review” when they are still waiting for documents. The operations team is alarmed. A fix seems urgent.

The first question is the one that exposes the problem: what changed? The team checks the agent’s instructions and finds no edits that week. They check the tools and find nothing new. Eventually, someone notices that a policy document in the knowledge base was updated on Friday and that it uses the phrase β€œfinal review” in a new sense. Another person points out that the model provider released an update a few days earlier. Any of the three could be the cause. Nobody can prove which and nobody can restore the Thursday configuration, because it was never recorded as a whole.
This is what makes agents different from conventional software and why habits from the old world are necessary but not sufficient. A traditional application changes when its code changes. An agent changes when any of several things change: its instructions, its knowledge, its tools, its model or its settings. Some of these can change without anyone touching the agent at all.

Figure 1 summarizes what carries over from traditional software practice and what needs new thinking.
Figure 1. Traditional software vs. AI agents

The cost of ignoring this compounds with scale. An agent that touches loans, payments or personal data can cause real harm in a short time and every hour spent searching for the cause of a regression is an hour of continued exposure. Teams that cannot answer β€œwhat changed?” quickly tend to respond by freezing all change, which protects against incidents and also against improvement.

A related point concerns accountability. In regulated industries, being able to show what an agent was running at the moment of a decision is not a convenience but an obligation. A regulator or auditor who asks why a member received a particular answer expects a precise reply: this version, with these instructions, drawing on this knowledge. Without versioning, the honest answer is β€œwe cannot be certain.”

Pause and check: For an agent in your organization, could you list everything that was live on a particular day last month: instructions, knowledge, tools, model and settings? If not, you could not reproduce a past incident either.

Make Change Safe and Reversible
Your task is to make every change to an agent visible, testable and reversible. That breaks down into three commitments.
β€’ Version the whole bundle. Record every ingredient that shapes behavior and treat a change to any of them as a new version.
β€’ Test before every release. Run the agent against a reviewed set of cases, with allowances for the fact that results can vary from run to run.
β€’ Rehearse rollback. Be able to restore the previous version in minutes and know what to do about actions the bad version already took.
These commitments apply whatever platform you use and they apply whether you have one agent or fifty. They are also proportionate: a low-risk internal assistant needs light versions of each, while an agent that handles money needs rigorous ones.

For Harbor, the task becomes concrete: snapshot every ingredient of the loan-status agent as one version, test each change against real member questions and be able to restore last week’s configuration and identify who was affected, within the hour.

Version, Test, Roll Back

Versioning the bundle
The first step is to be precise about what a version contains. Figure 2 shows the ingredients.
Figure 2. What a version contains
AGENT VERSION 4.2.0
+--------------------------------------------------+
| Instructions the brief (hash: a91f...) |
| Knowledge snapshot documents as of 20 Nov |
| Tool definitions names, schemas, permissions |
| Model provider, model, version |
| Settings temperature, step limit |
| Limits and rules approval and spending caps |
+--------------------------------------------------+
A change to ANY line is a new version.

Two ingredients deserve special attention because they change silently. Knowledge is the first. If the agent reads live documents, then a policy edit is effectively a release, whether or not anyone intended it. The remedy is to pin each version to a snapshot of its knowledge and to promote document changes through the same gates as instructions. The model is the second. Pin the specific model version where your provider allows it and treat a provider’s update as a candidate release to be tested before it goes live.

Now the technical part. The snippets below are simplified, illustrative Python rather than a production framework. The first builds a version manifest and fingerprints it, so any change, however small, produces a different identifier.

Figure 3a. A version manifest with a content fingerprint
import hashlib, json

def build_manifest(instructions, knowledge_snapshot_id, tools, model, settings, limits):
manifest = {
"instructions": instructions,
"knowledge_snapshot": knowledge_snapshot_id, # pinned, not "latest"
"tools": sorted(tools, key=lambda t: t["name"]),
"model": model, # exact model version
"settings": settings,
"limits": limits,
}
blob = json.dumps(manifest, sort_keys=True).encode()
manifest["fingerprint"] = hashlib.sha256(blob).hexdigest()[:12]
return manifest

Same ingredients -> same fingerprint. Any change -> a new, comparable version.

Testing when results vary

Agents built on language models do not always give identical answers to identical inputs. That makes a single passing run weak evidence. A case that passes once and fails the next time is a warning, not a success. Figure 4 shows a testing pyramid adapted for this reality, with fast, cheap checks at the base and expensive, realistic ones at the top.

Figure 4. A testing pyramid for agents
/\
/ \ 5. CANARY IN PRODUCTION
/----\ a small share of real cases
/ \ 4. ADVERSARIAL AND EDGE CASES
/--------\ attempts to break rules and limits
/ \ 3. SCENARIO EVALUATION
/------------\ reviewed real cases, repeated runs
/ \2. TOOL AND INTEGRATION TESTS
/----------------\ mocked systems, schemas, permissions
/ \1. STATIC CHECKS
/--------------------\ lint the brief, validate the manifest

The lower layers are quick and run on every change. The upper layers take longer and are reserved for candidates that have passed the earlier ones. The second snippet shows the heart of the scenario layer: each case runs several times and the result is reported as a pass rate, with unstable cases flagged for attention.
Figure 3b. Repeated-run evaluation to expose unstable cases
def evaluate(agent, cases, runs=5, min_pass=0.95):
report, unstable = [], []
for case in cases:
results = [judge(agent.run(case["input"]), case) for _ in range(runs)]
rate = sum(results) / runs
report.append((case["id"], rate))
if 0 < rate < 1: # sometimes right, sometimes wrong
unstable.append(case["id"])

overall = sum(r for _, r in report) / len(report)
return {
    "overall": overall,
    "passes_gate": overall >= min_pass and not unstable,
    "unstable_cases": unstable,
}

The numbers in these snippets are illustrative. Five runs and a 95 percent threshold are placeholders; choose values that match the cost of an error in your setting. The principle is what matters: a case that is sometimes wrong should block a release for an agent that handles consequential work, because production will find the failing runs.

It also helps to keep two kinds of test data separate. A development set is what the team looks at while improving the agent. A held-out set is what the release gate uses and nobody tunes against it. If the same cases are used for both, the agent gradually learns the test and the pass rate drifts upward while real quality stands still. Refresh the held-out set with fresh examples from production, including every case that caused an incident.

Rolling back, including what cannot be undone

Rollback is the most valuable safety net and the least rehearsed. Mechanically, it should be simple: a pointer from β€œlive” to a version, which you can move back in one step. Keep the previous few versions fully intact and ready and never delete a version that was live. Figure 5 lists the triggers that should prompt a rollback.

Figure 5. Rollback triggers

There is a catch that software engineers will recognize and many AI teams overlook. Rolling back restores the agent’s future behavior. It does not undo what the bad version already did. Emails have been sent, records updated, tickets closed. To handle this, keep a ledger of every action each agent takes, tagged with the version that took it. After a rollback, the ledger tells you exactly which cases the bad version touched, so a person or a corrective agent can review them.
The third snippet shows both halves: restoring the previous version and listing the cases that need follow-up.

Figure 3c. Rollback with an affected-case report
def rollback(agent_name: str, bad_version: str):
previous = registry.previous_live(agent_name) # kept intact and ready
router.point_to(agent_name, previous) # one step, no rebuild

affected = ledger.actions(                          # every action, tagged by version
    agent=agent_name, version=bad_version, since=registry.live_since(bad_version)
)
review_queue.add_all(a.case_id for a in affected if a.changed_state)

alert.owner(agent_name, f"Rolled back {bad_version}; "
                        f"{len(affected)} actions to review")
audit.log(agent_name, "rollback", bad_version, count=len(affected))

This design has a second benefit. Because every action carries a version tag, you can also design actions to be reversible where possible, for instance by drafting rather than sending, or by holding changes for approval. Figure 6 shows how different kinds of action behave after a rollback.

Figure 6. What rollback can and cannot undo

What Good Looks Like

As in our previous posts, we will not promise a particular saving or improvement. The result of production discipline is not a figure; it is a different experience when something goes wrong.

For Harbor, the next surprise unfolds very differently. The loan-status agent runs from a pinned bundle. When the policy document changes, it enters as a candidate version and is tested before release. The repeated-run evaluation flags a case that sometimes says β€œfinal review” too early and the release is held until the wording is clarified. Months later, a model update causes a subtle drift, a monitoring rule trips and the agent rolls back automatically. The ledger lists the thirty or so cases it touched. A person reviews them the same morning.

Expect the first few weeks to feel like added effort. Building the test set, pinning knowledge and recording actions all take time. The payoff arrives at the first incident, when the question β€œwhat changed?” has an answer in minutes instead of days.

Figure 7. A scorecard for production discipline

Three pitfalls to avoid
β€’ Versioning only the instructions. Knowledge, tools, model and settings all shape behavior. Leave one out and you cannot reproduce an incident.
β€’ Trusting a single passing run. Variation is part of how these systems work. Repeat your tests and take instability seriously.
β€’ Assuming rollback undoes everything. It restores future behavior only. Record actions so you can find and fix the past.

Figure 8. STAR recap

Where should you start?

Pick one agent and answer a single question: if it misbehaved this afternoon, could you restore Thursday’s version and list everyone it affected since? Wherever the answer is no, start there. Pin the knowledge and model, write the manifest, build a small repeated-run test set and begin recording actions with their version. Then practise a rollback on a quiet day, so that the first real one is not also the first attempt.

Software earned its reputation for reliability through unglamorous habits: versions, tests and the ability to go back. Agents deserve the same and they need a little more, because their behavior depends on more moving parts and their errors can be harder to spot. Teams that adopt these habits early will find that trust in their agents grows, because mistakes become small, visible and reversible.

Visit us on www.intellibooks.io

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.