research32 min studyLesson 891 in Engineering

Working context is a bounded view of versioned task state

Select task-relevant context while preserving goals, constraints, evidence identities, and pending action state rather than assuming a longer transcript is better memory.

On this page

What you’ll understand

  • Calculate a context budget including mandatory state and response reserve.
  • Preserve dependency identities when selecting or compressing records.
  • Distinguish a durable task record from the subset currently visible to a model.

An agent's current prompt cannot hold every past tool result, artifact, and conversation turn indefinitely. The engineering question is which information must remain immediately available and which can be retrieved by identity when needed. Goals, constraints, current artifact versions, completed checks, unresolved assumptions, and pending effects have different roles. A transcript summary that loses those distinctions can make the agent repeat work or act on an obsolete premise. Treat context selection as a bounded view over explicit task state, not as a guarantee that the model remembers everything it once saw.

Keep task state separate from prompt occupancy

A durable task record can identify the current objective, accepted constraints, artifact revisions, observations, and action attempts. The model receives only a selected rendering of that state. Preserve stable IDs so a claim about a file, tool result, or completed effect can be traced to the exact version it describes. A short record saying that a test passed is ambiguous if it omits which artifact revision was tested. Likewise, an action described as planned is different from one submitted, acknowledged, or externally verified as complete.

Reserve space for the system's required instructions, tool definitions, necessary task state, and a useful response or tool-call continuation. Measure the final serialized token count using the chosen tokenizer and formatting rather than assuming raw character length or independently tokenized fragments are perfectly additive. Optional history and retrieved records compete for the remaining budget. Context management can page details out to durable storage, as systems such as MemGPT explore, but paging does not itself validate the stored facts, choose the right retrieval, or ensure that a compressed record preserves every relevant condition.

∑itixi≤B,B=Cmax⁡−Cmandatory−Creserve,xi∈{0,1}\sum_i t_i x_i\le B,\qquad B=C_{\max}-C_{\rm mandatory}-C_{\rm reserve},\qquad x_i\in\{0,1\}
This is a simplified optional-record selection model with nonnegative measured formatted token costs t_i and a nonnegative remaining budget B. Mandatory and reserve categories are disjoint. Real tokenization and separators require checking the assembled prompt; the inequality does not identify the most useful or truthful records.↔ Scroll wide equations horizontally.

Selecting a claim also selects its dependencies

A derived conclusion can depend on a source observation, a particular input version, and an assumption that was true at the time. Selecting the conclusion without those identifiers can turn a scoped result into an unsupported general rule. A policy may include evidence directly or retain an available reference that must be resolved before use. Distinguish a valid pointer from inaccessible evidence: a missing or revoked source cannot be replaced by the summary's confidence. Dependency-aware selection should keep enough lineage to decide whether a future action still satisfies its preconditions.

Relevance scores are useful ranking heuristics, not authority or truth labels. A highly similar old record can refer to another project or a previous state. Preserve scope and source status before choosing which optional text to include. Compression can reduce repetition, but it can also merge contradictory observations or erase who said what. Test context transitions on tasks where the omitted qualifier matters, and inspect whether the agent distinguishes a user requirement from an external page's suggestion. More retained tokens can increase distraction and exposure to irrelevant instructions rather than improving decisions.

xclaim≤xevidencex_{\rm claim}\le x_{\rm evidence}
This is one deliberately strict toy policy requiring a selected derived claim and its evidence record to be included together. A real system can instead retain a validated resolvable reference with a required read before use. The constraint expresses a dependency choice, not a theorem that prompt inclusion makes a claim correct.↔ Scroll wide equations horizontally.

Test what survives a context transition

Build a fixture with a changed artifact revision, an earlier failed attempt, a pending operation ID, and a constraint introduced after the original plan. Force context selection or summarization, then ask which work can be reused and which needs a fresh check. Measure task success, unsupported claims, repeated effects, retrieval cost, and context size rather than only the quality of a summary. Preserve the externally checkable task state so failure analysis can distinguish missing evidence from a model ignoring evidence that was present. Research results on bounded-context architectures remain empirical evidence within their evaluated tasks.

