Frontier Foundry

Context Engineering

The Library · Context Engineering & Memory

Deciding what goes into a model's limited context window, when, and in what form.

Also called: context rot, context compaction, compaction, context management, context budget. In the glossary.

Context Engineering is cooling this week (×0.46 against the eight weeks before). What is moving.

How it works, as a machineThe Library · turns

Follow one turn from a user's request to a note for the next session, in a reading library with one small reading desk.

  1. Lay out the prefix
  2. Set the desk
  3. Pick the next action
  4. Press the old turns
  5. Emboss the note
  6. Load the memory
Play Context Engineering

Context Engineering in plain words

Context engineering is deciding what goes into a model's limited window on each turn: which instructions, files, tool results and memories, and in what form. With too little the model lacks what it needs; with too much it loses the thread and costs more. Long tasks depend on what is kept, fetched and trimmed.

An analogy

A small desk in a large library. Only what lies on the desk can be read, so a librarian keeps choosing: bring this book, clear that pile, write a summary card before the stack tips over. The reader's work is exactly as good as what is on the desk at that moment.

How Context Engineering connects

19 typed relations in the knowledge graph

Builds on

  • Agent Harness: The reader is the model inside an agent harness; that district's Context Loom is one room of this library.
  • Agent Memory: The archive wing is memory across sessions: write after, load before, retire what is stale.
  • Agent Skills: The playbook shelf is skills: a short card always, the full playbook when picked.
  • Evals: The test bench is an eval lab for context choices, with long sessions as cases.
  • Long Context: The desk is the context window: its size, and why a bigger one does not mean a better desk.
  • Model Context Protocol: The parcel desk is where tool definitions and tool results meet the window.
  • Multi-Agent Systems: The side room is a sub-agent with its own window and a short result.
  • Prompt Caching: The stamp press is the prompt cache: a strict prefix match billed at a fraction of normal.
  • Retrieval-Augmented Generation: The card catalog is retrieval run as an agent loop: search, read, search again.

Built on by

  • Agent Harness: Deciding what the model sees each turn is the whole craft.
  • Agent Memory: The index is the always-loaded layer of what a session starts with; its size is a context budget.
  • Agent Skills: The menu is what a skill costs in context on every call; the body costs only when picked.
  • Coding Agents: What goes into the window, and what is capped or compacted, is context engineering.
  • Long Context: What goes in the window, and what is kept out of it, is the same choice made before the load is pasted.
  • Model Context Protocol: Tool cards and results compete for one window; deciding what sits on the desk is the craft.
  • Prompt Caching: What goes into the prompt and in what order is context engineering; the cache rewards a layout that stays still.
  • Prompt Engineering: What the prompt holds, and what is left out of it, is a context decision.
  • Retrieval-Augmented Generation: The ten chunks are what is put on the reader desk: the context.

Its kinds

  • Prompt Engineering: The prompt is one of the things put in the window; context engineering decides all of them.

Often in the same sources

Agent Harness, Tool Use, Long Context, Multi-Agent Systems, AI Agents

See Context Engineering in the knowledge graph

Context Engineering in the news

from the daily digests

Who is behind Context Engineering

people, labs, products and models

People

  • Philipp Schmid (popularized): 'The New Skill in AI is Not Prompting, It's Context Engineering'.

Named in its facts

What the sources say

9 parts · 49 sources · updated 2026-11-26

Context engineering is deciding what goes into the model's window each turn (instructions, tools, retrieved facts, history) and what stays outside. These talks describe the same pressures: windows rot as they fill, tool definitions and tool results are the fastest way to fill them, and long runs force compaction or external logs. The answers are on-demand loading, sub-agent isolation, small durable memory, a stable cacheable prefix, and evals to prove the changes work.

Context windows and context rot

A bigger window does not mean a better desk. Speakers describe accuracy and instruction-following dropping as the window fills, with the middle of a long input hardest to use, so deciding what stays out matters as much as what goes in. How bad it gets depends on the model, and one speaker shows the instruction ceiling moved about 10x in a year.

  1. The limit gate checks every incoming item against the room left in the window and sends back what does not fit.
  2. The desk slots take in the assembled prompt and each new result, and hold all of it in one window of fixed size.
  3. The fill gauge counts the tokens on the desk and reports the level to the compaction trigger.
  4. The reader (the model) attends to every token on the desk and writes the next action; the more tokens, the less attention each one gets.
