Foredeck
DocsOpen ForedeckRequest access
  1. Foredeck
  2. Software factory guide
  3. Feature flags for AI agents

Guide · Published November 20, 2026

Feature flags for AI agents

Feature flags for AI agents put a runtime switch between a change an agent merged and the people who use your product. The code deploys turned off, a person decides when customers see it, and anyone, agent or person, can turn it off again without a deploy. The merge gate decides whether code is acceptable. The flag decides who gets it, and lets you take it back.

On this page

  1. Why the merge isn't enough
  2. Progressive rollout
  3. Kill switches
  4. Stopping on evidence
  5. Agents and the control plane
  6. Flag hygiene
  7. Rollouts as experiments
  8. Light and dark factories
  9. Where Foredeck fits
  10. FAQ

Why agent-written changes need control past the merge

Tests, review and merge policy answer one question before anyone uses a change: does this look right? They can't say what it does with real traffic, data and load. Coding agents make that gap matter more, for two reasons.

The first is volume: a software factory run by agents ships more changes a day, so more of them reach production with something no check caught. The second is context: when people sit on the loop rather than in it, nobody read every diff, so nobody remembers which change might have broken production.

A feature flag answers both by separating deploy from release. Google's SRE workbook puts it plainly: flag and experiment frameworks “allow you to separate feature launches from binary releases” ( Google SRE Workbook). The agent's code merges and deploys on green, and exposing it to users becomes a second decision that can be made, reversed and recorded on its own.

It also gives each change its own undo, though not a quality gate: by the time you turn a flag off, someone has seen the change. Quality is built in before the merge. The flag contains a bad change; it doesn't excuse one.

Progressive rollout by percentage

Pete Hodgson's article on feature toggles splits them into release, experiment, ops and permissioning toggles. Most agent-written changes need a release toggle, which he describes as “transitionary by nature”: it exists to get one change out safely, and then it goes.

The usual path is a ladder: your own team first, then a few named customers who agreed to see early work, then a small percentage, a larger one, and everyone. A percentage step hashes each user's id into a bucket from 0 to 99 and serves the change to buckets below the number. Hashing makes it deterministic: the same user gets the same answer on every request and every server, and raising the percentage only adds users, so nobody who had the change at 5% loses it at 25%.

In Foredeck, a Feature can ship behind its own Flag, named after it (feature.f-12 for F-12). The Flag is on in development and staging and off in production, and it moves through fixed steps: off, your internal cohort, named accounts, 5%, 25% and 100%. The bucketing follows a published evaluation spec, so the server and SDKs agree on who is in.

Hold each step until enough users have hit the new path to show a problem. A change that sits at 0% for a month hasn't been tested by anyone, so don't count it as a success. Foredeck starts a Change's survival window only when its Flag reaches the rollout you meant to reach, and marks it unobserved if it never gets there.

Kill switches for AI code

A kill switch is the flag you hope never to use. It comes in two sizes. The small one is the release flag itself: off sends every user back to the old code path, so that path has to keep working. The large one is long-lived and stops a whole capability; Hodgson calls these “Kill Switches” that let operators degrade non-vital features. In an agent factory, that includes a switch that stops a whole pipeline of agent work.

A few rules make kill switches work under pressure.

  • Off is never refused. Anyone, agent or person, can turn a change off in production at any time. Containing damage shouldn't wait for an approval.
  • Know which way it fails. If the flag service can't be reached, a release flag should fall back to the old path. A switch that keeps something running defaults the other way.
  • Don't clean them up by accident. In Foredeck, a Flag of kind kill switch is never archived or reported as stale, because an SDK reads a missing kill switch as on, and archiving one would restart what it stopped.

Stopping on evidence

A flag is only as useful as the signal to turn it off. “Checkout is slow” is a start. “Checkout is slow for users on one flag's new variation, right after one deploy” tells you which switch to flip.

That's attribution: the alert joined to the release and to the Change, meaning the pull request and the agent run behind it. In Foredeck, a monitor's alert names the Flag variation a breach is concentrated in and the deploy it followed, when it can tell. A critical alert attributed to a Change marks it regressed. Turning its Flag off in production marks it turned off, which isn't a rollback: it can be fixed and turned on again.

Attribution has to admit what it doesn't know. When one deploy carried several Changes, Foredeck doesn't guess which one failed: the failure is unassigned until a person says which. Once a failure belongs to one Change, a fix is filed and a person decides whether to fix it, drop it or rethink the approach. The next agent working in that repository sees the failure in its briefing.

Some tools flip the flag automatically on a guardrail breach. LaunchDarkly's Release Autopilot, for example, ramps changes while watching error rates and latency, and returns a change to its last good state on a breach (SD Times). Whether a machine or a person turns it off, the record should say which change it was.

Agents read rollout state and permissions from a control plane

An agent shouldn't keep rollout state in its context window or in the repo. It should read it from a control plane that holds what's on, at what percentage, in which environment, and who may change it, using a credential that says who it is.

The useful properties:

  • Permissions follow the credential. In Foredeck, an agent is any API key. In production it may turn a Feature's Flag off or on for your internal cohort, and nothing more: a step that would reach customers gets a 403 that says a person is required (who can ramp production). Agents keep full control of development and staging.
  • Keys are bound to an environment. A key reads one environment, so a staging deploy gets staging's flag state by using a staging key, and an agent testing in staging can't change production by mistake.
  • Every change is audited. Each Flag write records an event saying whether an agent or a person made it.
  • Stopping is cooperative where agents run on your machines. The factory reads kill-switch state and stops. Foredeck can ask a fleet to drain or stop, and the fleet on your machine obeys on its next heartbeat. Nothing reaches into the machine, and it's better to say so than to pretend otherwise.

