◉GEMINI LABJP
●ARGON — gemini-4-argon is generally available as of 10/13, aimed at complex coding, agents, math and science●DEEP RES — deep-research-pro-preview-12-2025 shuts down 10/23, 6 days left. Move to deep-research-preview-04-2026●NANO — gemini-nano-banana-2.1 is GA (10/06). gemini-3.1-flash-image is deprecated with no shutdown date yet●MCP — One write-up cut an 85,000-token tool result to 310 tokens by wrapping it in an ADK FunctionTool●FLASH — gemini-3.7-flash and 3.5-flash now route automatically to newer Flash models (10/08)●NEW — Stop Re-Reading Every Crash Report: Gre…●ARGON — gemini-4-argon is generally available as of 10/13, aimed at complex coding, agents, math and science●DEEP RES — deep-research-pro-preview-12-2025 shuts down 10/23, 6 days left. Move to deep-research-preview-04-2026●NANO — gemini-nano-banana-2.1 is GA (10/06). gemini-3.1-flash-image is deprecated with no shutdown date yet●MCP — One write-up cut an 85,000-token tool result to 310 tokens by wrapping it in an ADK FunctionTool●FLASH — gemini-3.7-flash and 3.5-flash now route automatically to newer Flash models (10/08)●NEW — Stop Re-Reading Every Crash Report: Gre…
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-api286managed-agents4regression-testing3staged-rolloutproduction140agent-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-07-15
Sample what you already accepted — an audit budget that catches silent quality drift
A confidence gate only ever looks at output the model hesitated on. Silent drift sinks into the batch that sailed through. Working from a fixed 30-minutes-a-day review budget, this walks through deriving detection time from the binomial, reallocating the same budget across risk strata, and catching slow decay with a cumulative monitor.
◈ API / SDK2026-07-04
When Gemini API Leaks Japanese Into Your English Output Once in a While — Field Notes on Measuring the Contamination Rate and Tightening It in Stages
You told Gemini to answer in English, and 3 out of 100 runs slip a Japanese sentence into the tail. Here is why you cannot stop that 'once in a while', and a production pattern that measures the contamination rate as an SLO and tightens it with graded recovery, with working code.
◈ API / SDK2026-05-20
Evolving Gemini API Structured Output Schemas in Production — Design Notes from an Indie App
How I rebuilt the JSON contract layer for a Gemini-powered recommendation feature in a long-running indie app — Dual-Emit, Sunset protocol, and a Python compatibility checker.