~350K tokens
Where Bergum puts the usable context for current models before quality degrades (his opinion), compared to a 1.4 MB floppy disk Jo Kristian Bergum
30-50%
Accuracy drop on long inputs well before the window limit, across 18 models, in Chroma's context-rot work as relayed by Voss Laurie Voss
200-300 -> ~2,000-5,000 instructions
Rules a frontier model can follow at once before accuracy collapses, a year ago vs. in Voss's rerun of IFScale (reported) Laurie Voss
  • A log-monitoring agent keeps pulling large tool outputs into context; as the window grows, the model hallucinates and its reasoning degrades, and it forgets the middle of long inputs. Elizabeth Fuentes Leone
  • The more tokens in the window, the less attention each gets, and the attention matrix grows quadratically with length, so Martinez advises keeping the window as small as possible. Ignacio Martinez
  • Martinez says studies show a problem is solved more accurately at zero tokens than at 256K tokens, and past the advertised limit (256K or 1M) performance falls off sharply. Nacho Martinez

When it breaksGPT-5.5's polite half-finished report. In Voss's instruction-overload test, GPT-5.5 began a long business report, then partway through said the task was silly and stopped, leaving most required words missing. It looks like a real answer unless you read to the end. Laurie Voss

Open questionShould you keep the context window as small as possible, or has the instruction-following ceiling moved enough to fill it?

  • Keep the window as small as possible, because attention per token falls as you add more Ignacio Martinez
  • Skills and prompt files can now be very long; fitting everything in is no longer the hard problem, cost and verification are Laurie Voss
  • On DeepSeek, keeping the full history recalled exact details 95% of the time, while summarizing or compacting first recalled them 32% of the time Samridhi Vaid

Compaction, summaries and session logs

When history will not fit, harnesses summarize, truncate or compact it. Speakers split on whether generic summaries can be trusted, and several converge on the same design: keep the full append-only log outside the window and treat any summary as one lossy view that can be rebuilt differently.

  1. The session log keeps every event in an append-only record, so nothing is thrown away for good.
  2. The compaction trigger watches the fill level and, past a threshold, sends the history to be summarized; below it, the turn goes on.
  3. The summarizer, a general model or one trained for it, writes a summary or checkpoint that replaces the older turns.
  4. The summary check compares the summary with the log and refuses one that dropped what the task still needs.
  5. The window builder builds the next window from the log by a pluggable strategy: the last N events, a summary, or a mix.
  6. The log query lets the agent look up the stored log when the summary turns out to be missing something.
7 and 12 hours
Codex runs OpenAI's team cites as spanning many compactions in one thread Gabriel Chua
700 per day
Deploys to Lovable's agent runtime; it works because the process is stateless and each turn is persisted to the task history (reported) Fabian Hedin
95% vs. 32%
Exact-detail recall on DeepSeek with full history vs. after summarizing or compacting, in the Towards AI tutor tests (reported) Samridhi Vaid
97%
Share of tokens served from cache in a full-history, 36-turn DeepSeek run, which made it the cheapest setup (reported) Samridhi Vaid
13.3% -> 38.3%
GPT-5.6 Sol's score on the ARC-AGI-3 public set with the official harness vs. with retained reasoning and compaction (OpenAI reports about 3x the score with 6x fewer output tokens) OpenAI
  • Strands offers sliding-window, summarizing and hybrid conversation managers; the summarizing one keeps the last few messages (four in the demo) and summarizes the rest. Elizabeth Fuentes Leone
  • Fuentes lists naive summarization as an antipattern, because the summary may lack what the agent needs to answer. Elizabeth Fuentes Leone
  • Anthropic's managed agents keep an append-only event log so nothing is thrown away, and a flexible compaction strategy decides which events (all, last N, or a summary) enter context. Priyanka Phatak

When it breaksTool output overload forces compaction and rework. At LinkedIn, as agents used more tools every tool output filled the window until the agent compacted mid-task, lost information, and had to redo work. Ajay Prakash

