← Context From First Principles

The Agent Writes Its Own Context

Treat plans, hypotheses, summaries, tool traces, critiques, and intermediate artifacts as self-generated future inputs.

A debugging agent hits a failing migration test, guesses duplicated tenant identifiers as the cause, and records the guess in its progress file. Twenty turns later the window has reset. A fresh invocation reads the file, finds “Root cause: duplicated tenant IDs,” and plans the rest of its work around a fact nobody ever established. The test output that prompted the guess is long gone. The guess survived; the evidence did not. Nothing in Chapters 10 through 14 prevents this, because every mechanism so far assumed the candidate universe was given. It is not. The agent manufactures it as it works, and this chapter governs what it manufactures.

The candidate universe does not stand still

Chapter 14 drew a pipeline from available information through candidates and admission into context. That drawing omitted the arrow that matters most once an agent starts acting:

    flowchart TD
    C["Context, step t"] --> M["Model"]
    M --> A["Action"]
    A --> O["Observation<br/>what the environment reported"]
    A --> G["Generated state<br/>plans, notes, hypotheses, reports"]
    O --> K["Candidate set"]
    G --> K
    K --> D{"Admission"}
    D -->|"context, step t+1"| C
  

Every action changes the future candidate set. A search query produces results; a file read yields an observation; a test run generates logs. A subagent call creates a report. A summary creates compact state. A plan update creates new coordination state. Agent execution is therefore a context-production process, and the first durable principle follows:

Agent execution changes the information environment of future agent execution.

Two identical starting contexts can diverge on the first action. One agent searches the cache subsystem, observes a stale entry, and forms a hypothesis about invalidation. Another reads the migration log, observes a timeout, and forms a hypothesis about connection pooling. Later contexts now differ in observations, hypotheses, and plans. Context is path-dependent in an agent loop — unremarkable as a claim about processes generally, consequential as engineering, because early decisions alter later information availability and there is no replay button on a production trajectory.

Generated text is not yet context

Precision first, because loose language here causes real design errors:

Self-generated context is agent-produced information that is preserved or reintroduced so that it can influence a later model computation.

Writing PLAN.md makes the plan available information and session state. It becomes context only when a later invocation receives it, through selection, admission, and rendering. Until then it is a candidate at most. The chapter covers observable, persistable state only: plans, task lists, progress records, summaries, hypotheses, critiques, reflections, subagent reports, tool-derived notes, decision records, intermediate files, structured working state. It excludes private hidden chain-of-thought, unavailable internal activations, and provider-private reasoning traces unless a product explicitly surfaces some representation as application-visible state. One architectural decision, stated as law:

Context engineering should govern observable state, not depend on private reasoning traces.

The application can govern tool calls, written plans, status fields, decision records, and explicit reflections. It cannot treat hidden reasoning as persistent application state, an auditable context item, or a stable API. Nothing in this chapter’s experiments seeds, reads, or manipulates hidden reasoning. Only observable state is written; only observable state is measured.

Three producers can fill the current context, and the distinction is load-bearing rather than taxonomic. The external world produces files, databases, pages, user instructions, tool outputs. The agent produces plans, hypotheses, summaries, critiques, reports, subagent instructions. The harness produces task status, progress records, checkpoints, evaluation outcomes, structured state. The working rule:

An item generated by the model does not automatically deserve the same evidential status as an observation generated by the environment.

A later section turns that rule into provenance requirements. Chapter 19 will use them for authority. Here they are recorded, not adjudicated.

Observation is not interpretation

The central mechanism. A test returns FAIL: expected 4, got 5. The agent writes “The cache invalidation logic is broken.” These are not equivalent. The first is an observation: what the environment reported. The second is an interpretation: what the agent currently thinks, carrying a hypothesis that exists precisely to be wrong sometimes. If both later appear as anonymous context, future computations treat a hypothesis as evidence. So the firewall reads:

tool observation
        ≠
agent interpretation
        ≠
established fact

Chapter 11 named one route by which possibility hardens into fact: epistemic collapse under compaction, where summaries promote the unresolved to the resolved. This chapter names the second route: an agent writes a hypothesis into state, the state is reused without its provenance and status, and a later computation treats it as fact. Same collapse, different machinery, same term consumed rather than reinvented. A useful future data model keeps observation, belief, decision, and status visibly apart — what the environment reported, what the agent thinks, what it chose, what work remains — but the chapter uses only as many categories as each experiment needs to stay interpretable.

