Context assembly and authoritative task state
Context is the information made available to a model invocation. The context window is its bounded sequence capacity, with input and output accounting determined by the interface. Context engineering selects and maintains that information across calls; it includes instructions, conversation history, tools and external material. The context-engineering report describes this broader scope.
Assembly starts with the immediate decision, gathers candidate information, checks eligibility, selects a useful representation and constructs the request. Application instructions, the user request, task records, observations and tool definitions have different roles. Keeping their serialization inspectable makes those choices testable instead of burying them inside a framework.
One call, several information sources
Request construction selects a view without replacing its sources.
Read the diagram as text
- Application guidance.
- Retained task records. Goals, constraints and recorded progress.
- Observation history.
- External candidates.
- Select and represent. Check eligibility before inclusion.
- Bounded request.
- Application guidance → Select and represent: Control: constrains assembly.
- Retained task records → Select and represent: Data: selected state.
- Observation history → Select and represent: Data: recorded evidence.
- External candidates → Select and represent: Data: candidate material.
- Select and represent → Bounded request: Data: constructed view.
The resulting input is a derived view: a representation built from underlying records. The materialized-view pattern supplies the analogy; a database materialized view is not required.
A constructed incident investigation provides a running example. The assistant must investigate a service alarm without changing production. Its task record retains the target revision, completed checks, unresolved deployment verification and an external check still running. An operator has already requested deployment; the assistant's verification read timed out. Neither the request nor the timeout establishes the deployment outcome.
| Immediate decision | Selected input |
|---|---|
| Explain the alarm | Read-only constraint, target revision, alarm observations, relevant change records and attributed hypotheses. |
| Report current status | Read-only constraint, current-revision check, deployment-verification result and unresolved work. |
Keep three things separate: authoritative application records, the history of observations and actions, and the current model input. A durable session log can retain material omitted from a call and supply it again later. A model proposal remains a proposal until the application accepts it through the appropriate state-changing process.
An output contract specifies the expected response structure, including how missing information is represented. Structural acceptance does not establish factual correctness; Structured Outputs and Tool Calling develops that distinction. Persistent agent memory retains information for reuse across runs, but only selected material enters a particular call. Its storage and writing policies belong in Agent Memory.
Instruction authority and examined data
A system instruction is application-supplied behavioral guidance carried through the interface's designated instruction mechanism. Roles and precedence are interface-specific. OpenAI's dated authority specification treats roles as structured metadata: a document declaring itself a system message does not become one. Conversation formatting explains the representation boundary.
Prompt injection attempts to make untrusted content redirect behavior across an intended instruction boundary. In the incident, a retrieved note might recommend bypassing approval. That recommendation is material to inspect, not authority to change production. AI Security explains the threat; assembly must preserve the distinction between the application's constraint and the note's content.
Authority survives a transformation
Summarizing examined data does not promote it into instructions.
Read the diagram as text
- Application guidance.
- Instruction-bearing field.
- External document. Untrusted content.
- Attributed summary. Still examined data.
- Examined-data field.
- Application guidance → Instruction-bearing field: Application assigns role.
- External document → Attributed summary: Summarize with attribution.
- Attributed summary → Examined-data field: Preserve data status.
Separate instruction-bearing fields from examined material, and retain attribution when that material is rewritten. A summary can report that an incident note recommends bypassing approval without adopting the recommendation. Delimiters and encoding help frame content, but encoding alone does not establish a reliable instruction boundary.
Permissions must remain enforced by application code for the specific operation and resource. Neither a retrieved instruction nor a correctly formatted model response grants access. This also applies to selecting private records for disclosure to a model, as explained in Authorization at access and disclosure boundaries.
Evidence records and preserved meaning
Provenance records origin and transformation history. A source snapshot and its summary are distinct information entities connected by a derivation, as formalized in W3C PROV.
An observation envelope is a useful application record that keeps evidence attached to its subject and limits. It is not a universal API schema. GitHub check runs illustrate the necessary distinctions: repository and run identity, head_sha, status, conclusion and timestamps. An in-progress run without a conclusion differs from a completed run whose conclusion is neutral.
| Representation | Useful property | Preservation risk |
|---|---|---|
| Raw log | Retains detailed exchanges. | Relevant facts compete with bulky output. |
| Bounded excerpt | Keeps selected original wording. | Omitted material may contain the decisive qualification. |
| Structured fields | Separates revision, lifecycle state and conclusion. | Discarded fields cannot qualify the retained values. |
| Prose summary | Combines information into a compact account. | Can obscure which source supports which assertion. |
Preserve labels that determine meaning. In an example incident table, 'p95 latency (ms), staging only: 420; production not measured' cannot become 'production latency: 420.' The heading, unit, scope and negation travel with the value. Context-preserving document handoffs explain this boundary. Source attribution supports inspection; extraction still needs checking against the source.
Failed, partial and unavailable observations need explicit status. A response can arrive without establishing success, and a timeout can leave an external outcome unknown. Preserve those limits alongside the operation and target. Results and justified completion claims covers the execution boundary; lineage and audit evidence covers its record.
Selection for the next decision
Relevance means bearing on the question. Sufficiency means containing enough information to support an answer. Relevant records can omit a necessary connection; even sufficient context can contain false assertions. Required-fact coverage therefore deserves its own check.
Retrieval finds external candidate material; Search and Retrieval explains how. Assembly decides which candidates join application state in the request. Nearest-neighbor search can return records even when none answers the question. A ranking is an ordering among candidates, not evidence that any candidate satisfies the information requirement.
Coverage, repetition and a gap
ExampleDuplicate historical evidence cannot fill a current information gap.
Read the diagram as text
- Task record.
- A check report.
- Duplicate A report.
- B check observation.
- No production changes.
- Historical A success.
- B check: in progress.
- Deployment: unknown. Required observation missing.
- Task record → No production changes: Supplies constraint.
- A check report → Historical A success: Supports history only.
- Duplicate A report → Historical A success: Repeats same coverage.
- B check observation → B check: in progress: Supports qualified status.
A practical selection map separates mandatory constraints, decisive evidence and optional background. For the incident's current-status report, the read-only constraint must survive; the current revision needs its own check observation; deployment status needs independent evidence. Old successful checks may explain history, but another copy adds no coverage of the missing deployment observation.
Assess permission separately from usefulness before accessing a record and before sending it to the model. An application credential may reach information the requester cannot use. Current eligibility must come from trusted application state, not a model-supplied identity or a source's claim that sharing is allowed.
Remove repetition without merging distinct revisions or disagreements. Two reports can share almost all their wording while differing in a date, number or negation that changes the decision. Retain identity and validity separately from duplicate-cluster membership; revision-aware deduplication explains why textual overlap is insufficient.
Missing decisive evidence calls for another authorized read when feasible, or a bounded answer that identifies the gap. Irrelevant evidence calls for filtering. These are different repairs: increasing the number of returned records can add noise without supplying the missing fact. Selection should improve coverage and marginal usefulness, not merely increase volume.
Complete-request budgets and overflow choices
Tokens are the model's sequence units, rather than a fixed number of words or characters. Budget the assembled request: instructions, history, evidence, tool definitions, output contracts and formatting. Complete-request token counts explains why independently estimated fragments do not establish the final count.
| Request | Input | Input + reserve | Capacity result |
|---|---|---|---|
| Before selection | 15,000 tokens | 17,000 tokens | Exceeds the window by 1,000 tokens. |
| After selection | 13,000 tokens | 15,000 tokens | Leaves 1,000 tokens beyond the reserve. |
Fit is a capacity condition, not a quality score. An application can choose a smaller operating budget, but no universal fraction is established. Unused capacity need not be filled with background that contributes nothing to the decision.
Provider counting may be an estimate. Claude's documented endpoint accepts structured inputs, including tools and supported media, but actual usage can differ slightly and include provider-added tokens. Count for the intended model, preserve headroom for uncertainty and recount after reconstructing the request. An input estimate alone does not budget a complete multi-step interaction.
Cached prefixes still occupy the context window: caching changes processing cost, not capacity. A file pointer is also not necessarily a small model input. In the demonstrated Gemini upload workflow, the backend loads the referenced file into context even though the client does not retransmit its bytes.
Repair overflow explicitly: remove redundant logs, retrieve a narrower passage, narrow the decision or compact selected history. Then serialize and count again. Preserve mandatory constraints; shrinking the answer reserve is acceptable only if the remaining allowance supports the required output.
Arbitrary message deletion can also break the interface. Preserve required tool-call/result pairings when trimming history. A smaller request that loses the relationship between an operation and its result is not a valid repair.
Evidence ordering and coherent interpretation
Required message structure constrains ordering before editorial preferences enter. A tool result must remain correlated with its call identifier, not merely its function name or completion position. Authorized dispatch and call identity explains that contract. Evidence inside permissible structures can then be arranged for the decision.
| Position | Chronological arrangement | Question-grouped arrangement |
|---|---|---|
| 1 | E1 — A check passed. | Current target: E3 — Target changed to B. |
| 2 | E2 — Deployment verification timed out. | Current check: E4 — B check in progress. |
| 3 | E3 — Target changed to B. | Deployment: E2 — Deployment verification timed out. |
| 4 | E4 — B check in progress. | History: E1 — A check passed. |
Chronology makes changes and their sequence easy to follow. Question grouping makes the evidence for each requested conclusion easy to locate. Either can be appropriate; neither permits detaching a qualification or silently changing wording. The comparison is an organizational choice to test, not a demonstrated ranking of formats.
Lost in the Middle names historical research in which moving relevant information changed performance on selected question-answering and retrieval tasks. Several tested models favored beginning or end positions, with task-specific exceptions. This establishes a reason to test position sensitivity, not a universal rule for present-day models.
Move the same decisive passage while holding the total content fixed. Vary distractor volume and total length in separate comparisons. Context access and demonstrated behavior explains why a passage's inclusion does not establish its successful use, and why answer failure alone cannot reveal internal attention.
Loading and refreshing changing information
Freshness concerns validity for the current question. Source time, observation time and summary-generation time describe different events. Rewriting an old observation today does not make its facts current.
When the incident target changes from revision A to B, A's successful check remains evidence about A. It does not become a B result. The same failure appears with cached business records: a reported deployment wrote a new credit score successfully, but a downstream agent read an older cached score because invalidation failed.
Just-in-time loading waits until a decision needs information before acquiring its details. Progressive disclosure initially exposes compact descriptions or references, then loads fuller material when needed. A skill containing query-language guidance illustrates this pattern: its description helps select it, while its body supplies the syntax needed before execution.
Preloading avoids later discovery work but retains material that may never matter. Demand-driven loading keeps the working input focused while adding retrieval steps and possible selection failures. Repository guidance can likewise load by subsystem; that guidance still needs maintenance when the implementation changes.
Refresh when the target or task changes, a new result arrives, or an observation exceeds its permitted validity period. HTTP caching provides a concrete model of age and revalidation, but cache freshness is a reuse contract rather than proof that a business fact remains true. The application must define validity for its own decision.
Recent observations need not form a consistent snapshot. Under PostgreSQL Read Committed isolation, successive SELECT statements can see different committed states, even within one transaction. An assembler that reads the target revision, then reads its status after another transaction changes the target, must reconcile identities rather than assume recency makes the pair compatible.
If refresh fails, preserve the last observation's age and mark current evidence unavailable. Do not replace a timestamp with the latest retrieval attempt. Changed permissions also require reevaluating eligibility. Action-time revalidation adds a separate requirement when the system proceeds from reporting to consequential action.
Compaction and summary fidelity
Compaction replaces accumulated context with a smaller representation for subsequent calls. Summarization creates a shorter account; retrieval loads selected external content. Durable notes remain outside the window until supplied again. These operations can cooperate, but they are not interchangeable, and a shorter input is not automatically more useful.
Omission drops material. Exact extraction retains selected original spans. Structured projection selects fields from task records. Abstractive summarization rewrites information in new language. Each reduces detail differently; rewriting also creates opportunities to change relationships. Simple truncation can precede model-based summarization, provided omissions are marked and needed source material remains recoverable.
Stored evidence versus visible evidence
ExampleRecovery adds source content through an explicit read.
The call can inspect the original observation.
Read the diagram as text
- Incident.
- Stored observation. Deployment requested; verification timed out.
- Input: full observation.
- Input: summary + reference. Deployment unverified; source retrievable.
- Read stored source.
- Input: recovered excerpt. Original status wording available again.
- Incident → Stored observation: Has observation.
- Stored observation → Input: full observation: Included in full.
- Stored observation → Input: summary + reference: Summarized and referenced.
- Input: summary + reference → Read stored source: Reference enables read.
- Stored observation → Read stored source: Supplies original content.
- Read stored source → Input: recovered excerpt: Returns selected content.
- Full input. The call can inspect the original observation. Active: Incident, Stored observation, Input: full observation. New: Incident, Stored observation, Input: full observation.
- Compacted input. Only the active representation changes; storage remains. Active: Incident, Stored observation, Input: summary + reference. New: Input: summary + reference.
- Explicit recovery. A read supplies the excerpt for another call. Active: Incident, Stored observation, Input: summary + reference, Read stored source, Input: recovered excerpt. New: Read stored source, Input: recovered excerpt.
| Retained representation | Available information | Likely gap |
|---|---|---|
| Full history | Original exchanges, if they fit. | No automatic guarantee of effective use. |
| Recent window | Latest interactions and their wording. | Earlier constraints or decisions may be absent. |
| Summary only | The information selected for the summary. | Omitted details and exact source wording. |
| Summary plus recent window | Older selected state and recent exchanges. | Details excluded from both representations. |
A task summary should retain active constraints, decisions with rationale, unresolved questions, relevant observations, pending work and evidence references. A chronological recap can spend its space describing activity while omitting the obligations that remain. Reconcile the summary against current records before continuing.
A source reference is a retrieval handle, not the source's contents. Explicitly reading the referenced record restores selected evidence to the next input.
| Representation | Statement | What it establishes |
|---|---|---|
| Original observation | Deployment requested; verification timed out. | The request is recorded; deployment outcome remains unknown. |
| Faithful summary | Deployment remains unverified after a timed-out check. | Preserves the unresolved outcome. |
| Faulty summary | Deployment completed. | Introduces unsupported completion. |
Summary errors can alter entities, predicates, circumstances and connections between statements. Inspect negation, uncertainty, scope and revision identity, not just fluency. FRANK's factuality taxonomy supports this relationship-level inspection; it does not measure modern agent-compaction failure rates.
Repeated rewriting can also lose a qualification: 'cache mismatch is suspected' can become 'cache mismatch' and then 'the cause was cache mismatch.' This is a possible failure, not an inevitable drift law. Validate important claims against original observations. Fresh sessions with structured handoffs and continuous compacted sessions remain alternatives to test on the actual task.
Source authority must survive rewriting too. A summarized incident note remains externally supplied content; it cannot grant approval. Untrusted content across transformations and memory covers this risk. Preserve requested, attempted, observed and verified status using the distinctions in justified completion claims.
Trigger compaction with enough headroom for the transformation. In Claude's documented compaction beta, a threshold initiates an additional sampling iteration, and subsequent processing drops content preceding the compaction block. Compaction usage is reported separately. Submitted history, effective input and stored history can therefore differ; the API behavior does not guarantee summary fidelity.
Exclusion, invalidation and derivative rebuilding
Eviction removes material from a working input to save space. Invalidation marks an assertion as no longer usable under its previous interpretation. Supersession supplies a replacement. A history can preserve the old assertion and the evidence that changed it, rather than silently overwriting both.
A correction must reach dependent representations. If an obsolete note contributed to both an excerpt and a summary, excluding the note alone leaves two routes for its conclusion to return. Regenerate a derivative from eligible current sources, exclude it pending review, or retain it explicitly as historical evidence when that use remains permitted.
Review every dependent representation
ExampleRemoving a source leaves its derivatives to inspect.
Read the diagram as text
- Changed source.
- Existing excerpt.
- Existing summary.
- Check or rebuild.
- Future input.
- Excluded pending review.
- Changed source → Existing excerpt: Prior derivation.
- Changed source → Existing summary: Prior derivation.
- Existing excerpt → Check or rebuild: Submit for review.
- Existing summary → Check or rebuild: Submit for review.
- Check or rebuild → Future input: If checked and eligible.
- Check or rebuild → Excluded pending review: If unchecked or ineligible.
Source deletion and derivative repair are distinct even in documented products. Zep states that deleting an episode does not regenerate summaries of nodes shared with other episodes; information from the deleted episode can remain there. Deleting an episode that invalidated a fact also does not automatically reverse that invalidation.
Recheck eligibility when saved material returns through retrieval or conversation reconstruction. A previously permitted copy cannot establish present permission. A revoked note and an unchecked derivative should remain out of future inputs until their owning systems establish an eligible replacement.
Excluding content from future calls does not delete stored transcripts, checkpoints or cross-run memory, and cannot retract an already transmitted request. LangGraph distinguishes current-message removal from checkpoint deletion and separate store operations. Broader erasure belongs in Lifecycle fulfillment across derivatives; persistent storage lifecycle belongs in Agent Memory.
Verification across successive calls
Inspect what each call could actually receive, including selection and transformation decisions. A complete stored transcript is insufficient when the provider processes a compacted view. Check the boundary between submitted history and effective input, and distinguish known content from provider-controlled or unobserved processing.
| Category | Boundary evidence | Appropriate investigation |
|---|---|---|
| Unavailable | The required observation was never obtained. | Inspect acquisition failure or missing source coverage. |
| Excluded | The record existed but was not selected. | Inspect eligibility, selection and budget decisions. |
| Misrepresented | The selected representation changed the claim. | Compare the transformation with its original evidence. |
| Stale | The observation concerns an obsolete state. | Inspect target identity and refresh rules. |
| Present but unused | Required evidence was present, but behavior failed to reflect it. | Test competing explanations; do not infer internal attention from the answer alone. |
Four inspectable request snapshots
ExampleEach reconstruction preserves constraints while changing available evidence.
Inspect scope and evidence identity.
Read the diagram as text
- Incident: read-only.
- Request 1: initial. Target A; A check passed; deployment unknown; attributed incident note included.
- Request 2: revision changed. Target B; B check in progress; A historical; deployment unknown.
- Request 3: compacted. B status retained; verification still pending; note-derived hypothesis remains attributed.
- Request 4: exclusion applied. Revoked note and unchecked derivative excluded; B and deployment qualifications retained.
- Incident: read-only → Request 1: initial: Initial view.
- Incident: read-only → Request 2: revision changed: Refreshed view.
- Incident: read-only → Request 3: compacted: Compacted view.
- Incident: read-only → Request 4: exclusion applied: Rebuilt view.
- Initial assembly. Inspect scope and evidence identity. Active: Incident: read-only, Request 1: initial. New: Incident: read-only, Request 1: initial.
- Revision change. New target requires its own observations. Active: Incident: read-only, Request 1: initial, Request 2: revision changed. New: Request 2: revision changed.
- Compaction. Check qualifications against retained originals. Active: Incident: read-only, Request 1: initial, Request 2: revision changed, Request 3: compacted. New: Request 3: compacted.
- Exclusion. Inspect derivatives before further disclosure. Active: Incident: read-only, Request 1: initial, Request 2: revision changed, Request 3: compacted, Request 4: exclusion applied. New: Request 4: exclusion applied.
Long-session tests should start from retained history and evaluate a continuation. Sally-Ann DeLucia describes loading ten prior turns and testing the next, making late failures reproducible. The number is an example, not a coverage threshold. Include continuations that depend on old constraints, changed targets and information removed from the active view.
Confirm that the policy activated. A short run that never compacts provides no evidence about compaction fidelity. Compare against untouched history where it fits, holding model, prompt, tools and tasks fixed. Initial compaction experiments reported that untouched history could outperform defaults, but their small trial counts did not establish a universal ranking.
A context ablation changes one assembly choice while preserving other conditions: selection, ordering, compression or removal. Reset initial state and memory between independent trials, equalize budgets and repeat runs. Report task counts and uncertainty. Controlled offline comparisons provides the broader method.
Choose settings on development cases, then evaluate the frozen policy on held-out tasks. Repeatedly modifying settings after inspecting the final test converts that test into development data. A policy that preserves this incident's distinctions still needs evidence that it handles different investigations.
Capture only what the investigation requires. OpenTelemetry's GenAI conventions advise against recording full instructions and payloads by default; protected external references are an alternative. Recorded messages may also be truncated while retaining valid structure. Mark capture coverage explicitly: a valid trace object need not contain the complete request. Capture policy and execution provenance develops these controls.
Open questions
Decision-dependent preservation remains difficult because a detail's importance may emerge only later. Progress would be a compaction policy that preserves required facts on held-out continuations while reducing context, including cases where an initially peripheral constraint becomes decisive.
Ordering policies must separate position effects from changing content and task difficulty. A useful advance would demonstrate repeatable gains when identical evidence is rearranged across varied tasks and lengths, with distractor volume controlled independently. A single successful placement does not establish a transferable rule.
Correction and revocation propagation remain hard when many derivatives share sources. Progress would be an inspectable dependency inventory that prevents a disallowed assertion from reappearing through summaries or saved history, while preserving eligible historical evidence. Deleting one source is insufficient when retained summaries are not rebuilt.
Repeated compaction lacks a general fidelity guarantee. Its practical importance is preserving uncertainty and unfinished obligations across long work; the difficulty is distinguishing compression effects from evolving tasks and model variation. Progress would compare successive summaries against original records over repeated controlled continuations, reporting specific semantic losses rather than fluency alone.






































































































































































































































































































































































































































































































































































































































































