Open questionCan you trust LLM-written summaries to carry a long task?

  • Naive summarization can drop the very facts the agent needs later, so treat it as an antipattern Elizabeth Fuentes Leone
  • Compaction the model was trained for works: Codex threads span many compactions and users report it rarely forgets Gabriel Chua
  • Do not compact if the cache is on: keeping everything was cheaper, faster and better at recall in their tests Omar Solano

Tool lists and tool output bloat

Tool definitions and tool results are the fastest way to fill a window. Speakers show three fixes: load tool definitions on demand, keep big results outside the window (files, pointers, code that returns only the answer), and cap loops. They disagree on whether to keep tools or give the model a sandbox.

  1. The tool index shows the agent a search step instead of every tool; a tool's schema loads only when the agent picks it.
  2. The call cap counts calls to each tool and refuses the call past the limit with a plain reply.
  3. The tool runner runs the call, in code or a shell where it can, so intermediate results never reach the window.
  4. The blob scan keeps binary blobs, base64 images and secrets out of a result and has a reference returned instead.
  5. The result trimmer cuts a large result to its head and tail plus a pointer ID, and sends the middle to storage.
  6. The pointer store holds the stored middle; the agent fetches it back by ID only when it needs it.
43% fewer tokens, 31% lower cost
Arize reports after moving its agent to code mode, with latency about constant Mikyo King
~1/3 of context
Share a naive MCP client could burn on ~100 registered tools before any work, per Curn Jan Curn
30-40 tools
LinkedIn's stated limit before MCP degrades performance; they front thousands of tools with 3 meta tools Ajay Prakash
  • Curn says naive MCP clients register every tool up front, so ten servers meant about a hundred tools and roughly a third of context gone before the first question; he calls it a harness problem, not a protocol problem. Jan Curn
  • Progressive tool discovery, introduced by Anthropic then Cursor, loads only the one or two tools needed instead of all of them; Cloudflare's code mode treats MCP tools as code. Jan Curn
  • King's code mode gives the agent tool search plus a programming environment: it calls many tools in one turn and puts only what it needs back into context. Mikyo King

When it breaksBase64 images blew up the window. Figma's first MCP output embedded base64 image data in the code it returned, which exploded the context window. Jesse Lumarie

Open questionShould an agent get a catalog of tools or a sandbox and code?

  • Give it a sandbox: search for tools, then compose them in code and return only what is needed Mikyo King
  • Keep tools, but hide them behind three meta tools (search, get schema, execute) so the catalog scales to thousands Ajay Prakash

Retrieval, agentic search and knowledge layers

Agents start each task knowing nothing about a company, so something must fetch the right facts. Speakers argue over lexical vs. semantic vs. hybrid retrieval, and over whether to build a persistent company-wide context layer. The shared warning is that finding a document is not the same as understanding.

  1. The source router sends a question to a live API call, a synced cache or a derived summary.
  2. The search tool (BM25, grep, a filesystem workspace) runs the agent's query, and the agent can search again after each read.
  3. The snippet list returns titles and snippets first, and the agent opens only the ones it wants.
  4. The zero-result check treats a search that returns nothing as a possible failure and sends the agent back to search.
  5. The conflict check lets a newer, fresher source override an older hit, so the first plausible answer does not win.
  6. The answer composer returns a compact, sourced answer instead of raw documents.
21M -> 10.8M tokens
Tokens for the same task without vs. with Unblocked's context engine (reported by Waselnuk) Brandon Waselnuk
150,000 -> under 1,000 tokens
Prompt tokens to describe tooling to agents, before vs. after Pinecone's Nexus (reported) Edo Liberty
77% faster
Reported speedup from Nexus in early-access customer tests, with better accuracy Edo Liberty
45,000 -> ~5,000 tokens
Context sent per coding query vs. tokens that actually mattered in Sakthivel's measurement (reported) Rajkumar Sakthivel
94%
Reduction in tokens (worst-case baseline of full files) from a local code index; he says real savings are lower Rajkumar Sakthivel
  • Bergum argues an agentic-search workspace organized as a filesystem gives progressive disclosure: show title and snippet, then let the model read more with grep, sed and similar tools. Jo Kristian Bergum
  • Bergum says BM25 suits agent users: they write long precise queries, exact matching on names and SKUs matters, it is cheap, and the model can see why a query matched. Jo Kristian Bergum
  • Waselnuk warns that MCP access is not understanding: the agent may never call the tool, or stops at the first plausible answer (satisfaction of search) and misses a newer Slack decision. Brandon Waselnuk