Hypotheses therefore carry their uncertainty with them or they travel as counterfeits. A persisted hypothesis should keep, at minimum, its status and its evidence: unverified, based on observation-17, evidence against none yet. Later, falsified by observation-31. The exact schema is not prescribed; the principle is:

If temporary interpretations are persisted, their uncertainty must persist with them.

And confirmation must mean something checkable. A structured-state condition that lets the model mark its own hypothesis confirmed with no evidence lets the model win by declaring itself correct, which destroys the experiment. In deterministic fixtures a confirmed fact is backed by a fixture or tool-observation identifier, and the evaluator checks the backing. Production criteria come later; experimental validity comes now. Nor is the answer a confidence number on everything. Chapter 7 rejected one-dimensional importance; this chapter rejects one-dimensional confidence with the same argument. Producer, status, evidence references, scope, creation and update times: use only what the mechanism needs.

A hypothesis that becomes evidence

The failure mode, developed concretely. Weak evidence suggests hypothesis H. The agent records H in progress state. Future search queries assume H. Retrieval returns evidence related to H. The summary strengthens H. Each step is locally reasonable; the trajectory is self-reinforcing. This is not necessarily hallucination. It is a context feedback failure: a wrong item repeatedly selected, persisted, and amplified until a guess steers the work it was meant to serve. The durable statement stays measured:

Persistence can convert an error in one computation into an input assumption for many future computations.

Can, not must. The same loop is why agents work at all: a test result informs a decision, the decision updates the plan, the plan targets the next action, and correct state accumulates. The question is never whether agents should write state. It is what generated state deserves to survive, in what form, and under what evidential status. Impact scales with repetition — a small error reintroduced every turn can matter more than a large one seen once — which is why readmission frequency belongs in the policy alongside the persist-or-not decision. Chapter 14 owns admission generally; this chapter consumes it: a progress note need not be resident merely because the agent wrote it, and write-then-permanently-pin is recorded as the accidental policy to avoid.

Plans go stale in the same way hypotheses do. A plan that reads reproduce, inspect cache, add test, patch invalidation is temporary coordination state, useful until evidence clears the cache, after which keeping it resident constrains action toward a cleared suspect. Goal, plan, and current step are three different objects with three different lifetimes: the goal may persist while the plan changes and the step completes. Summaries steer trajectories too, which gives Chapter 11’s fidelity failures a second life as trajectory-control failures: a summary that drops the decisive qualification does not merely misrepresent the past, it redirects the future. Critiques and reflections earn the same treatment. “Previous attempt failed because we changed too many files” may be true or not; once persisted it biases later work, so a critique retains its source, the trial it refers to, its status, and its evidence. The experiment needs only enough of this to test the mechanism, never a grand schema.

Every action manufactures more context

Tool observations deserve special attention because they look environment-made while being agent-caused. The model chooses the tool call; the environment emits the observation; the observation becomes a candidate. The agent therefore controls not only what it writes but which information the environment produces for it — choosing queries, choosing files, choosing tests is choosing future context. This is the bridge from Chapter 14, and Chapter 17 owns everything on the tool-design side of it. Here only the mechanism travels: action choice manufactures future observation.

Subagents generalise the mechanism across agent boundaries. A lead agent delegates an investigation; the subagent produces a report; the report becomes a parent candidate that can compress useful work, introduce error, lose provenance, or duplicate other reports. Self-generated context does not have to return to the same model instance. No multi-agent architecture is built from this; the boundary example is enough. But two consequences follow that belong here. First, generated artifacts outlive their producing computation: progress files, feature lists, and reports shape fresh sessions, other agents, future models, and human reviewers the original invocation never sees. Agent-generated context can have a longer lifetime than the computation that created it. Second, write quality separates from answer quality as an evaluation target. A model can produce a good immediate answer while leaving poor persistent state, or a mediocre reply alongside excellent continuation state. Systems that only score the current output cannot see the difference, and the experiments score both.

What production harnesses already do

The historical line starts with ReAct, used here the way the book uses all early mechanisms: for the observable architecture, not the internals. Yao and colleagues interleave generated reasoning traces with task actions and environment observations across question answering, fact verification, and interactive decision tasks, reporting large absolute gains on the decision benchmarks. The transferable lesson is the trajectory shape itself — prior generated state plus environment observations influencing later action — while the reasoning traces stay on the private side of this chapter’s boundary. Nothing in the mechanism requires them as an application primitive.

