Module 09 · Lesson 9.6
Versioning, Rollbacks and Production Operations
On this page
- What you will learn
- Why an agent needs versions
- What to version in an AI agent
- Put the version label on every trace
- A release checklist and the rollback rule
- Incident basics: detect, roll back, investigate, write up
- A version registry with rollback in Python
- Conclusion and your next step
- Common errors and fixes
- Validation checklist
- Hands-on exercise
- Knowledge check
- Frequently asked questions
- References
Picture a restaurant that changes its menu, its supplier and its head chef on the same Friday. On Saturday the food tastes odd. Nobody can say which of the three changes caused it, and nobody wrote down what the old recipe was. Going back is guesswork.
Agents are easy to change and hard to reason about, so this happens often. A single edited sentence in the instructions can change how every customer is treated. This lesson shows how to version everything that changes behaviour, record the version in every trace, release carefully and roll back (return to the last good version) in minutes. Most of it needs no coding. One short Python script shows a version registry with a rollback.
What you will learn
- List everything in an agent that should be versioned.
- Explain how version labels in traces help you find the cause of a change in behaviour.
- Follow a release checklist and a rollback procedure.
- Run a Python script that releases versions and rolls back, printing each change.
Before you start
- Caching, Model Selection and Token Optimization, because changes like those need safe releases.
- No coding experience is needed for most of this lesson.
- Optional: Python 3.10 or later, if you want to run the example yourself.
Why an agent needs versions
In normal software, behaviour changes when the code changes, and your version control tool records every change. An agent is different. Its behaviour also depends on text and settings that are easy to edit and easy to forget: the instructions, the model name, the knowledge base and the descriptions of the tools.
Without versions you cannot answer the most important question after a problem: what changed? With versions you can compare the good state and the bad state and see the difference.
- Version
- A label for one exact, unchanged state of something, such as v1 or 1.2.0.
- Release
- Making a new version the one that real customers use.
- Rollback
- Switching customers back to the previous good version after a bad release.
- Incident
- An event where the service harms customers or the business and needs urgent action.
What to version in an AI agent
Version everything that can change how the agent behaves. The table shows the usual list for the Quillfeather support agent.
| Part | Example of a change | Where to keep its version |
|---|---|---|
| Instructions (the system prompt) | Add a rule about refunds | A file in your repository with a version label |
| Model and settings | Switch to another model or change a setting | A config file, with the model name in one place |
| Tool contracts | Add a field to the lookup_order result | A file describing each tool's inputs and outputs |
| Knowledge base | Rewrite the returns page KB-03 | A dated label such as kb-2026-11 |
| Code | Change the retry logic | Your normal version control tool, with a release tag |
Bundle the parts into one release version
Customers do not use "instructions 1.1.0" alone. They use a particular combination of instructions, model, tools and knowledge base. Give each combination one label, such as v2, and store the full list behind it. Then a release or a rollback moves all the parts together.
v1 = instructions 1.0.0 + model-a + tool contracts 1.0.0 + kb-2026-10
v2 = instructions 1.1.0 + model-b + tool contracts 1.0.0 + kb-2026-11Put the version label on every trace
The trace event format from Tracing Tool Calls and Agent Decisions has a version field. Fill it in on every event. Then you can ask useful questions: did the error rate rise after v2 went live? Are v2 runs slower than v1 runs?
{"run_id": "R-0007", "step": 1, "kind": "model", "name": "gemini", "ms": 120, "ok": true, "version": "v2"}Pair this with the monitoring numbers from Monitoring Quality, Failures, Latency and Cost. Split each number by version. If the handover rate is 15% on v1 and 40% on v2, you have found the change that matters.
A release checklist and the rollback rule
A release is safest when it is boring. Use the same checklist every time.
Step 1: Write down what changed and why, in two or three lines.
Step 2: Run the evaluation suite on the new version and compare it case by case with the current version, as in [Regression Testing and Model/Prompt Changes](/lessons/regression-testing-model-and-prompt-changes).
Step 3: Check the release rule: no new failures on must-pass cases. If it fails, do not release.
Step 4: Confirm the previous version is still available and tested, so you can go back.
Step 5: Release to the new version, ideally to a small share of traffic first if your setup allows it.
Step 6: Watch the monitoring numbers for the new version for a set period, such as the first hour.
A rollback is only quick if you prepared for it. Keep the old version's instructions, model setting and knowledge base available, and make the switch a single change, such as writing the old version's name into a small config file. The blog post Zero-Downtime Deployments: Feature Flags, Blue-Green, and AI-Generated Rollout Plans covers general techniques for switching traffic safely.
Incident basics: detect, roll back, investigate, write up
Even careful releases sometimes fail. A calm, repeatable routine helps. Four steps cover the basics.
- Detect. An alert fires or a person reports a problem. Note the time and what customers are seeing.
- Roll back. Return to the last good version. If the harm may be ongoing, such as an agent giving wrong refund promises, you can also pause the agent and hand customers to a person.
- Investigate. Use the traces and the version labels to find what changed and which runs were affected. Do not read personal data you do not need. Keep the redaction rules from Data Privacy, Sensitive Information and Secure Logging.
- Write it up. Record what happened, the cause, how you found it, what you changed and what will stop it happening again.
The write-up is often called a post-mortem. Its purpose is learning, not blame. For a full template, see Writing a SEV1 Incident Post-Mortem with AI: Prompt Templates for On-Call Engineers.
A version registry with rollback in Python
The script below keeps two versions in a dictionary, tracks which one is active and remembers the history. A release is refused if the version is unknown or the evaluation did not pass. A rollback goes back one step. It prints each change, so you can follow it.
REGISTRY = {
"v1": {"instructions": "support-prompt 1.0.0", "model": "model-a", "tools": "contracts 1.0.0",
"kb": "kb-2026-10"},
"v2": {"instructions": "support-prompt 1.1.0", "model": "model-b", "tools": "contracts 1.0.0",
"kb": "kb-2026-11"},
}
state = {"active": "v1", "history": ["v1"]}
def show(label):
print(label, "-> active:", state["active"], "| history:", state["history"])
def release(version, eval_passed):
if version not in REGISTRY:
print("REFUSED: unknown version", version)
return
if not eval_passed:
print("REFUSED:", version, "has new eval failures")
return
state["active"] = version
state["history"].append(version)
show("release " + version)
def rollback():
if len(state["history"]) < 2:
print("REFUSED: nothing to roll back to")
return
state["history"].pop()
state["active"] = state["history"][-1]
show("rollback")
def diff(a, b):
return [k for k in REGISTRY[a] if REGISTRY[a][k] != REGISTRY[b][k]]
show("start")
print("v1 vs v2 differ in:", diff("v1", "v2"))
release("v3", True)
release("v2", False)
release("v2", True)
trace = {"run_id": "R-0007", "kind": "model", "name": "gemini", "ms": 120, "ok": True,
"version": state["active"]}
print("trace:", trace)
rollback()
rollback()Offline and deterministic. Model names here are placeholders. Run it with python registry_demo.py.
What each part does
REGISTRYmaps each version label to the full set of parts: instructions, model, tools and knowledge base. This is the bundle fromversions.txt.stateholds theactiveversion and thehistoryof past active versions, so a rollback knows where to go.release(version, eval_passed)refuses an unknown version or a version that failed evaluation. Otherwise it makes the version active and adds it to the history.rollback()removes the latest entry from the history and makes the one before it active. If there is nothing to go back to, it refuses.diff(a, b)lists which parts differ between two versions. It answers "what changed?" quickly.- The
tracedictionary shows the version label being copied into a trace event.
start -> active: v1 | history: ['v1']
v1 vs v2 differ in: ['instructions', 'model', 'kb']
REFUSED: unknown version v3
REFUSED: v2 has new eval failures
release v2 -> active: v2 | history: ['v1', 'v2']
trace: {'run_id': 'R-0007', 'kind': 'model', 'name': 'gemini', 'ms': 120, 'ok': True, 'version': 'v2'}
rollback -> active: v1 | history: ['v1']
REFUSED: nothing to roll back toRead the output from top to bottom. The comparison shows that v2 changed the instructions, the model and the knowledge base all at once. That is three changes in one release, which makes a problem harder to trace. A calmer plan would release them one at a time. The two refusals show the safety rules working. After the real release the trace carries the label v2, and the first rollback returns to v1. The second rollback is refused because there is no older version.
Conclusion and your next step
Version the instructions, model, tool contracts, knowledge base and code. Bundle them under one release label, record it in every trace and release only when the evaluation suite shows no new failures. When something goes wrong, roll back first and investigate second, then write down what you learned.
Your next step: write the release checklist for your own agent and name the file where its active version lives. Then continue to Practical Lab: Deploy and Monitor an Agent Service, where you put the API, traces, monitoring and a rollback together in one small service.
For related reading, see Agent Runtime and Deployment Architecture and the Agent Launch Safety Checklist.
Common errors and how to fix them
After a release nobody can say what changed.
Why it happens: Several parts changed together and no version records were kept.
Fix: Bundle parts under one version label, store the full list for each label, and release one change at a time where possible.
Rollback takes hours.
Why it happens: The old instructions or model setting were overwritten, so the previous version has to be rebuilt.
Fix: Keep every released version available, and make the switch one small change, such as a version name in a config file.
The rollback did not fix the problem.
Why it happens: Data written by the bad version, such as cached answers or saved sessions, is still being used.
Fix: Clear caches tied to the bad version and check how stored data from the new version behaves with the old one.
Traces cannot be linked to a release.
Why it happens: The version field is empty or filled in only on some events.
Fix: Set the version once when the run starts and copy it to every trace event, then check this in a test.
Validation checklist
Tick each item once you have confirmed it.
Hands-on exercise
Plan a release and its rollback
Quillfeather wants to change the help instructions and switch the knowledge base to a new month. Write a short release plan with the version bundles, the checks, the watch period and the rollback steps.
You will need
- Current version v3: instructions 2.0.0, model-a, tool contracts 1.2.0, kb-2026-10.
- Proposed version v4: instructions 2.1.0, model-a, tool contracts 1.2.0, kb-2026-11.
- The evaluation suite has 25 cases, 6 of them marked must-pass.
- Active version is read from a file called active_version.txt.
Acceptance criteria
Your work is done when every one of these is true.
Hints (3)
- Two parts change here. Could you release them one at a time?
- Which numbers would show a problem quickly: handover rate, grounding failures, errors?
- After a rollback, think about cached answers and sessions created under v4.
Show a model answer
A good plan writes v3 and v4 out in full and notes that two parts differ: the instructions and the knowledge base. It suggests releasing them separately if time allows, so a problem points to one change. Before release, run all 25 cases on v4 and compare them case by case with v3. If any of the 6 must-pass cases newly fails, stop. After release, watch error rate and handover rate for v4 against v3 for the first hour. Roll back by writing v3 into active_version.txt, then check that the health endpoint reports v3 and that new traces carry the label v3. Clear any cached answers produced under v4, and open a few v4 traces to start the investigation.
Knowledge check
Choose an answer, then check it. Nothing is recorded — this is for you.
Show the answer and explanation
Answer: B. With the label you can split error rates and handover rates by version and see which release caused a change. The provider does not require it. You add it for yourself, and you will be glad of it during an incident.
Show the answer and explanation
Answer: B. Rolling back stops the harm fast. Investigating first feels responsible, but every minute spent searching is another minute of customers getting wrong answers. The traces are still there to read after the rollback.
Show the answer and explanation
Answer: B. All of them change behaviour. Versioning only the code is tempting because that is what version control tools do automatically, but an edited prompt or a new knowledge base can change answers just as much.
Frequently asked questions
What is a rollback?
A rollback means switching customers back to the previous working version after a release causes problems. It works best when the old version is kept ready and the switch is one small change, such as a line in a config file.
Should I version my prompts?
Yes. A prompt change can alter every answer, so keep prompts in files in your repository, give them a version label, and record the label in your traces. Treat a prompt edit like a code change: test it before release.
What is semantic versioning?
It is a way of numbering versions as MAJOR.MINOR.PATCH, such as 1.2.3. The first number rises for big, breaking changes, the second for new features and the third for small fixes. It is common for software, and you can borrow the idea for prompts and tool contracts.
What should I do when an AI agent starts behaving badly in production?
Roll back to the last good version first, or pause the agent and hand customers to a person if the harm may continue. Then use the traces and version labels to find what changed, and write up what happened so the same mistake is caught earlier next time.
- Written by
- PromptFable Editorial
- Last updated 18 Nov 2026
- Review
- Reviewed by Waseem Nadir, Technical Reviewer
- Last reviewed 27 Nov 2026
References
Primary sources for the technical details in this lesson. Vendor platforms change — check the official page if anything here looks different from what you see.
- Semantic Versioning(opens in a new tab)
semver.org · Official documentation · The MAJOR.MINOR.PATCH numbering scheme and its rules.
- Config(opens in a new tab)
The Twelve-Factor App · Official documentation · Why settings such as the active version belong in configuration, not in code.
- Demystifying evals for AI agents(opens in a new tab)
Anthropic · Official documentation · Using evaluations to check changes before they reach customers.
- Traces(opens in a new tab)
OpenTelemetry · Official documentation · General background on traces, which carry the version label.
- NIST AI Risk Management Framework(opens in a new tab)
NIST · Official documentation · A general framework for managing AI risk, including monitoring and change control.
PromptFable is independent and is not affiliated with, endorsed by or sponsored by Anthropic, Google, OpenAI or any other vendor. Claude, Gemini, Google AI Studio and other product names are trademarks of their respective owners.