Skip to main content
← Guides

Context is a budget, not a warehouse

Prompts & workflows · Prompt guide

Bigger windows still dilute attention — static content up front, just-in-time retrieval, compaction and notes spend tokens where signal is highest.

Prompt effect has not been tested.

A prompt is a re-runnable template, not a promise of results. Changing the model, version or input can change the outcome. Use the checkpoints on this page to verify it yourself, and treat the official sources as evidence of mechanism rather than a guarantee of effect.

What this guide covers

Context engineering decides which tokens belong in the window at each inference. Anthropic's official definition: prompt engineering writes instructions; context engineering curates and maintains the optimal set of tokens during inference — system instructions, tools, external data, message history all count. The window is a budget, not a warehouse: stuffing more in does not mean getting more out. We have not run hands-on tests; the mechanisms below come from official docs and papers.

Attention budget and position effects

Anthropic calls the phenomenon context rot: as context tokens grow, the model's ability to accurately recall information from that context declines. The root is the transformer architecture: n tokens form n² pairwise attention relations, and the longer the sequence, the thinner the capacity to capture them gets stretched. Short sequences dominate training data, so models also have less experience with long-range dependencies.

The Lost in the Middle paper tested multi-document QA and key-value retrieval: performance is highest when relevant information sits at the beginning or end, and degrades significantly when it lands in the middle of a long context. Explicitly long-context models behave the same way. Takeaway: do not bury key information mid-context; a big window is not uniformly good.

Static first, dynamic last

OpenAI's prompt caching matches on prefixes: a request first checks whether the beginning of the prompt is already cached; a hit reuses it, a miss processes everything and caches the prefix. It activates automatically above 1024 tokens — no request changes needed. The placement rule follows: instructions, examples, and tool definitions up front; user-specific variable content at the end.

Three details decide the hit rate: tool definitions and their order must be exactly identical across requests; multi-turn history is only appended to the end of the messages array, never reordered; the cached_tokens field in the response reports hits, and prefixes unused for a while are evicted. Caching is organization-scoped; the official docs state no data is stored during the process, making it eligible for zero data retention.

Just-in-time retrieval and progressive disclosure

Another way to save budget: do not pre-load data — keep lightweight identifiers. File paths, stored queries, links; load on demand at runtime with tools. Anthropic cites Claude Code as its example: write targeted queries, inspect slices with head/tail, and never load whole data objects into the window. Identifier metadata carries signal: directories, naming, and timestamps hint at purpose and relevance. The agent explores layer by layer, keeping only what is currently needed in working memory.

The official trade-off is explicit: runtime exploration is slower than pre-computed retrieval; without guidance the agent misuses tools, chases dead ends, and misses key information. Hybrid strategies are common: pre-load some data for speed, leave the rest to autonomous exploration.

Three techniques for long tasks

When a task outgrows the window, Anthropic offers three routes:

  1. Compaction: summarize history near the limit and reinitialize the window. Tune recall first, then precision; clearing old tool results is the lightest touch.
  2. Structured note-taking: the agent periodically writes notes outside the window and reads them back later. Progress and dependencies survive window resets.
  3. Sub-agents: each explores deeply in a clean window and returns only a distilled summary; the lead agent synthesizes.

Choose by task shape: compaction preserves conversational flow, notes suit milestone-driven iterative development, and sub-agents suit research and analysis where parallel exploration pays off.

Failure modes

  1. Edge-case laundry lists: stuffing every rule into the prompt. The official advice is diverse, canonical examples instead.
  2. Bloated tool sets: overlapping functionality, ambiguous choices. If a human cannot say which tool to use, the agent cannot do better.
  3. Over-aggressive compaction: dropping details that look trivial now but matter later. Tune the compaction prompt on complex traces.
  4. Waiting for bigger windows: the official judgment is that relevance problems persist at any size — curation cannot be skipped.

System prompts have two extremes of their own: hardcoded if-else logic is brittle, vague guidance is empty. The official advice: start minimal, then add instructions and examples based on observed failure modes.

Sources

Verified 2026-11-07; all three fetched directly with HTTP 200. The OpenAI doc site was unreachable from this network; official content was taken from a raw file in its official repository.

Sources

SourceURL
Anthropic Engineering · Effective context engineering for AI agents (direct fetch 200 on 2026-11-07)https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents
OpenAI Cookbook · Prompt Caching 101 (official repo raw file, direct fetch 200 on 2026-11-07)https://raw.githubusercontent.com/openai/openai-cookbook/main/examples/Prompt_Caching101.ipynb
Lost in the Middle paper (arXiv 2307.03172, abstract page direct-fetched 2026-11-07)https://arxiv.org/abs/2307.03172

Source snapshot: 2026-11-07; item-specific rechecks and their scope are recorded in the text or source notes. Features and terms may change; check the original sources before use.