Reflexion is the sharper precedent: Shinn and colleagues have agents verbally reflect on task feedback signals, keep the reflective text in an episodic memory buffer, and reuse it in subsequent trials, reporting large gains including 91 per cent pass-at-one on HumanEval against an 80 per cent baseline in the authors’ measurements. That is generated text becoming future input by explicit design, which is exactly this chapter’s subject. The chapter’s contribution is the question the paper’s ablations do not centre: what happens when the reflection is wrong. Self-reflection is not intrinsically corrective, and persistence decides how far an incorrect reflection travels.

Anthropic’s long-running-agent work supplies the deliberate-state counterpart. The November 2025 harness carries continuity in artifacts the agents write and read: feature lists with pass/fail status, progress notes, init scripts, git history, with each session starting from the recorded state and ending by updating it. The March 2026 harness extends the pattern into planner, generator, and evaluator agents communicating through files — sprint contracts negotiated before code, structured handoff artifacts between sessions, evaluator findings specific enough to act on. Three of its lessons transfer directly. Planner specifications constrain everything downstream, so errors in generated plans cascade: write quality governs answer quality before either is measured. Communication through files with lightweight references, rather than copying full outputs through every coordinator, preserves fidelity across agent boundaries. And the evaluator’s early leniency toward its own generator’s work had to be tuned out over several rounds — a production sighting of self-authored evidence wearing a lab coat. The multi-agent research system adds the cross-agent form: a lead agent’s plan persisted to memory against truncation, subagents returning condensed findings, and subagent outputs written to a filesystem with references passed back, explicitly to avoid the multi-stage game of telephone. Its appendix adds two more earned details: state-mutating agents are evaluated on end state rather than prescribed paths, and errors compound across long stateful runs. All three posts are first-party engineering evidence of shipped design experience, not controlled studies, and every quantitative claim stays vendor-reported.

SWE-agent is used for one narrow point and no more: Yang and colleagues’ thesis that agents are a distinct category of end user whose interface shapes their behaviour, with a custom agent-computer interface changing what trajectories and observations look like. The form of tool observations, the available actions, and what gets written back into context are interface products. Benchmark figures stay in the paper. Voyager is deliberately omitted: an expanding executable skill library would overlap memory, skills, and tooling questions the book has assigned elsewhere, and nothing in its mechanism adds to the persistence problem beyond what the harness and subagent cases already cover. Omission with a stated reason beats padding with a famous name.

Structured state, bounded state

The experimental question the chapter earns: free-form progress narrative against bounded structured working state — goal, confirmed facts, open hypotheses, decisions, remaining work, evidence references, using only the fields the fixture needs. Structure may reduce status collapse, provenance loss, and accidental reinterpretation; it may also lose nuance, demand schema design, and consume management effort. No winner is assumed.

Boundedness is a validity condition, not a feature. A structured record that only appends becomes another unbounded transcript wearing fields as costume, so the structured condition defines update, replace, invalidate, and close semantics up front. State carries versions — v1, v2, v3, with recorded changes — because correction delay and invalidation cannot be measured without them. When contradiction arrives, the system updates the live record rather than appending “H was false” beside a prominent “H is probably true” and letting future context contain both. That conflict problem belongs to Chapter 19 for precedence; here the requirement is only that working state has explicit invalidation semantics instead of append-only accumulation. The append-only evidence log still exists, but it lives with the evaluator as audit: what happened, what was observed, what the active state recorded at the time. Mutable active state represents what the agent currently needs. The old record stays auditable somewhere without staying active context — the book’s available-versus-current distinction applied to the agent’s own past.

Generated state goes stale two ways, and the chapter keeps the book’s vocabulary straight. Trajectory-obsolete means the task moved on: current step still reads “run migration test” after the test finished. World-stale means the external fact changed, which belongs to Chapter 20. Only the first is governed here. Scope is controlled the same way: a plan for one task does not quietly enter another, with isolation deferred to Chapter 21. Self-generated state is not exempt from compaction either — a generated summary may itself be summarised later under Chapter 11’s fidelity constraints — and agent state never outranks its producer: a self-written claim carries no authority for being self-written, with Chapter 19 to adjudicate.

Proposed experiments

The questions. Does persisting agent-written state help continuity, and does persistence change the probability that an early error propagates?

