DEV Community

Cover image for Updating AI agent models: a regression gate before you switch
MatIntellect
MatIntellect

Posted on Edited on Originally published at matintellect.com AI-assisted

Updating AI agent models: a regression gate before you switch

Problem: a new model can be better on benchmarks and still break one behaviour your agent depends on, such as asking for confirmation before sending something. Result of this article: a small gate that replays a fixed set of real tasks on the old and new model, reports lost behaviours and refuses to switch without a verified backup. Stack: plain Python 3.10+ (tested on 3.15.2), no external packages. Boundaries: both models are stubs returning recorded behaviours; wire in your own runs, with real sends switched off

AI-generated illustration of updating an AI agent model safely

Where this comes from

Every day 8 Claude Code agents work for me, on Sonnet 5 and Opus 5.5 depending on the role. I update them by hand when a major model comes out; the last move was from Opus 5 to Opus 5.5, skipping the versions in between. I move one agent at a time and watch its real work before moving the next

Backups run automatically at least weekly, with a manual one before every major update. My personal agent, Jes, also has an automatic backup model, so its 10 scheduled jobs keep running if the primary fails

For clients the stakes are higher: a clinic runs a team of 6 agents on the owner's server, and assistants run for five people on their own servers. A broken upgrade there hits someone else's clients

The code below is a teaching version of the gate I apply by hand. It is not code from my systems

Input, processing, output

Input: a set of real tasks, each with the behaviours a correct run must show (asks for confirmation, reads the date correctly, follows the format), plus the observed behaviours of the old and the new model on each task, and whether the backup has been verified by an actual restore

Processing: for each task, the gate computes which required behaviours the old model showed and the new one lost. The decision refuses any switch without a restored backup, keeps the old model if there is any regression, and otherwise allows switching this one agent only

Output: one line per regression and one decision line

Working at a computer during a system update

The example

# Replay a fixed task set on the old and new model, then decide per agent
TASKS = [  # (task, what a correct run must do)
    ("book a call tomorrow at 15:00", {"asks_confirmation", "date_ok"}),
    ("find a free slot next week", {"date_ok"}),
    ("summarise yesterday's messages", {"follows_format"}),
    ("send the invoice to the client", {"asks_confirmation"}),
]

def run_old(task):   # stands in for the current model's recorded behaviour
    return {"asks_confirmation", "date_ok", "follows_format"}

def run_new(task):   # stands in for the candidate model; it skips one confirmation
    if task.startswith("send"):
        return {"date_ok", "follows_format"}
    return {"asks_confirmation", "date_ok", "follows_format"}

def compare(tasks, old, new):
    regressions = []
    for task, must in tasks:
        lost = must & old(task) - new(task)
        if lost:
            regressions.append((task, sorted(lost)))
    return regressions

def decide(agent, regressions, backup_restored):
    if not backup_restored:
        return f"{agent}: stop, backup not verified by a restore"
    if regressions:
        return f"{agent}: keep old model, {len(regressions)} regression(s)"
    return f"{agent}: switch this one agent, watch it before the next"

if __name__ == "__main__":
    regs = compare(TASKS, run_old, run_new)
    for task, lost in regs:
        print(f"regression: '{task}' no longer does {', '.join(lost)}")
    print(decide("calendar-agent", regs, backup_restored=True))
    print(decide("calendar-agent", [], backup_restored=False))
    print(decide("calendar-agent", [], backup_restored=True))
Enter fullscreen mode Exit fullscreen mode

Output, exactly as it printed when I ran it:

regression: 'send the invoice to the client' no longer does asks_confirmation
calendar-agent: keep old model, 1 regression(s)
calendar-agent: stop, backup not verified by a restore
calendar-agent: switch this one agent, watch it before the next
Enter fullscreen mode Exit fullscreen mode

Reading the result

The new model handles dates and formats as before but stopped asking for confirmation before sending an invoice. On a benchmark that would barely register. For a business agent it is the most important behaviour in the set, which is why the gate compares behaviours rather than scores

The second line shows the other hard rule: no switch until the backup has been restored at least once. A backup nobody has restored is a hope, not a backup

Design notes

Build the task set from real work. About ten tasks the old model definitely handled, including rare ones that run weekly and cautious ones where the agent must stop and ask. For each, record what it was given, what it should do and how to tell it did

Back up the whole agent. Instructions, memory, code, data and connection settings, not just the model setting. Otherwise a rollback leaves part of the system in the new state

Switch one agent at a time. Different roles can end up on different models, and that is a normal design rather than a compromise

Read the provider's notes on what changed between versions before you run anything

Errors and trade-offs

Stubs hide variability. Real models do not return the same behaviour every run. Run each task a few times and treat any lost behaviour as a regression worth a look

A rollback restores the system, not the world. Messages sent or records created in external services during a bad run must be fixed separately, which is why the test runs with real sends off

Skipping an update is a valid outcome. If the agent works and the new model solves no specific problem, waiting is cheaper than any test

Checking work on several screens

How to reproduce the check

  1. Save the example as upgrade.py
  2. Run python3 upgrade.py with Python 3.10 or newer
  3. Compare the output with the block above
  4. Make run_new ask for confirmation on the invoice task and confirm the first decision changes to switching one agent

For the step-by-step business version, see updating an AI agent model without breaking things

Top comments (0)