When it breaksSatisfaction of search. Agents using MCP or a wiki stop at the first plausible source, such as an architecture record, and never see last night's Slack thread that says to do the opposite. Brandon Waselnuk

Open questionIs lexical search enough for agents, or do you need semantic/hybrid retrieval?

  • BM25 plus grep is a strong agent primitive: exact matches, cheap, and easy for the model to inspect Jo Kristian Bergum
  • Similarity alone is not enough; combine vector, keyword, relational, graph, temporal and feedback signals Anders Swanson
  • Run dense and BM25 together: dense alone lost buried facts at 400K tokens while BM25 found them Samridhi Vaid

Memory systems across sessions

A window is not memory: when a session ends everything on the desk is lost. Speakers compare tiny files, vector stores, graph stores and full databases for what carries over, and stress that memory needs scoping, review and feedback or it fills with stale, conflicting or poisoned entries.

  1. The memory writer runs after the session as a background job and keeps preferences, facts and procedures, not raw transcripts.
  2. The memory screen refuses poisoned or conflicting entries before they are stored.
  3. The memory store keeps the notes: one capped markdown file per user, or typed episodic, semantic and procedural records.
  4. The vault file holds what a fresh window must read first: a feature list and a progress file, in JSON.
  5. The staleness sweep retires or merges notes that a lifecycle event or recall feedback marks as out of date.
  6. The memory loader puts the notes in the next session's prompt, or retrieves them by hybrid search.
8,000 characters
Cap on Arize Alyx's one-markdown-file-per-user long-term memory, which beat knowledge graphs for them Fuad Ali
1,000 vs. 50,000+ records
Swanson: a memory system can work well at a thousand records and drift into weird results at fifty thousand or a million Anders Swanson
  • Arize tried vector retrieval, episodic and semantic stores and temporal knowledge graphs, and landed on one markdown file per user capped at 8,000 characters. Fuad Ali
  • Arize's memory file is loaded on every full request and is written by a background job after the session, which makes it small, exact and easy for a human to audit. Fuad Ali
  • Swanson says files, wikis and grep give no governed recall and do not scale in multi-tenant settings; he argues a memory layer built on files ends up as a homemade database. Anders Swanson

When it breaksStale memories after a toolchain change. If a project used npm and then switched build systems, memories about npm are still recalled by agents later and mislead them. Anders Swanson

Open questionShould agent memory live in files or in a database?

  • A single capped markdown file per user beat vector retrieval, episodic stores and temporal knowledge graphs Fuad Ali
  • Files and grep do not scale or give governed recall; carried far enough you end up building your own database Anders Swanson

Instruction files, skills and progressive disclosure

Always-on rules cost tokens on every turn, so speakers push toward short descriptions that open into full playbooks only when needed. They also say that rules written for older models can now hurt, and disagree on whether skills should be hand-written, distributed through MCP, or replaced by a managed knowledge layer.

  1. Rule files (the system prompt, CLAUDE.md) are pinned to the desk and cost tokens on every turn.
  2. The rule audit runs when the model changes and deletes the rules the new model no longer needs.
  3. The skill index keeps only each skill's name and description in the system prompt; the full text stays on the shelf.
  4. The skill loader reads a skill's full text when the agent picks it and returns it as a tool result.
  5. The skill distiller writes a new skill from the trace of a successful or failed run.
  6. The skill scan screens each new skill before it is shared and sends back ones with hidden code or injections.