The design, in brief. Deterministic multi-stage fixtures with a goal, several plausible hypotheses, tool observations, one misleading early clue, one later decisive correction, and a completion criterion. The state writer at step two never sees the evidence introduced at step five. The first experiment compares the full raw trajectory, environment observations only, free-form generated state, bounded structured state with explicit update and invalidation, and an oracle minimal state, with a matched-budget arm. The second seeds the false hypothesis as observable state and varies whether it is never persisted, persisted unqualified, persisted with an explicit unverified status and evidence reference, left uncorrected after contradiction, or invalidated on contradiction. Hidden reasoning is never seeded, read or measured.

The measurement that matters. The lifecycle, mirroring Chapter 14: created, persisted, admitted, used, correct. Wrong-state persistence, promotion from hypothesis to treated-as-fact, correction delay in steps, and actions taken before correction, with remove-and-restore comparisons where causal use is claimed.

What would change the book. If observations alone suffice, the runtime sheds state machinery; if free-form state matches structured, no schema is added for elegance. The second experiment is a demonstration of a mechanism, not evidence about how often agents err. Nothing here has been run.

What travels forward

Agent-generated state is one producer among the sources of candidates, alongside retrieval, memory, tools and artifacts, and it has to arrive through the same door as they do. What it must carry with it is provenance and status: who produced it, whether it is an observation, a belief or a decision, what evidence it rests on, which version it is and what superseded it. No separate hierarchy of state records is proposed; the compiler of Chapter 23 takes candidates whatever their source, and a candidate built from agent state is checked by the same gates as any other.

The corpus of real sessions is empty. How much assistant-generated content survives across invocations, how often plans repeat, and how often hypotheses return are unmeasured, and the observer can distinguish only what it can see at the model-context hook.

When working state becomes memory

Self-generated state persists across steps, tasks, sessions, and sometimes longer, and at some horizon it starts to resemble memory. But not every progress note is memory, and this chapter does not decide where working state ends and durable past influence begins. That boundary is Chapter 16’s entire subject: if agent-generated state may outlive its trajectory, what distinguishes working context state from durable memory. The handoff question is asked here and answered there. What this chapter established is everything the answer will assume: an agent does not merely consume context but manufactures its future information landscape; persisted output is not evidence for having been written; and errors grow more dangerous the more often a system reintroduces them as context. The compiler’s candidate interface — retrieval, memory, tools, artifacts, and agent-generated state arriving through one door — is now fully motivated. What remains is to define the strangest source of all: the durable past.

References

  • Yao, S., Zhao, J., Yu, D., et al. “ReAct: Synergizing Reasoning and Acting in Language Models.” ICLR 2023 (arXiv:2210.03629, v3 camera-ready). Interleaved generated reasoning traces with task actions and environment observations; reported gains on HotpotQA, Fever, ALFWorld, and WebShop. https://arxiv.org/abs/2210.03629
  • Shinn, N., Cassano, F., Berman, E., et al. “Reflexion: Language Agents with Verbal Reinforcement Learning.” NeurIPS 2023 (arXiv:2303.11366). Verbal reflection on task feedback stored in an episodic buffer and reused across trials; reported 91% pass@1 on HumanEval. https://arxiv.org/abs/2303.11366
  • Yang, J., Jimenez, C. E., Wettig, A., et al. “SWE-agent: Agent-Computer Interfaces Enable Automated Software Engineering.” Preprint, arXiv:2405.15793, May 2024. Agent-computer interface thesis: interface design shapes agent trajectories and observations. https://arxiv.org/abs/2405.15793
  • Anthropic (Young, J., et al.). “Effective harnesses for long-running agents.” First-party engineering essay, November 2025, verified September 2026. Feature lists, progress notes, init scripts, and git history as deliberately shaped future context. https://www.anthropic.com/engineering/effective-harnesses-for-long-running-agents
  • Rajasekaran, P. “Harness design for long-running application development.” First-party engineering essay, Anthropic Labs, March 2026, verified September 2026. Planner/generator/evaluator with sprint contracts and file-based communication; structured handoff artifacts; planner-error cascade; evaluator leniency tuned out; simplification principle. https://www.anthropic.com/engineering/harness-design-long-running-apps
  • Hadfield, J., et al. “How we built our multi-agent research system.” First-party engineering essay, Anthropic, June 2025, verified September 2026. Lead plan persisted to memory; subagent findings as cross-agent context; filesystem artifact outputs with lightweight references against multi-stage information loss; compounding stateful errors. https://www.anthropic.com/engineering/multi-agent-research-system