The cache lab offers a smaller residency example. Reset, set both C=4 and stride s=2, predict sixteen initial misses, then inspect or Play. Reset and set both C=8 and s=2 for eight misses and eight hits in the initial sixteen requests. The empty fully associative LRU stream accesses(i×s) mod 16, has period eight, adds two requests per second, and caps at 4096. It contains no tokens, task dependencies, provenance, or semantic retrieval. It illustrates that capacity and access pattern interact, while actual context usefulness requires the separate task-state tests.

A context account must include mandatory state and continuation reserve

A toy serialized prompt limit is 8192 tokens. Disjoint measured categories are 1200 mandatory tokens,1800 selected history,800 current tool output,3000 optional memory, and 1200 reserved continuation. Assume all formatting is already included in those counts.

  1. The total reservation is 1200+1800+800+3000+1200=8000 tokens, leaving 8192−8000=192. Counting only the optional memory would miss most of the actual context occupancy.

  2. An additional 900-token record would exceed the total limit by 708 tokens if inserted unchanged. The system must select, compress, or retrieve later under its policy rather than silently dropping required state.

  3. If that record is the only evidence for a selected conclusion, removing it requires retaining a resolvable source identity and a read-before-use requirement, or removing the unsupported conclusion as well. Token arithmetic alone does not choose the correct semantic alternative.

The result

A bounded prompt can remain coherent when its categories and dependencies are explicit. A shorter or longer context is not by itself evidence of correct task state.

Explore the model

Interactive lab

Interactive lab · cache

Residency is not semantic working memory

Reset, set both C=4 and s=2, predict sixteen misses at initial N=16, then inspect or Play. Reset and re-enter both C=8 and s=2 for eight misses and eight hits. The empty fully associative LRU model accesses(i×s) mod 16, with N=16+floor(2t) capped at 4096. It has no tokenizer, context selection, evidence, or dependency identity.

Residency is not semantic working memoryA fully associative LRU cache starts empty and requests address (i·s) mod 16. Hits move an address to the newest position; misses evict the oldest when full. Playback starts with 16 requests and adds two per second, capped at 4096 explicitly simulated requests. This toy stream is not a processor-cache benchmark. Current readings: Hits / requests: 0 / 16; Hit rate: 0%; Address-stream period: 16 addresses. All parameters are adjustable with the labeled controls below.Fully associative LRU cache after 16 deterministic requests: 0 hits and 16 misses.Most recent 16 requestsaddress = i × 3 mod 160M3M6M9M12M15M2M5M8M11M14M1M4M7M10M13MCurrent cache order · oldest → newest471013Latest address 13 · miss: inserted as newestToy address stream · period 16 · starts empty
Cached addressMiss / evictionMost recent request
Hits / requests
0 / 16
Hit rate
0%
Address-stream period
16 addresses
t = 0 s

A fully associative LRU cache starts empty and requests address (i·s) mod 16. Hits move an address to the newest position; misses evict the oldest when full. Playback starts with 16 requests and adds two per second, capped at 4096 explicitly simulated requests. This toy stream is not a processor-cache benchmark. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forPreserve the right task-state relationships rather than equating stored quantity with useful memory.

Check your understanding

A summary says an artifact passed validation but omits its revision and evidence reference. What is missing for safe reuse of that result?

Try it yourself

A4096-token limit reserves 900 mandatory tokens and 700 continuation tokens. Optional formatted records cost 800,1000, and 900 tokens. Can all three fit? What minimum reduction is needed, and what must a reduction preserve?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Compute the remaining optional budget before deciding which record can be shortened or deferred.

Compare with the solution

The optional budget is 4096−900−700=2496 tokens, while the three records total 2700. At least 204 tokens must be removed or deferred. The selection must preserve necessary constraints and evidence dependencies or arrange a valid read-before-use path; the arithmetic does not justify deleting a critical qualifier.

Take it with you

  • Working context is a selected rendering of explicit versioned task state.
  • Budget mandatory content, formatting, and continuation along with optional records.
  • Preserve dependency identity and test decisions after context transitions.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.