Loading Context on Demand: How It Works and What It Costs

Using evidence priority, rebuildable handles, and freshness fingerprints to control the material each round of reasoning actually needs to see.

On this page · 19 sections

Context Engineering is not about stuffing more material into the model. It is about answering a harder question before each inference: which information is most likely to change the correct decision at this moment?

In coding tasks, the volume of information and the rate of correctness are not monotonically related. A design document that is complete but out of date can be more dangerous than having no document at all; and when domain specifications enter the context in bulk, the constraints that are actually relevant can get buried.

Marshall's Progressive Context is therefore not simple directory-based loading, but a mechanism for ranking evidence, expanding handles, and validating freshness.

The Short Version

  • Context Engineering answers “which information is most likely to change the current decision,” not how to stuff more material into the model.
  • Material is ranked P0-P3 by Source Proximity: the closer to the current behavior, version, and risk, the higher the priority.
  • A Locator bound to a version matters more than a summary; inputs are computed into a Fingerprint, and once they drift the old result loses the right to keep advancing.
  • Every round of expansion needs stop conditions; for a short task with clear files and call path, a full Context Pack can be heavier than simply reading the source.

The smallest unit of Context is not a file, but decision value

I divide context material into four priorities. The lower the priority in the table below, the later and the less of it enters the context:

Priority Content Handling
P0 The current goal, direct requirement sources, accepted scope, non-goals, current source code, blocking questions Enters the context immediately
P1 Repository rules that must be followed, relevant domain contracts, permission and risk constraints Loaded when the corresponding Goal/Domain is hit
P2 Historical background, old discussions, adjacent modules, trend-type logs First compressed into a summary with sources attached
P3 The entire repository tree, full logs, the set of historical Tickets, all Schemas, unrelated domains Only a Locator (that is, a pointer from which the original can be re-read) is kept; expanded when needed

This ranking is not decided by file type. A current Provider Readback may be P0 even if it is only a few lines long; a very long “authoritative architecture document” that corresponds to an old version can only be P2 or P3.

The core principle is Source Proximity: the closer a piece of evidence is to the current behavior, the current version, and the current risk, the higher its priority.

How one round of Context Selection works

The mature version ran a Perception Bootstrap at the start of every non-trivial Stage. It does not solve the business problem directly; it establishes the evidence boundary for this round of reasoning:

1. Confirm the Goal, Stage, Branch, HEAD, and Worktree state
2. Identify the direct sources: user input, Jira, PRD, Figma, PR, or runtime evidence
3. Find the affected repositories, domains, interfaces, and high-risk surfaces
4. Sort the material into P0-P3
5. Save a path, URL, Revision, Hash, or Query Locator for large material
6. Expand only the parts the current decision still lacks
7. Generate an Input Fingerprint and bind it to the Node/Worker

The biggest difference from constructing one giant Prompt up front is that Context is not a static preliminary step; it unfolds progressively along with the decisions. Only after reading the caller do you know which Provider needs to be traced; once it is confirmed that there are no data writes, the whole Data Runtime specification no longer needs to be loaded.

A “map” and an “encyclopedia” are two entirely different kinds of entry point

An entry file should tell the Agent where to look, not try to hold every answer.

OpenAI's Harness Engineering article summarizes a similar lesson: an oversized AGENTS.md crowds out the task and the code, makes every rule look equally important, and quickly accumulates stale content. So the entry point works better as a table of contents, while stable knowledge lives in a structure that can be located, maintained, and mechanically checked.

Marshall's control plane adopted the same structure:

  • constitution.md holds only a small number of global invariants;
  • the Goal Command points to the rules the current goal needs;
  • the Domain Index then points to the affected domains;
  • a Risk Lens is loaded only when permission, data, Provider, or release risk is hit;
  • runtime artifacts are located through Artifact Role and Hash rather than copied into every Prompt.

This amounts to giving the model a directory tree first and then letting it take the shortest path for the problem at hand.

Locators matter more than summaries

A summary can help reasoning, but it cannot become an untraceable source of fact. The mature version's Context Pack kept the following for key material:

source_type
locator
observed_revision / commit
content_sha256
observed_at
scope
why_selected

This has two benefits:

  • after Compaction (that is, compressing earlier conversation into a summary) there is no need to keep all the original text; it is enough to keep a Locator that can be re-read and the version at the time;
  • when a conclusion in a summary becomes doubtful, you can go back to the source and check, rather than guessing which of several compressed versions is correct.

So the most important content of a Working Note is not a restatement of all the code, but:

  • the goal;
  • confirmed facts;
  • decisions;
  • unresolved questions;
  • next steps;
  • a rebuildable handle for each fact.

Freshness is not a timestamp

“The file was updated yesterday” does not prove that it still applies to the current run. Real freshness has to be bound to the inputs that would change the semantics:

  • Git HEAD, the Base Ref, and the Worktree Diff;
  • the Provider Object ID, Revision, or Updated Time;
  • the version of the Requirement Source;
  • the Hashes of the Domain Spec and its associated code;
  • the immutable Result of the previous Stage;
  • the Context Manifest the Worker actually read.

