Continuous State Anchoring
Surface live post-conditions and ambient state continuously, so the agent never reconstructs reality from stale history.
Friday, 4:40 p.m. A deployment agent gets a routine task: raise the database connection pool for payments-api from 20 to 40 on staging, run the load test, and report the p95 latency. The agent starts well. On turn 2 it calls set_target(env="staging") and gets back {"ok": true}. It runs a baseline load test and reads several long reports.
On turn 9 it has a good idea. Before testing a new value, it wants to know what production actually runs, so the test is realistic. It calls set_target(env="prod-eu"), reads the config, sees pool_size: 20, and goes back to work on the load test. It never switches back.
Twelve turns later, the agent edits pool.yaml and calls apply_config(service="payments-api", file="pool.yaml"). The tool answers {"status": "applied", "revision": "r118"}. The agent restarts the service, which reports {"status": "rolling", "pods": 12}. Staging has two pods. Nobody notices the number.
The untested setting is now live in production. Twelve pods at 40 connections each ask the database for 480 connections, more than it accepts. Checkout starts failing, the on-call engineer gets paged on a Friday evening, and the first question in the incident channel is "why did the staging agent touch prod?"
The agent did not misread anything. Every response it got was accurate. It simply believed it was on staging, because "staging" was the last thing it remembered being true, and no response in the twelve turns since had said otherwise.
Why it happens
A person doing the same job would have had the answer in front of them the whole time. The shell prompt reads (prod-eu) $. Many teams color production terminals red. The IDE status bar shows the branch, and the cloud console shows the account in the top corner. Jakob Nielsen put this first in his list of usability heuristics: visibility of system status. The system keeps telling you where you are, so you never have to remember it.
The agent has no status bar. Everything it knows arrives as one long line of text, oldest first: the task, its own reasoning, every tool call and every response, appended in order. The Guide calls this the 1D temporal ribbonLexicon · 081D Temporal RibbonThe linear token stream through which an agent perceives reality.. Nothing on the ribbon is ever updated in place. A fact changes only when something later on the ribbon says it changed.
So when the agent asks itself "which environment am I in?", nothing answers. It has to reconstruct the answer from history: scan back for the most recent set_target call and trust that nothing since has changed it. That is bookkeeping, and the interface has quietly handed it to the agent.
In this session, the bookkeeping is stacked against it. The word "staging" appears in the task, on turn 2, and in almost every line of the agent's own reasoning ("the staging numbers look fine"). The word "prod-eu" appears once, in a short call on turn 9. Both statements are true, at different times, and nothing on the ribbon marks the first one as superseded. Stale state sitting next to live state, with no way to tell which is current, has a name: temporal vertigoLexicon · 17Temporal VertigoDisorientation from stale past states coexisting beside live state..
Position makes it worse. Models tend to weigh the start and the end of their context most heavily, and attend less reliably to what sits in the middle. The Guide calls this layout of strong and weak zones attention geometryLexicon · 14Attention GeometryPositional layout of information across primacy, middle and recency zones.. The task, with its "on staging", sits at the strong start. The turn-9 switch sinks into the weak middle as more load-test output piles up after it.
The figure below condenses the session from the hook to the four turns that matter, as two transcripts. Under each turn, compare where the agent really was with what it believed. In the top row, the responses say nothing about the target. In the bottom row, every response ends with the current target.
The gap between where the agent was and what it believed is the real failure. The Guide calls the divergence between what the agent believes and what is actually true world-model driftLexicon · 20World-Model DriftDivergence between the agent's internal beliefs and actual environment state.. Drift is silent while the agent is only reading. It turns into damage at the first write, because a write acts on the real world, whatever the agent pictures.
What it costs
Writes that land in the wrong place. The prod-instead-of-staging deploy is the famous version, but the pattern is everywhere: a commit on the wrong branch, a DROP TABLE in the wrong database, a refund from the wrong merchant account, a rm -rf build/ run after a cd the agent forgot about. These are the expensive mistakes, and they usually hit the environment you least wanted touched.
Turns spent re-checking. A careful agent, or one prompted to be careful, learns to distrust its memory. It calls get_current_target() before every action, or runs git branch and pwd every few turns. Each check is a full turn of latency and reasoning for a fact the previous response could have carried for a few tokens.
Supervision that eats the gain. After one production incident, the sensible reaction is to require human approval for every deploy the agent makes, or to give it staging credentials only. Both make sense. Both also remove most of the reason for having a deployment agent.
Incidents nobody can explain at first. Every tool call in the session succeeded. The error dashboards show nothing until the database refuses connections. The post-mortem ends up with an engineer reading 22 turns of trace to find the one line on turn 9 that explains everything.
The fix
In plain words: never make the agent remember state that the system already knows. Every response should carry three things.
- Ambient state. A small, fixed block with the current values of whatever decides where the next action lands: environment, branch, working directory, account, open transaction. It appears on every response, in the same place, with the current values.
- Post-conditions on writes. Every write says what changed, where, from what to what, and what happens next.
- Provenance on data. Any data that depends on state says which state produced it, such as which environment a report was measured on.
Here is the load-test report the agent read on turn 20, its last read before the write, in both forms.
{ "report": "baseline-2", 1 "p95_ms": 182, "errors": 0, "rps": 400 }
- 1The report is accurate and says nothing about where the agent is now. The last statement of the target is eleven turns back, in the middle of the session.
{ "state": { 1 "env": "prod-eu", 2 "env_set_at": "turn 9", "protected": true, 3 "local_changes": ["pool.yaml"] }, "report": "baseline-2", "measured_on": "staging", 4 "p95_ms": 182, "errors": 0, "rps": 400 }
- 1The state block repeats on every response, about 40 tokens each time. It is overwritten each turn, never appended, so it adds no history. The tensions below cover how to keep it small.
- 2The current target, and the turn that set it. Turn 9 is no longer buried in the middle: the fact it established is restated at the newest end of the ribbon.
- 3
protected: truetells the agent the target is a production environment, before it does anything that changes it. - 4The report names the environment it measured. Staging numbers next to a prod-eu target is a contradiction the agent can see and act on.
Pin 1 is the core of the fix, and its shape matters as much as its content. The block is a snapshot: the same keys, the same place, current values. A running log of every state change would put old values back on the ribbon and recreate the temporal vertigo it was meant to cure.
Pins 2 and 3 answer the question the agent was failing to ask. With env: prod-eu on every response since turn 9, the next thought, "apply the staging change," sits a few lines below a value that contradicts it. Pin 4 makes the contradiction explicit: staging numbers, prod-eu target.
The second half of the fix is on writes. Even with the state block in place, the response to a write is the last chance to catch a mistake before it spreads. Here is apply_config reporting its post-conditions:
{
"status": "applied",
"env": "prod-eu",
"revision": "r118",
"changed": { "db.pool_size": { "from": 20, "to": 40 } },
"takes_effect": "on restart of 12 pods"
}
A bare "applied" asks the agent to trust that the write did what it meant. This response says where it went and what it did. An agent that reads "prod-eu" and "12 pods" here has one more turn to stop before the restart.
Where the state block applies
Any tool surface where actions depend on a mode, a location or a session has state worth anchoring. The block can come from each tool, or the harness can attach it to every response from one place. Either way, the agent sees the same fields every turn.
| Surface | State the agent tends to reconstruct | What to anchor |
|---|---|---|
| Deploy or cloud CLI | target environment, account, region | env, account, region, protected |
| Shell | working directory, active virtualenv | cwd, venv, last exit code |
| Git | branch, uncommitted changes | branch, dirty, commits ahead of remote |
| Database | which database, open transaction | database, in_transaction, read_only |
| Browser | current page, signed-in user | url, user, open tabs count |
| Editor or files | open buffers, unsaved edits | open_files, unsaved |
Keep the block to fields that change during a session and change where actions land. The service name the agent was asked to work on doesn't belong there. The branch it is committing to does.
In MCP terms
If your deploy tools live in an MCP server, the protocol won't keep the agent's status bar for you. It gives you a typed slot for the state block and a way to point at live state. The block itself, and the post-conditions on writes, are yours to send.
- Output schema (
outputSchema). Declare thestateobject, withenv,env_set_at,protectedandlocal_changes, in the output schema of every tool,get_load_reportincluded, and list it underrequired. Servers must return structured results that conform to the schema, so the block can't quietly drop off one tool. - Structured content (
structuredContent) and text content (content). Return the state block instructuredContent. The spec asks tools that return structured content to also return the serialized JSON in a text block, for backwards compatibility, so the target shows up at the top of both, for example a first line ofenv=prod-eu protected=true. - Resource links (
resource_link) and update notifications (notifications/resources/updated).apply_configcan link to a resource for the live target, saydeploy://payments-api/prod-eu, that the client can fetch or watch. When the target changes, the server sends an update notification for that URI. - Not in the protocol. Notifications reach the client, not the model, and carry only a URI. No field means "here is the world after your call." So
apply_configitself has to answer withenv,changedandtakes_effect, as in the post-conditions above, and every other response has to restateenv.
Spot it in your traces
Here are six of the session's 22 turns as a trace, renumbered T1 to T6. The prod-eu switch from turn 9 is T2. It was the only moment the agent could have caught the problem, and by the write it was far behind.
- T1
set_target(env="staging")→ { "ok": true }Target set to staging, as the task asks.Correct first move. The confirmation says nothing about the new state, but the call itself is clear. - T2
set_target(env="prod-eu")→ { "ok": true }Check what production runs, so the test value is realistic.A reasonable read, done by switching the global target. Nothing after this turn mentions the switch again. - T3
get_config(service="payments-api", key="db.pool_size")→ { "value": 20 }Production uses 20 too. Back to the staging test.The agent's reasoning says it went back. No call switched the target back. World-model drift starts here. - T4
get_load_report(id="baseline-2")→ { "p95_ms": 182, "errors": 0, "rps": 400 }Staging baseline is healthy. Apply the new pool size.Eleven turns since the target was last stated. Nothing in the response contradicts the stale belief. - T5
apply_config(service="payments-api", file="pool.yaml")→ { "status": "applied", "revision": "r118" }Applied to staging. Restart to pick it up.A write with no post-conditions. The response never says where the config went. - T6
restart_service(service="payments-api")→ { "status": "rolling", "pods": 12 }Production restarts. The pod count was the only clue, and the agent had no reason to compare it with staging's two.
Every call in that trace succeeded. To find the same pattern in your own logs, look for these signals:
- A state change far from the write it affects. Find every call that changes a mode or location (
set_target,checkout,cd,use_database,switch_account). Count the turns until the next write, and check whether any response in between restated the new state. Long gaps with no restatement are where drift lives. - Reasoning that names a stale state. Search the agent's reasoning for environment, branch or directory names, and compare each mention with the most recent call that set that value. A thought that says "staging" after a switch to prod is drift caught in the act.
- Frequent "where am I" calls. An agent that runs
pwd,git statusorget_current_target()before most actions is doing bookkeeping the interface should do for it. The calls are cheap individually and expensive in total turns. - Writes that don't name their target. List every tool that changes something and check whether its success response says where the change landed.
{"status": "applied"}is a write the agent can't verify. - Numbers that don't fit the believed state. Pod counts, row counts, account balances or file paths that only make sense in a different environment. If the trace shows them and the agent kept going, nothing made the mismatch stand out.
Review checklist
Run these against any tool surface where actions depend on a mode, location or session. Each check takes a call or two and works as a pull request template for new tools.
- Attach a state block with the current target, location or mode to every response, in the same place and with the same keys.How to check Call three different tools in a row. Each response should include the same state keys, such as
env,branchorcwd, with current values. - Overwrite the state block each turn instead of appending a history of changes.How to check Change the target twice, then make any call. The state block should show only the current value, not a list of past ones.
- Make every write report its post-conditions: where it landed, what changed from what to what, and what happens next.How to check Run a write against a test environment. The response should name the environment and show old and new values, not only
"status": "ok". - Label data with the state that produced it.How to check Fetch a report or query result, then switch the target. The earlier result should say which environment or branch it came from, so it can't be mistaken for the new one.
- Mark protected or production targets in the state block.How to check Switch to a production target and make any read. The state block should flag it, for example
protected: true. - Keep the state block under about 50 tokens and limited to fields that change during a session.How to check Count the block's characters and divide by four. Remove any field that never changes within a session.
When laws collide
A state block repeats on every response, so it competes with laws that guard the context window, and it pairs naturally with laws that keep state honest.
- Pulls against · H-03Token Hygiene & High Observation YieldWhere they clashToken Hygiene asks every response to carry only what helps the next decision. A 40-token state block on every response of a 60-turn session adds about 2,400 tokens, and on most of those turns the state didn't change.How to have bothKeep the block small, fixed and overwritten, with only fields that decide where actions land. On a turn where nothing changed, a one-line form such as
env=prod-eu branch=pool-40is enough. Spend the full block, plusprotectedflags, when state changed or a write is next. - Works with · H-04Freshness & Context Half-LifeHow they combineThis heuristic keeps the current state visible at the newest end of the ribbon. Freshness & Context Half-Life marks older observations as stale or superseded, such as the turn-2 confirmation of staging.What you getTogether they close both sides of temporal vertigo: the live value is always present, and the stale one is labelled as old. The agent no longer has to judge which of two true-looking statements is current.
- Works with · H-10Poka-Yoke BoundariesHow they combineAnchoring shows the agent where it is. Poka-Yoke Boundaries lets a write state where it expects to be, for example
apply_config(..., expect_env="staging"), and refuses to run when the two disagree.What you getThe state block prevents most wrong-target writes, and the precondition stops the rest before they reach production. An agent that ignored the block still gets a refusal that names the real target.
How much anchoring a surface needs depends on who uses it. The Guide treats the model as the user persona: family, size and training decide how a given interface lands, an idea it calls Persona = ModelLexicon · 12Persona = ModelTreating model family, scale and training as the user persona.. A large model in a short session may track a target switch on its own. A small, fast model in a 60-turn session will lose it. The state block costs both of them a few tokens and protects both from the same incident.
Terms from this page
- 081D Temporal Ribbon
- The linear token stream through which an agent perceives reality.
- 17Temporal Vertigo
- Disorientation from stale past states coexisting beside live state.
- 14Attention Geometry
- Positional layout of information across primacy, middle and recency zones.
- 20World-Model Drift
- Divergence between the agent's internal beliefs and actual environment state.
- 12Persona = Model
- Treating model family, scale and training as the user persona.