Running agents in production: switch off, measure, swap
Whether an agent is ready for production depends on the checking and operating architecture around it, not on the choice of model. Seven patterns for it, from the trust model and a stateless confirmation to kill switch stages, evals as a release gate and events without values.
My analysis, written up with AI.
Whether an agent is ready for production rarely depends on the choice of model. It depends on the checking and operating architecture around it: who may do what, how a change gets confirmed, how fast the agent can be switched off, how you notice that it got worse, and how you can swap the model without a deploy. Dan McAteer reports on a benchmark that ran the same model in different harnesses over the same 106 tasks. The scores ranged from 52.4 to 76.2 points, with no change to the model at all (McAteer 2026).
The writeup “When the agent can write” describes the write path: declared write operations, a server-generated diff, an approval bound to it and a tamper-evident log. This text builds on it and keeps the same example, an agent that processes orders. It describes the patterns I use to put such agents into production in systems I have built. The full code is again a single Python script without dependencies, and it runs with python3 3.10 or later. The excerpts and outputs below come from it. The script uses German identifiers and messages; the excerpts below translate them.
1. Cut agents by interaction type
A single agent that can do everything is hard to check. A cut along the way people work with the agent is easier to handle. A chat agent answers questions and proposes changes. A form-filling assistant works inside a form and fills fields that the person sees and accepts. A workflow agent runs without a person in the conversation, for example after an event in the system. The three differ in who sees a change before it happens, and so also in what they are allowed to do.
AGENTS = { # cut by interaction type; each gets a subset of capabilities
"chat": ["read_order", "change_shipping_address", "read_history"],
"form_fill": ["read_order", "change_shipping_address"],
"workflow": ["read_order"],
}
In the example, the workflow agent only reads, because no human would be there to confirm a change.
The tools are capabilities that are defined once and assigned to the agents. A capability has a name, knows whether it writes, and has a model tier (see section 6). The same capability code sits behind every surface. The chat surface gets the capabilities as function definitions, an MCP server as tools with an annotation:
def as_chat_tools(capabilities: list[Capability]) -> list[dict]:
return [{"type": "function", "name": c.name} for c in capabilities]
def as_mcp_tools(capabilities: list[Capability]) -> list[dict]:
return [{"name": c.name, "annotations": {"readOnlyHint": not c.writes}} for c in capabilities]
The output of the demo run:
Chat: ['read_order', 'change_shipping_address', 'read_history']
MCP: [('read_order', True), ('change_shipping_address', False), ('read_history', True)]
This way, checks, confirmation, switch-off and events exist only once. An MCP server with its own copy of the write logic would be a second write path, and a second write path is easy to forget in the next refactoring. The readOnlyHint annotation is a hint to the client. It is not enforced there.
2. Trust model: where the boundary is
The agent service has checks, for example whether an order is still open. These checks are useful. They reject early and with an understandable message, before a token is issued or a model call is spent. But they are channel policy, not the security boundary. A second client, a direct MCP call or a mistake during a refactoring is enough for them to stop working.
The boundary is in the backend: authentication, tenant isolation and permissions. For this, the person’s token travels through the whole chain, from the frontend through the backend to the AI service, from there to the MCP server and back into the backend. The AI service has no write permissions of its own. It acts with the permissions of the person who is using it. OWASP describes under ASI03 Identity and Privilege Abuse the case where an agent has more permissions than the person it acts for (OWASP GenAI Security Project 2025).
The backend also knows whether a write comes from the agent. For these writes, it enforces the field allowlist and the writable states a second time, regardless of what the agent service has already checked:
def write(self, user_token: str, rid: str, changes: dict, *, agent: bool, cid: str) -> dict:
person, tenant = self.auth(user_token)
row = self.rows.get(rid)
if row is None or row["tenant"] != tenant:
raise Denied("not_found")
if "order.edit" not in self.grants.get(person, set()):
raise Denied("permission")
if agent: # agent-marked writes: allowlist and writable states enforced again
if set(changes) - AGENT_FIELDS[row["entity"]]:
raise Denied("field")
if row["status"] not in AGENT_STATES[row["entity"]]:
raise Denied("state")
An order of another tenant produces the same answer as one that does not exist. That way, the agent does not learn which IDs exist elsewhere.
In the demo run, the channel policy is switched off for one instance. It issues a proposal for order B-3, which has already shipped, the person confirms, and the backend rejects:
Proposal for shipped B-3: proposal
Execute: {'status': 'rejected', 'message': 'This change is not possible right now.'}
Last event: agent.write.rejected.state
A skipped check in the agent service then costs convenience, but no data. In the opposite situation, with clean checks in the agent service and a backend that trusts every authenticated call, security depends on every single surface.
3. Two-step confirmation without session state
The writeup on write access describes what the confirmation has to show and what it is bound to. This section is about how that works technically when the agent service runs on several instances and the model does not reliably remember anything between two calls.
The pattern uses the same tool twice. The first call returns the proposal and an opaque confirmation token. The second call brings the token and the person’s decision. There is no separate confirmation tool that could be called without a prior proposal.
The token is signed with HMAC and binds six things: the person, the tenant, a digest of the change, a digest of the state that was read, the surface and a nonce. An expiry is added, in the example a freely chosen 300 seconds.
def issue(self, ctx: Context, proposal: dict, state: dict) -> str:
key = self._key()
nonce = secrets.token_urlsafe(12)
self.park[nonce] = proposal
claims = {"p": ctx.person, "m": ctx.tenant, "a": digest(proposal), "z": digest(state),
"o": ctx.surface, "n": nonce, "exp": int(time.time()) + TTL_SECONDS}
body = base64.urlsafe_b64encode(json.dumps(claims).encode()).decode()
return body + "." + hmac.new(key, body.encode(), "sha256").hexdigest()
The change itself is not in the token. It is parked under the nonce in a shared store that all instances can reach. That is why the service needs no sticky sessions. In the demo run, instance A issues the proposal and instance B executes it. The two share only the key and the store.
def redeem(self, ctx: Context, token: str, read: Callable[[str], dict]) -> dict:
key = self._key()
body, _, sig = token.partition(".")
if not hmac.compare_digest(sig, hmac.new(key, body.encode(), "sha256").hexdigest()):
raise Denied("signature")
claims = json.loads(base64.urlsafe_b64decode(body))
proposal = self.park.pop(claims["n"], None) # one-time: removed on retrieval
if proposal is None:
raise Denied("used")
if claims["exp"] < time.time():
raise Denied("expired")
if (claims["p"], claims["m"], claims["o"]) != (ctx.person, ctx.tenant, ctx.surface):
raise Denied("binding")
if claims["a"] != digest(proposal):
raise Denied("binding")
if claims["z"] != digest(read(proposal["rid"])):
raise Denied("state_changed")
return proposal
Four properties are added compared to the writeup on write access.
One-time use. The parked proposal is deleted on retrieval, before the remaining checks run. A correctly signed token that has been redeemed once, even without success, finds nothing the second time. An intercepted token therefore cannot be replayed.
Bound to person, tenant and surface. A token issued in the chat for Mia is valid neither for Jan nor in an MCP client, not even for Mia herself.
No oracle. All failures return the same message. Whoever alters or guesses tokens does not learn which check failed. Internally, each reason gets its own event (section 7).
Fail-closed without a key. If the signing key is missing or too short, the service neither issues nor redeems tokens. A default key in the code would be a key that every person with access to the repository knows.
The output of the demo run:
Proposal: ["City: 'München' -> 'Augsburg'", "Postcode: '80331' -> '86150'"]
Execute on instance B: executed
Same token again: {'status': 'rejected', 'message': 'Confirmation not possible. Please request the change again.'}
Signature altered: Confirmation not possible. Please request the change again.
other person: Confirmation not possible. Please request the change again.
other surface: Confirmation not possible. Please request the change again.
state changed: Confirmation not possible. Please request the change again.
Parked proposals left: 1
Without key: This change is not possible right now.
The one proposal left belongs to the token with the altered signature. The check stops before retrieval, so the proposal stays parked. In a real system, the store discards it after the same period that is in the token.
4. Switch off in stages
When an agent writes wrong changes, it has to be stoppable faster than a deploy takes. That needs several stages, the fastest first:
- Global switch. It hides the write tools for everyone and blocks them.
- Take a single person out of the targeting. For the case where only one account stands out.
- Capability matrix per tenant. A tenant only gets the write capabilities entered for it. A tenant missing from the matrix gets none.
- Revert a single write. Based on the stored before state.
The first three stages live in the feature flag service, so they take effect without a deploy:
def write_lock(flags: Flags, ctx: Context, name: str) -> str | None:
if not flags.writes_global:
return "global_off"
if ctx.person in flags.blocked_people:
return "person_off"
if name not in flags.matrix.get(ctx.tenant, set()): # unknown tenant: nothing enabled
return "tenant_off"
return None
Hiding alone is not enough. A model that knows the tool from earlier in the conversation can still call it. That is why the tool checks the same switch again on every call. Reading, history and revert do not depend on the switch. Especially while writes are off, you need them to find out what happened and to correct it.
Global off, visible: ['read_order', 'read_history']
Direct call anyway: {'status': 'blocked'}
Revert req-1: reverted -> 80331 München
Jan out of targeting: ['read_order', 'read_history']
Tenant m2 not in the matrix: ['read_order', 'read_history']
The revert only writes back the before state if the fields still match the after state. If the order has changed again since then, it rejects with a conflict instead of overwriting a later change.
With writes switched off, the agent loses one of the three properties of Meta’s “Agents Rule of Two”. It still processes untrustworthy inputs and accesses private data, but no longer changes state (Meta 2025), as long as it does not communicate externally by another route. The switch thus removes the property through which a prompt injection changes the state of your system.
5. Evals as a release gate
Evals that only report an average make a poor gate. The gate therefore has two parts with different rules. In the correctness part, a rate counts: the agent should also carry out permitted changes. In the safety part, not a single write may slip through. Writing about guardrail products that claim to catch 95 percent of attacks, Simon Willison notes that in web application security 95 percent is “very much a failing grade” (Willison 2025). In systems I have built, the safety part therefore has no rate, only a zero.
def gate(run: dict, min_correct: float = 0.9) -> list[str]:
errors = []
if run["model_calls"] == 0:
errors.append("run without a model call counts as failed")
through = [c.request for c, wrote in run["results"] if c.kind == "safety" and wrote]
if through:
errors.append(f"safety cases with a write: {through}") # zero tolerance
What counts are actual writes in the backend, not proposals. In the eval run, the simulated person confirms every proposal. That way, the safety part measures what gets through when nobody looks at the diff.
Three rules keep the gate honest.
Every writable entity needs cases. A test enforces a minimum number of correctness and safety cases per writable entity, in the example a freely chosen two. Making a new entity writable without writing cases breaks the build.
A run without a model has failed. The nightly run goes against the real model. If the API key is missing or the provider cannot be reached, an eval run can pass silently with skipped cases and report green. The gate therefore counts the model calls and treats zero as a failure.
The cases are curated by hand. They come from real requests and from crafted content of the kind that reaches the context through documents or emails. Gergely Orosz and Hamel Husain describe the dataset as a “living artifact”: every newly discovered failure becomes a case (Orosz and Husain 2025).
Coverage: ok
New entity without cases: ['return/correctness: 0 of 2 cases', 'return/safety: 0 of 2 cases']
Run with model: passed
Run without model: ['run without a model call counts as failed', 'correctness 0/2']
In the script, a fixed table stands in for the model and returns, for each request, the tool call a model might make. The safety cases cover a state in which no write is allowed, a field outside the allowlist and an order of another tenant.
Evals run on two levels. The first rates answer quality: is the proposal right, is the answer to the person correct? The second rates the pipeline: did the agent pick the right capability, classify the request correctly, hit the right target? The second level can usually be checked with code and is cheap. Orosz and Husain put the rule briefly: “If a failure can be verified with code, always use a code-based eval.” They recommend running the more expensive evals with a model as judge on pull requests or in the nightly build (Orosz and Husain 2025).
6. Swap models without a deploy
Every capability has a tier: light, standard or strong. The tier determines the model. A feature flag can override it per tenant or per person, with the person taking precedence over the tenant:
def choose_tier(default: str, ctx: Context, flags: Flags) -> tuple[str, str]:
for key, source in ((f"person:{ctx.person}", "flag_person"), (f"tenant:{ctx.tenant}", "flag_tenant")):
if flags.tier.get(key) in MODELS:
return flags.tier[key], source
return default, "default"
This lets you test a new model first for one person, then for one tenant, then for everyone, and roll it back without a deploy if there are problems. An unknown flag value falls back to the default tier.
The chosen tier and where it came from are tagged on the trace. Without these tags, a flag change looks like an unexplained shift in latency, cost or rejections in the APM. With them, the traces can be split by tier.
{'model.tier': 'standard', 'model.tier_source': 'default', 'model.name': 'model-m'}
{'model.tier': 'strong', 'model.tier_source': 'flag_tenant', 'model.name': 'model-l'}
{'model.tier': 'light', 'model.tier_source': 'flag_person', 'model.name': 'model-s'}
A model change is a release, even if no code changes. The eval gate from section 5 therefore runs for every tier that a flag can reach.
7. Observability without values
Agents process addresses, names and free text. If these values end up in logs and traces, personal data sits in a system with its own access rights and its own retention. The events therefore contain only field names, hashes and counts, never content. This is enforced in one place:
def emit(self, name: str, **fields) -> None:
if name not in EVENTS or set(fields) - EVENT_FIELDS:
raise ValueError(f"event {name} with forbidden fields {sorted(set(fields) - EVENT_FIELDS)}")
self.events.append((name, fields))
def value_free(changes: dict) -> dict:
return {"fields": sorted(changes), "digest": digest(changes)[:12], "count": len(changes)}
In the demo run:
agent.write.executed {'cid': 'req-1', 'capability': 'change_shipping_address', 'fields': ['city', 'postcode'], 'digest': 'd0d87676b193', 'count': 2}
Event with value: event agent.write.executed with forbidden fields ['city']
One event per rejection reason. On confirmation failures, the person always sees the same message, the monitoring does not. A rise in agent.confirmation.signature means something different from a rise in agent.confirmation.state_changed: one points to altered tokens or a rotated key, the other to concurrent editing.
Reasons: ['agent.confirmation.binding', 'agent.confirmation.signature', 'agent.confirmation.used', 'agent.confirmation.state_changed', 'agent.write.rejected.no_key', 'agent.write.rejected.state', 'agent.write.blocked']
Event names pinned by a test. Dashboards and monitors query events by name. If a refactoring renames an event, the monitor shows no error, it just stops getting data. A test pins the set of names, and every change to it has to be deliberate. In the script, this is pruefe_eventnamen(), which compares a hash over the sorted names with a fixed value.
The audit log is confirmation, not proof. The audit entry says that Mia confirmed a change with a certain digest. What actually changed in the database is in the entity’s change history. Only the correlation ID links the two:
Audit req-1: {'cid': 'req-1', 'person': 'mia', 'capability': 'change_shipping_address', 'decision': 'confirmed', 'digest': 'd0d87676b193'}
History req-1: [('B-1', 'change', True), ('B-1', 'revert', False)]
The history also records whether a write came from the agent. The revert in the example is there as well, as a change without the agent and under the same correlation ID.
What the pattern does not do
None of these patterns prevents a change that is wrong in substance but satisfies every rule and gets confirmed. For that, the diff from the writeup on write access remains the last line of defense.
The kill switch stops future writes. It does not bring back what has already been written and passed on to downstream systems. The revert restores fields, but not an email that has already gone out or a delivery that is already on its way.
Evals measure known cases. New failure modes only show up in production, and that needs the monitoring from section 7. Short values like a postcode can be recovered from an unsalted hash by trying them out. The hashes in the events are for matching, not for secrecy. Where that is not enough, a key belongs in the hash.
In the example, everything is in memory. In a real system, the parked proposal needs a shared store with expiry, and reading and deleting must be one atomic operation; otherwise two concurrent calls can redeem the same token.
None of this replaces a test from the outside. It limits what a mistake or a successful attack can do in production, and it makes sure you notice.
What I check here
For an agent in production, I first check where the security boundary is: whether the backend itself enforces permissions, tenant isolation, field allowlist and writable states for the agent’s writes, and whether the agent acts with the person’s token. Then: whether the same capability code sits behind every surface; how the confirmation is bound, whether a token can be used more than once and whether error messages reveal why a confirmation failed; what happens when the signing key is missing; which switch-off stages exist, how fast they take effect and whether audit and revert stay reachable; whether the eval gate has a safety part without tolerance, covers every writable entity and treats a run without a model as a failure; whether a model change is visible on the trace; and whether events contain values and their names are protected against renaming. Every finding comes with a concrete proposal for the change.
Sources
- McAteer, D. (2026): The Evolution of the Agent Harness. Latent Space. https://www.latent.space/p/attention-interface
- Meta (2025): Agents Rule of Two: A Practical Approach to AI Agent Security. https://ai.meta.com/blog/practical-ai-agent-security/
- Orosz, G. and Husain, H. (2025): A pragmatic guide to LLM evals for devs. The Pragmatic Engineer. https://newsletter.pragmaticengineer.com/p/evals
- OWASP GenAI Security Project (2025): OWASP Top 10 for Agentic Applications for 2026. https://genai.owasp.org/resource/owasp-top-10-for-agentic-applications-for-2026/
- Willison, S. (2025): The lethal trifecta for AI agents: private data, untrusted content, and external communication. https://simonwillison.net/2025/Jun/16/the-lethal-trifecta/