The mature version computed these inputs into a Fingerprint. It was re-validated at node start, at Worker Dispatch, at Node Result, and at Stage Completion. When an input drifts, the old result is not simply flagged as “possibly stale”; it loses the right to keep advancing.

This blocks a subtle error: the design is based on Commit A, the user updates to Commit B while the run is in progress, and the Agent nonetheless finishes the implementation using the summary of A. That kind of drift is very hard to detect from chat context alone.

A Context Pack is data, not new instructions

When Jira issues, web pages, logs, or RAG results are handed to an Agent, the external content may contain text that looks like instructions. The mature version therefore required that Evidence entering a Worker is Data and cannot override the system, the repository, or the Goal Contract.

A Worker receives only:

  • the minimal context relevant to its risk perspective;
  • explicit Source Locators;
  • its own read-only capabilities;
  • an output Schema and a Report Path;
  • the Route it is allowed to take when uncertain.

It does not read the whole control plane, and it cannot obtain new tools or write permissions from evidence text. This both reduces Tokens and lowers the chance of a Prompt Injection (that is, instructions smuggled into external content being executed as commands) crossing a trust domain.

Stop conditions for Progressive Discovery

On-demand loading easily degenerates into endless exploration. Every file read reveals another batch of related files, and in the end the whole repository still gets dragged into the context.

So every round of expansion needs stop conditions:

  1. whether the current Material Decision already has direct evidence;
  2. whether new material could change the plan, rather than merely adding background;
  3. whether the key call chain has been traced from the entry point to the final side effect;
  4. whether the risk boundary already covers permissions, data, async behavior, caching, and Providers;
  5. whether the remaining unknowns are discoverable facts or product decisions the user must make.

If the next piece of material would only repeat an already-confirmed conclusion, reading should stop; if the remaining question is a Material Choice, enter the Question Gate instead of using more context to make the decision for the user.

What Compaction, notes, and Subagents each solve

These three mechanisms are often treated as one and the same “long-context solution,” but they fit different shapes:

Technique Best suited to Main risk
Compaction A continuous conversation on the same task, preserving the main decisions and the most recent work Over-compression loses key details that seemed secondary at the time
Structured notes Cross-session work with clear milestones that needs a stable handoff Notes can go stale, or record an inference as a fact
Subagent Subproblems that are independent, need deep digging, and whose results can converge cleanly Tokens, latency, duplicated exploration, and synthesis cost

Anthropic's Context Engineering article also treats the three as different instruments and emphasizes that Context is a finite resource. My conclusion from practice is:

  1. first use Locators and narrow reads to reduce input volume;
  2. use a Working Note only when the task really does span windows;
  3. use a Subagent only when independent exploration can bring in new evidence.

Common failure modes

Source Authority Inversion

An old chat or a RAG summary is ranked ahead of the current code, and the model overrides the real implementation with a stale explanation. The remedy is to make evidence priority explicit and to return to a Source Readback before concluding.

Context Flooding

All domains, all tests, and the full logs get loaded out of fear of missing something. The result is attention scattered across low-value material and Compaction happening sooner. The remedy is P0-P3 and decision-driven expansion.

Handle without Freshness

Only the file path is saved, not the Commit/Hash at the time. The path still exists but the content has changed, and on recovery the new bytes get treated as the old evidence. A Locator must be bound to a version.

Summary Becomes Authority

An automatic summary is copied across many rounds, and eventually nobody reads the original anymore. Summaries should explicitly label Fact, Inference, and Unknown, and always retain the source handle.

Loader Self-weight

In order to load on demand, the model first has to understand a complex Loader Schema, Context Ledger, Triage, Pack, and Re-entry protocol. The loader's own documentation can become the largest always-loaded context, cancelling out the attention budget that on-demand loading saved.

Unbounded Discovery

With no stop conditions, Context Selection turns into a whole-repository audit. Every read must answer “which current decision could this change?”

How to measure whether a Context design is working

Counting Prompt Tokens alone is not enough. A Prompt that is too short can also cause repeated rework because it lacks a key rule. More useful metrics include:

  • how many irrelevant files were read before the first useful edit;
  • whether key decisions can be traced back to the current Source;
  • how many times work was redone during the task because of stale evidence;
  • the number of Compactions and the time each recovery took;
  • the share of the Context taken up by rules, business source code, and tool output respectively;
  • the duplication rate and actual adoption rate of what Subagents return;
  • review issues caused by missing context versus omissions caused by context overload.

The goal is not the fewest Tokens, but the highest decision gain per Token.

Where it applies, and the trade-offs

Progressive Context suits tasks that span repositories, span sources, last across multiple context windows, or must account for the version of their evidence. In those cases, the Manifest, Fingerprint, and Working Note turn “what the model remembers” into a fact boundary that can be re-read.

For a short task where the files and the call path are already clear, a full Context Pack can be heavier than simply reading the target source code. Whether to turn on the heavier context machinery depends not on the total volume of material, but on whether recovery, drift validation, and isolation between multiple executors genuinely constitute a current risk.

References

Related notes

Working on something similar?

I'm always happy to compare notes on distributed systems, delivery, and applied AI.

[email protected]