36% -> 100%
Success rate on a task (Chromium fork on AWS Lambda, Sonnet 4.6) after a distilled skill was reused (reported, no sample size) Rafal Wilinski
51%
Cut in instruction tokens when an optimizer replaced long worked examples with compact rules (Pane's worked example) Alvin Pane
  • Wilinski defines a skill as a playbook: the harness sees only a short description, then reads and injects the full text when relevant, which can steer a long run away from a wrong trajectory. Rafal Wilinski
  • LinkedIn returns a playbook's instructions as the tool output when the agent invokes it, so one MCP carries both tools and instructions on how to use them. Ajay Prakash
  • LinkedIn asks that each playbook be self-contained and about one task, and big playbooks be split into smaller referenced ones, which allows reuse and progressive discovery. Ajay Prakash

When it breaksOld prompt rituals backfire. Instructions telling the model how to think and verify, plus contradictory rules, were harmless or ignored by weaker models, but frontier models spend extra tokens on them and get confused by contradictions. Lance Martin

Open questionHow should company skills reach agents: a governed MCP server or a managed knowledge layer?

  • A remote MCP server as the source of truth that searches and serves the right version of each skill Rafal Wilinski
  • Stop hand-writing skills and plugins; tell the knowledge layer what you care about in a manifest and let it organize itself Edo Liberty

Sub-agents and context isolation

A sub-agent gets its own window, does the heavy reading, and returns a short result so the main desk stays clean. Speakers agree on the benefit but disagree on cost and complexity: you still pay for the tokens, handoffs lose detail, and Lovable and Arize both rolled back specialist-agent designs.

  1. The brief hands a heavy subtask (a big file, a trace, a wide search) from the main agent to a sub-agent.
  2. The pointer share passes an ID to stored data between agents, so each fetches what it needs instead of a whole context.
  3. The clerk's window holds the large input and does the heavy reading; none of it enters the main window.
  4. The evaluator, in a separate window with its own prompt, checks the clerk's work and sends back what fails.
  5. The result slot returns only the distilled answer, or a pointer to stored data, to the main desk.
2.6% -> 45.4%
Reported accuracy jump of recursive language models on a long chain-of-thought benchmark (third-party test, relayed by Madura) Kevin Madura
10 -> 1
Arize collapsed ten specialist agents into one agent with on-demand skills Fuad Ali
  • Fuentes says sharing a whole context between agents adds garbage because not every agent needs it, so agents in a swarm pass a memory-pointer ID through invocation state. Elizabeth Fuentes Leone
  • Curn says sub-agents keep the main window clean but you still pay for the tokens, and a sensitive tool result stays in context and can be abused. Jan Curn
  • Madura says an RLM keeps the full input as a REPL variable, delegates subtasks to sub-models, and gets back only what matters, so the window fills more slowly. Kevin Madura

When it breaksLovable's multi-agent framework made the product worse. Lovable built a main agent that spawned specialist implementation, front-end and back-end agents that messaged each other. It made the product worse, so they went back to one main model plus small retrieval models. Fabian Hedin

Open questionSplit work across sub-agents or keep one agent with on-demand skills?

  • Isolate heavy work in sub-agents or sub-models and share only pointers or results Elizabeth Fuentes Leone
  • Sub-agents still burn tokens and keep sensitive values in context, so they only push the problem further Jan Curn
  • One agent loading skills and tools on demand worked better than ten specialists Fuad Ali
  • Give data-heavy work to sub-agents; the main agent stays small Sally-Ann DeLucia
  • One main agent was enough for a tutor; sub-agents add complexity Louis-François Bouchard

Prompt caching, prefix stability and cost

Agents resend the same prefix every turn, so cache hits decide the bill. Speakers say input tokens, cache-hit share and turn count drive agent cost, that a single changed byte early in the prompt wipes the cache, and that caching is the first of several levers before shrinking prompts or downsizing the model.

  1. The prompt orderer lays the prompt out from stable to volatile: system and tools, then rules and memory, then session state, then messages.
  2. The prefix check compares the start of the prompt with last turn's, byte for byte; one changed byte there is a cache miss.
  3. The hit-rate meter counts cached and uncached input tokens for every turn.
  4. Server-side state keeps the session under an interaction ID, so history is not rebuilt by hand and the prefix stays intact.
  5. The cost ledger turns input tokens, cache-hit share and turns per task into the bill for the task.
$21 -> over $200
Cost of one knowledge-work agent task with vs. without prompt caching, on Artificial Analysis' benchmark George Cameron
up to 72%
Cost reduction Anthropic's team found on internal benchmarks by fixing prompt-cache use in default harnesses Lance Martin
~1/10 price
Rate at which Martin says cached prompt tokens are billed relative to base input tokens Lance Martin
90% input / 10% output
Sakthivel's split of AI coding cost, which is why he cuts input first (reported) Rajkumar Sakthivel
56% to 87%
Cost reduction TokenPilot reports against prior context managers on two agent benchmarks, from stabilizing prefixes and evicting in batches Hugging Face
  • Martin says prompt cache is billed at about a tenth of base tokens and is faster, but it is a strict prefix match, so even a one-byte change in the prefix invalidates it. Lance Martin
  • Martin orders prompts as system instructions and tools (global), CLAUDE.md and memory (per project), session state, then messages; a cache diagnostic found up to 72% savings in internal benchmarks. Lance Martin
  • Cameron says today's agent-cost drivers are input tokens, cache-hit share and turns per task; with zero cache hits a $21 task costs over $200. George Cameron

When it breaksOne stray space wiped the cache. Ivan Leo says some startups lost their cache from a single whitespace they mistakenly added while managing opaque thought signatures by hand. Ivan Leo

Open questionIs a big instruction prefix a cost problem or a solved one?

  • A prompt with thousands of instructions is expensive and slow, so adding more is a cost-latency trade-off Laurie Voss
  • The repeated prefix is billed at about a tenth the rate if you keep it stable, so protect the cache Lance Martin
  • Cache first, then shrink the instructions (one example cut instruction tokens 51%), then downsize the model Alvin Pane
  • Keep the full history cached: it was the cheapest setup at 97% cached tokens, cheaper than summarizing each turn Samridhi Vaid

Measuring context quality

Context choices only count if you can see their effect. Speakers say the hard problem moved from fitting rules in to verifying that the model followed them, and they describe tests that replay long runs, compare candidate prompts with confidence intervals, and warn that optimizers overfit easily.

  1. The task set holds production-like cases, including long sessions replayed ten turns deep.
  2. The repeat runner runs the candidate and the current prompt on the set several times, in a sandbox.
  3. The verifier scores each run pass or fail, and sends a failing run to the failure press.
  4. The variance scale subtracts normal run-to-run disagreement from the gap between the candidate and the current prompt.
  5. The ship gate lets a change through only if the confidence lower bound is above zero in the critical categories; otherwise it sends the candidate back to run again.
  6. The failure press turns failing runs into new rules, memory-ranking signals and skills, and queues them as the next candidate.
443 vs. 2,463
Regressions vs. improvements in Pane's illustrative shadow test of a prompt half the size (his worked example) Alvin Pane
$29
What Voss says his 2,300 test calls across seven models cost, showing context research can be cheap Laurie Voss
~$600
What Towards AI says its compaction evals cost to run (reported) Samridhi Vaid
  • Voss says the old hard part was fitting instructions in; now it is verifying the model followed them, and the answer is checking the output with an eval each time. Laurie Voss
  • Voss cites a 46-model paper: a model can ace a benchmark yet rewording or reordering the same instructions can swing how well it follows them. Laurie Voss
  • Arize runs agents through Harbor in sandboxes with 1/0 verifiers across permutations and tracks pass@k, because the same task can flake. Mikyo King

When it breaksAn impossible eval burns tokens. Martin says that with a poorly specified eval where the last 20% is unsolvable, the hill-climbing agent burns huge numbers of tokens chasing it. Lance Martin

Open questionCan you let an optimizer or the model rewrite your prompts?

  • Yes: an optimizer cut instruction tokens 51%, then paired shadow tests with confidence intervals checked quality held Alvin Pane
  • Carefully: prompts are very easy to overfit, since the model wiggles them into shapes that win the eval but do not match production Lance Martin

Sources

the 24 newest of 49

More in Context Engineering & Memory

The Library: the whole area
  • Long ContextModels that read very long inputs (hundreds of thousands to millions of tokens).
  • Retrieval-Augmented GenerationFetching relevant documents at question time and putting them in the prompt.
  • EmbeddingsVectors that place similar meanings near each other, used for search and clustering.
  • Agent MemoryLetting agents keep and recall information across sessions.
  • Prompt EngineeringWriting instructions and examples that steer a model's behavior.
  • Prompt CachingReusing computation for repeated prompt prefixes to cut cost and latency.
  • Knowledge GraphsStoring facts as linked entities so agents can traverse relationships.