Interactive LLM context laboratory

A context window is a finite budget, not an infinite memory.

System rules, user messages, history, retrieved evidence, tool output, and future generation all compete for tokens. Allocate them deliberately, then see which information survives truncation and which evidence the model may still underuse.

Reserve output before filling inputKeep system policy explicitRetrieve evidence selectivelyCompress with provenancePosition affects effective useReserve output before filling inputKeep system policy explicitRetrieve evidence selectivelyCompress with provenancePosition affects effective use

Pack the prompt, then watch policy decide what survives

The segmented 3D tape is the final context. Height represents retained tokens. Faded upper blocks are requested content dropped or compressed by the active policy.

systemconversationmemoryretrievaltoolsoutput reserve
128512
02048
01024
02048
01024
1281024
none25%
none35%
Input tokens retained0
Tokens dropped/compressed0
Evidence retained0%
Effective evidence use0%

Context engineering decides what the model is allowed to notice before generation begins.

The capacity equation

The input and maximum generated output share one model context limit. Reserve generation space first; otherwise a full prompt can leave no room for the answer or trigger server-side truncation you did not design.

input tokens + output reserve <= context capacity
policyhistorymemoryevidencetoolsgeneration

Fitting is not using

Long contexts can contain relevant evidence yet models may use it less reliably depending on position, distractors, instructions, and retrieval quality.

Protect authority

System rules and current user intent should not be silently displaced by verbose history, retrieved documents, or tool output.

Compress selectively

Summaries save tokens but can erase quantities, uncertainty, chronology, and provenance. Keep original source references and structured facts.

Budget uncertainty

Token counts vary by tokenizer and content. Add safety margin for serialization, tool schemas, citations, and unexpected outputs.

Every truncation policy encodes product priorities

Preserve priorities

Keeps system and current retrieved evidence first, compresses durable memory, then drops older conversation and verbose tool output. Useful when policy and task evidence outrank conversational continuity.

Authority first

Recency first

Retains system rules and the newest conversation, then fills remaining space with evidence, tools, and memory. This can preserve dialogue coherence while losing older but decisive facts.

Continuity first

Proportional compression

Scales flexible segments together after preserving system and output reserve. No category disappears suddenly, but every category may lose detail.

Balanced degradation
A production context pipeline

Construct context from intent outward.

Do not concatenate every available string. Each segment should earn tokens according to authority, relevance, recency, and the cost of omission.

Start with invariants

Place policy, identity, tool constraints, and the current user request in explicit structured sections. Keep untrusted retrieved content distinguishable from instructions.

Select, do not dump

Retrieve a small candidate set, rerank for the current task, deduplicate overlapping passages, and include only evidence that can change the answer.

  • Track source and timestamp.
  • Prefer complete passages over fragments.
  • Preserve contradictory evidence.

Summarize durable history

Store decisions, preferences, and unresolved commitments as structured memory. Keep recent turns verbatim when wording matters; compress older exchanges with links back to originals.

Measure loss

Log which segments were requested, retained, compressed, and dropped. Evaluate whether missing context caused errors instead of treating truncation as invisible infrastructure.

Common questions

Does a larger context window eliminate retrieval?

No. Retrieval controls relevance, permissions, latency, and attention competition. Larger capacity can reduce truncation while still benefiting from selective evidence.

What is lost in the middle?

Some models use relevant information less effectively when it appears between the beginning and end of long inputs. The effect varies by model, task, training, and context composition.

Should system instructions always be first?

Follow the model's documented message format. More generally, preserve instruction authority and prevent untrusted content from being interpreted as policy.

How should tool output be handled?

Parse structured fields, remove irrelevant logs, cap repeated content, preserve errors and provenance, and treat tool output as potentially untrusted data.

Spend context on information that can change the answer.

Explore SuperPowers workflows that preserve useful computer state, turn explicit goals into visible work, and produce complete websites.

Explore SuperPowersComputer-use cacheWebsite-building agent