Flags are also a standard interface. OpenFeature, a Cloud Native Computing Foundation incubating project, describes itself as “a vendor-agnostic, community-driven API for feature flagging” (OpenFeature). Behind a standard API, the vendor can change without touching every gate. Foredeck has an OpenFeature provider, though it isn't on npm yet.

Flag hygiene when agents create many flags

One flag per change means a factory makes flags faster than any team used to. Hodgson's warning applies with more force: “Savvy teams view their Feature Toggles as inventory which comes with a carrying cost.” A flag left in the code is an old path that still runs if someone flips it.

The worst case is on record. In 2012, Knight Capital deployed new trading code that “repurposed a flag that was formerly used to activate the Power Peg code,” a function it had stopped using years before. One of eight servers missed the new code, so orders with that flag ran the old code. In about 45 minutes Knight sent millions of orders and lost more than $460 million (SEC order; SEC press release).

Practices that keep agent-made flags from piling up:

  • Name each flag after its work, and never reuse a key. In Foredeck an archived Flag keeps its key, so creating another with the same key is refused.
  • Say what kind of flag it is. A temporary release flag, an experiment and a permanent kill switch need different cleanup rules.
  • Make cleanup a piece of work, not a good intention. Hodgson lists teams that add a removal task to the backlog, set expiry dates, or cap how many flags exist at once. Foredeck files a cleanup Feature 14 days after a Feature's Flag is fully on in production, which removes the gate and the old path, and archives the Flag once that cleanup is live.
  • Report what looks forgotten. Foredeck's stale report lists flags that have been off for 30 days, so nobody gets them, or temporary flags at 100% for 14 days, so everybody does.

Turning a rollout into an experiment

A percentage rollout already splits users at random. Attach a metric, such as checkout completions per user, and the same split becomes an experiment: compare the users who got the change with the ones who didn't. Without a metric, it's only a rollout.

Two details decide whether the comparison means anything.

  • Only randomly assigned users count. Your own team and named accounts got the change because you chose them, so they stay out of the readout. In Foredeck, only users placed by the split record an exposure, and counted events count only after a user's first exposure.
  • Report the sample size and the uncertainty. A 5% step on a quiet feature may not have enough users to show anything, and the readout should say so.

The same mechanism works on the factory itself: read the prompt version or model from a flag, split agent runs between two, and compare how their changes did in production. The factory scorecard compares agents, models and prompts on survival and cost per surviving change.

Light and dark factories

Dan Shapiro put the “dark factory” at the top of his five levels of AI coding: a place “where humans are neither needed nor welcome.” StrongDM's AI team runs one under two rules: “Code must not be written by humans” and “Code must not be reviewed by humans” (StrongDM).

In a dark factory, flags are the last brake: every ramp and every off switch is automated, and the guardrails have to be right the first time.

A light factory keeps a person at the helm. Agents write the change, deploy it turned off and can always turn it off. A person decides when customers see it, using what the change did in development, staging and your own org. That's one decision per change, not a person reading every diff.

The line between the two shouldn't be fixed. Autonomy is earned from the production record: when an agent, model or prompt keeps shipping changes that survive, it can be trusted with more of its own rollout. When its changes start getting turned off, it gets less. You can only make that call if every flag flip is tied back to the change and the run that made it. The software factory guide covers the rest of the line.

Where Foredeck fits

Foredeck is the stats and control plane for your software factory. Each pull request becomes a Change, tied to the agent run, prompt and model that made it. A Feature can ship behind its own Flag: merged off in production, ramped a step at a time by a person, turned off by anyone, and cleaned up when it's done. When something breaks, the alert, the deploy and the Flag point back to the Change, and the next agent hears about it. It's a light factory, with you at the helm.

Request accessRead the Flags docs →

Feature flags for AI agents: FAQ

What is a kill switch for AI code?

A feature flag that turns a change, or a whole pipeline, off in production without a deploy. Anyone, agent or person, should be able to flip it off at any time; turning it back on for customers is a person's decision.

Does every agent-written change need its own feature flag?

No. Docs, tests and small fixes can ship directly. Put a flag on changes risky enough to release a step at a time, such as new behavior users will notice or changes to money or data paths. One flag per change keeps the off switch scoped to that change.

Should an AI agent be allowed to turn a feature flag on?

In development and staging, yes. In production, a common split is that an agent may turn a flag off or show it to your own team, and only a person takes it to customers. As an agent, model or prompt builds a record of changes that survive in production, you can widen what it's allowed to ramp on its own.

How is turning off a feature flag different from a rollback?

A rollback redeploys an earlier version, and takes every change shipped since then out with it. Turning off a flag stops one change, in seconds, with nothing redeployed. Both contain a bad change after users have seen it. Neither replaces tests and review before the merge.

When does a feature flag become an experiment?

When it has a random split and a metric attached. A percentage rollout already assigns users at random by hashing their id, so a metric lets you compare the users who got the change with those who didn't.

© 2026 ForedeckBuilt for light factories, with people at the helm.HomeDocsinfo@foredeck.ai