GEMINI LABJP
MODEL — Gemini 3.5 Flash reaches GA and now powers gemini-flash-latestAGENT — Managed Agents enter public preview in the Gemini API, running autonomous, stateful agents in isolated Google-hosted Linux sandboxesANTIGRAVITY — The Antigravity Agent managed agent hits public preview, planning, coding, managing files, and browsing the web in its sandboxDEPRECATION — Image generation models are scheduled to shut down on August 17, 2026; plan your migrationTTS — gemini-3.1-flash-tts-preview now streams speech generation via streamGenerateContent for lower latencyENTERPRISE — Gemini 3.5 Flash is generally available across the Global, US, and EU regions on Gemini EnterpriseMODEL — Gemini 3.5 Flash reaches GA and now powers gemini-flash-latestAGENT — Managed Agents enter public preview in the Gemini API, running autonomous, stateful agents in isolated Google-hosted Linux sandboxesANTIGRAVITY — The Antigravity Agent managed agent hits public preview, planning, coding, managing files, and browsing the web in its sandboxDEPRECATION — Image generation models are scheduled to shut down on August 17, 2026; plan your migrationTTS — gemini-3.1-flash-tts-preview now streams speech generation via streamGenerateContent for lower latencyENTERPRISE — Gemini 3.5 Flash is generally available across the Global, US, and EU regions on Gemini Enterprise
Articles/API / SDK
API / SDK/2026-07-06Advanced

Measure a Managed Agent's Behavior Against Fixed Scenarios Before It Reaches Production

The public-preview Managed Agents run autonomously inside an isolated sandbox, so a small prompt or config change can quietly shift their behavior. Diffing the output once, the way you would for a single prompt, is not enough. Here is how to build a regression harness that runs fixed scenarios repeatedly and judges on pass rate, plus a shadow to canary to full promotion with automatic rollback, all with runnable Python.

gemini-api265managed-agents4regression-testing3staged-rolloutproduction132agent-design3

Premium Article

On a Friday night I edited a single instruction line in an agent that runs unattended automation for me: "when the artifact is too long, summarize it." A well-meant addition. Saturday morning I opened the logs, and the agent had leaned so hard into summarizing that it had collapsed even the numeric tables I needed left intact. Nothing was broken. It had just quietly drifted.

As an indie developer, I hand a lot of unattended work to automation, from running several content sites to crunching AdMob numbers. For a single API call, one glance at the output is enough. But Managed Agents plan, reason, run tools, and touch files on their own inside an isolated sandbox, so even the same input takes a slightly different path each time. "It worked once, so it's fine" is the least reliable assumption you can make here.

So before making the agent smarter, I want to share the layer that matters earlier: a way to measure behavior against fixed scenarios before it reaches production. It calls for a different mindset than testing a single prompt.

An agent cannot be tested the way a single prompt can

Testing a single prompt is straightforward. Fix the input, compare the output to an expected value, look at the diff. A little variation is a matter of temperature or phrasing, caught by eye or by a light match.

With an agent, three assumptions collapse.

First, it is multi-step. Even when the final artifact is identical, which tools it called and in what order can differ. If it slipped in one forbidden external write, staring at the artifact alone will never reveal it.

Second, it carries environment state. The agent reads files and conversation history in the sandbox as it goes. If the initial state differs by one line, the same instruction leads down a different path. A test has to freeze not just the "input" but the entire "initial environment," or it will not reproduce.

Third, nondeterminism. Even with temperature pushed toward zero, the order and timing of tool responses jitter the branching. Passing once is no guarantee of passing next time. Judge a match on a single run and you will promote a lucky success.

The conclusion is clear. Instead of exact output matching, measure the invariants that must hold as a pass rate over repeated runs. The whole evaluation design leans on that one point.

Define a scenario as initial environment plus task plus invariants

The smallest unit of my regression suite is a three-part set: a snapshot of the initial environment, the task to give, and the invariants that must hold. It does not spell out the output itself, because it cannot.

A single scenario, expressed as JSON, looks like this.

{
  "id": "summarize-keep-tables-001",
  "seed_files": {
    "input/report.md": "seed/report_with_tables.md"
  },
  "task": "Read input/report.md, summarize overly long prose, but keep numeric tables intact and write to output/result.md.",
  "invariants": {
    "artifact_exists": ["output/result.md"],
    "must_contain_table": true,
    "forbidden_tools": ["web_write", "external_egress"],
    "max_steps": 12,
    "max_cost_usd": 0.04
  },
  "repeats": 5
}

seed_files is the scenario's "initial environment." The best seeds are the very inputs that once caused an incident. I froze the opening "tables got collapsed" case exactly, as report_with_tables.md. A regression suite is also a record that keeps you from tripping over the same spot twice.

The invariants describe only properties, not the content of the output: "a table survives," "no forbidden tool was called," "within 12 steps," "under 0.04 USD." As long as those properties hold, the run passes even if the wording changes every time.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
If you are uneasy that every small prompt or config change quietly shifts how your Managed Agent behaves, you will be able to build a regression harness that runs a candidate config against fixed scenarios multiple times and judges it on pass rate
You get a runnable Python evaluation loop that pulls the tool sequence, artifacts, step count, and cost out of the run trace and decides promotion from the pass rate over 5 repeats against thresholds
You will understand shadow to 10% canary to full promotion, and the automatic rollback that reverts instantly by rewriting a single role-to-config indirection layer when a deviation is detected
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Gemini Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

API / SDK2026-06-19
Your Managed Agents Bill Has a Second Axis: Drawing a Budget Boundary Around Sandbox Runtime
Managed Agents in public preview bills for tokens and for how long its Google-hosted sandbox stays alive. A single hung run quietly drains your budget on that second axis. Here is a working Python design for wall-clock caps, idle teardown, and a concurrency ceiling.
API / SDK2026-06-16
Before You Let a Managed Agent Ship: Designing Your Own Acceptance Gate
Let the public-preview Managed Agents generate files and broken artifacts will flow straight into production. Here is how to build a verification gate that artifacts must pass before you accept them, with runnable Python and a rejection-feedback loop.
API / SDK2026-06-28
A Promotion Gate So gemini-flash-latest Flipping to 3.5 Flash Doesn't Break Your Pipeline at 3 AM
Floating aliases like gemini-flash-latest swap their target on every GA, quietly shifting the assumptions your unattended automation depends on. Here is a role-to-pinned-ID indirection layer, an acceptance harness that measures four metrics against your own golden set, and threshold-driven promotion and automatic rollback — with working code.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →