Context engineering is the practice of deciding, at every step an AI system takes, exactly which pieces of information — instructions, past messages, retrieved documents, tool results — get placed into a model’s limited working memory, and which get summarized, stored elsewhere, or left out entirely. It grew out of prompt engineering but covers a much bigger job: instead of polishing one block of text, it manages an entire, constantly shifting pool of information across a task that might run for many steps.
What Counts as Context
Every piece of information a model sees before it responds counts as context: system instructions, the conversation so far, descriptions of the tools it can call, documents pulled in through retrieval, and the results of steps it has already taken. All of it competes for space inside the model’s context window — the fixed number of tokens it can process at once.
For a single question and answer, fitting everything in is trivial. The problem shows up with AI agents that run for many steps in a row: each tool call, file read, or search result adds more tokens, and past a certain point the window fills up — or worse, fills with information that is stale, repetitive, or contradictory.
The Four Moves: Write, Select, Compress, Isolate
A framework popularized in a widely read 2025 engineering post from LangChain breaks the discipline into four recurring moves. Write means saving information outside the active context — a scratchpad file, a memory store — so it can be pulled back in later instead of sitting in view the whole time. Select means retrieving only the piece that’s actually needed at a given step, rather than loading everything up front. Compress means summarizing or trimming material once its full detail is no longer required, keeping the gist while freeing up tokens. Isolate means splitting a large task across multiple focused agents or sandboxes, each working with its own narrow context, so one agent’s clutter doesn’t spill into another’s.
Anthropic’s own engineering guide, published around the same time, describes concrete versions of these ideas in its own agent-building work: agents that write persistent notes to a file instead of holding everything in memory, “compaction” that summarizes a long conversation before it hits the context limit, and sub-agents that hand back a short summary of a few thousand tokens to a coordinating agent instead of their full working history. Tool design matters here too — a system built around the Model Context Protocol still needs each tool description kept short and non-overlapping, since bloated tool definitions eat into the same limited space as everything else.
Why It Matters: Context Rot and the Attention Budget
Two practical problems justify the extra engineering. First, measured model performance degrades as a context window fills up — researchers call this pattern context rot: a model that recalls a fact perfectly in a short prompt can miss the same fact once it’s buried among tens of thousands of other tokens. Second, attention itself is a limited resource. A transformer weighs every token against every other token, so as the context grows, that computation — and the model’s practical ability to track what actually matters — gets stretched thinner, especially since most training happens on shorter sequences than production agents actually use.
Badly managed context does not just waste money on unnecessary tokens; it can make an agent lose track of an earlier instruction, repeat a mistake it already made, or act on data that is no longer accurate. For anyone building a customer-support bot, a coding assistant, or a research tool on top of a large language model, the job is now as much about curating what the model sees as it is about telling it what to do.
Context Engineering vs. Prompt Engineering
The two are related but not the same. Prompt engineering is about crafting a single, well-worded instruction for a one-off task. Context engineering is the ongoing discipline of managing everything that surrounds that instruction — memory, retrieved data, tool descriptions, prior steps — across a task that can run for minutes or hours. The distinction matters most for anyone building agents rather than simple chatbots: a good prompt cannot compensate for a context window cluttered with irrelevant or conflicting information, and a perfectly clean context still needs a clear instruction to act on. Developers building long-running coding agents run into this directly — as a session grows, keeping an agent’s context lean and current becomes as important as the initial instructions were.
Anyone building an agent today can go deeper with Anthropic’s engineering guide to context engineering, which walks through the write, select, compress, and isolate techniques in more technical detail.