What it is
Context engineering is the craft of deciding what information an AI model gets to see before it answers. Not just the question you type, but everything around it: the standing instructions, the documents you attach, the examples you show, the conversation so far, the results of any searches or tools the AI has used, and anything it has been told to remember about you.
A useful way to picture it: a prompt is the question you ask a new assistant. Context is the folder you hand them along with it. You can phrase the question beautifully, but if the folder holds last year's price list, three irrelevant reports, and no example of what a good answer looks like, the answer will be poor. And if the folder is so thick that the one page that matters is buried on page 212, the answer may be poor too.
The model only knows two kinds of things. The first is what it learned in training, which is general, fixed, and often out of date. The second is whatever is sitting in its context window right now, the limited working space for this one conversation or task. Everything specific to you, your business, your book, your customer, or today's date has to arrive through the second route. Context engineering is the job of choosing what goes into that space, in what shape, in what order, and what stays out.
The context usually has six kinds of ingredient:
- Instructions. What the model should do and how. This includes the system prompt, the standing instructions set by the app or by you, and the specific request.
- Documents and facts. The material the answer should be based on: a policy, a chapter, a spreadsheet, a product sheet. Feeding in trusted material and asking the model to stick to it is called grounding.
- Examples. A few samples of the output you want. Showing beats describing, which is the whole idea behind few-shot prompting.
- History. The conversation so far, including the model's own earlier replies, mistakes and all.
- Tool results. When an AI searches the web, reads a file, or queries a database, what comes back is pasted into its context. An AI agent working on a long task can pile up a lot of this.
- Memory. Notes carried over from earlier sessions, such as "the user writes in British English" or "the manuscript is a cosy mystery". Products that offer memory are quietly choosing which of these notes to put back in front of the model.
The work itself comes down to four decisions. Choosing: which of all the things you could include actually help with this task? Trimming: can a 40-page document become the three pages that matter, or a long chat become a short summary? Ordering and labelling: which comes first, and can the model tell your instructions apart from the material it should read? Leaving out: what is stale, contradictory, or merely distracting?
That last point surprises people. It seems natural that more information would always help, since the model can simply ignore what it doesn't need. In practice, it often can't. Irrelevant material competes for the model's attention, outdated facts clash with current ones, and a mistake left in the history can be repeated again and again. Anthropic's engineers put the goal as finding "the smallest possible set of high-signal tokens" (high-signal meaning genuinely useful) that makes a good result most likely. Tokens are the small chunks of text models read, so in plain words: the least text that does the most work.
Why it matters
Wording has limits; information doesn't. People spent the first years of chatbots hunting for magic phrases. Those help at the margins, but no phrasing can make a model know your refund policy, your character's eye colour, or what your client said last Tuesday. Most disappointing AI answers are not a wording problem. They are a missing-information problem, or a too-much-information problem.
It's why the same model gives one person junk and another person gold. Two people ask for a sales email. One types a single line. The other pastes a short description of the product, the customer's actual message, two past emails that worked, and a note on tone. Same model, same afternoon, very different results. The difference is almost entirely context.
It matters more as AI does longer jobs. A chatbot answering one question has a small, tidy context. An agent that researches, writes, checks, and revises for an hour fills its context with search results, file contents, drafts, and notes to itself. Unless something manages that pile, the agent slows down, costs more, and starts to lose the thread. Much of the recent engineering work on agents, including subagents, summaries of old history, and notes stored outside the window, is context engineering under another name.
It saves money and time. Anyone paying for AI by usage pays for every token in the context, on every turn. Sending a whole manual when a single page would do is slow and expensive. Techniques like RAG, which looks up the few relevant passages in a larger library and inserts only those, exist largely to keep the context lean.
It makes results repeatable. If you rely on luck, some days are good and some are bad. If you know which ingredients produce a good answer, you can supply them every time, save them, and hand them to a colleague.
Real-world examples
The name catches on (June 2025)
The phrase "context engineering" had been used here and there before, but it took off in a single fortnight in June 2025. On 12 June, Walden Yan of Cognition, the company behind the coding agent Devin, published an essay titled "Don't Build Multi-Agents". He described context engineering as the next level beyond prompt engineering, and argued that when an AI task is split between several agents that can't see each other's work, they make conflicting choices. His first principle was to share context, including the full record of what each agent did, not just individual messages.
A week later, Shopify's chief executive, Tobi Lütke, posted on X that he preferred the term over prompt engineering, because "It describes the core skill better: the art of providing all the context for the task to be plausibly solvable by the LLM." (An LLM is a large language model.) The post went out on 19 June by the world clock, the evening of 18 June in North America. On 25 June, the AI researcher Andrej Karpathy added his support, calling it "the delicate art and science of filling the context window with just the right information for the next step". He also pointed out that people tend to hear "prompt" as the short task description you'd type in daily use, while serious AI apps involve far more than that.
Two days later the developer and writer Simon Willison predicted the term would stick, because its meaning is closer to what people guess it means than "prompt engineering", which many had come to see as a fancy name for typing into a chatbot. On 2 July, LangChain, the company behind a popular toolkit for building AI apps, published a guide sorting the techniques into four groups: write (save information outside the window for later), select (pull the relevant pieces in), compress (keep only the tokens the task needs), and isolate (split the work so no single context carries everything). On 29 September 2025, Anthropic published "Effective context engineering for AI agents", which described context as a finite resource with an "attention budget" and laid out techniques such as compaction, where a conversation nearing the limit is summarised and continued in a fresh window.
The shift in wording reflects a real shift in the work. Prompt engineering is about the message. Context engineering is about the whole package the model receives, much of which, in a modern app, is assembled automatically rather than typed by a person.
An AI plays Pokémon and poisons its own notes (2025)
One of the clearest public records of context going wrong comes from Google DeepMind's technical report on Gemini 2.5, published in July 2025. It describes Gemini Plays Pokémon, a livestream set up by Joel Zhang, an independent developer not affiliated with Google, in which Gemini 2.5 Pro played the original Game Boy game Pokémon Blue using an agent setup that kept goals, summaries, and notes in its context. On 2 May 2025 it finished the game after 813 hours.
The report is frank about the failures. At one point in Pokémon Blue, the player has to buy a drink from a vending machine for a thirsty guard. In the later remakes, the guard wants a special TEA item instead, which doesn't exist in Blue. The model repeatedly became convinced it needed the TEA and, in the report's words, spent "many, many hours" trying to find it. Because the false belief was written into its goals and summaries, it kept being fed back in. The report calls this "context poisoning": misinformation spread through several parts of the context, which could take a long time to undo and left the model fixated on impossible or irrelevant goals. It also noted that as the context grew well beyond 100,000 tokens, the agent tended to repeat actions from its long history rather than come up with new plans.
On 22 June 2025, the writer and technologist Drew Breunig used the Pokémon case to open a post called "How Long Contexts Fail", which named four failure modes that have since become common vocabulary:
- Context poisoning: an error or hallucination gets into the context and keeps being referred to.
- Context distraction: the context grows so long that the model leans on it too heavily and neglects what it learned in training.
- Context confusion: unneeded material in the context gets used anyway and drags the answer down.
- Context clash: new information or tools conflict with things already in the context.
For confusion, Breunig cited a study in which a small Llama 3.1 model failed a task when given 46 tools to choose from, but succeeded when given only 19, even though everything fitted comfortably in its window. More options made it worse, not better.
Chatbots get lost in long conversations (May 2025)
In May 2025, researchers from Microsoft Research and Salesforce Research, led by Philippe Laban, published "LLMs Get Lost In Multi-Turn Conversation". They took tasks that models handled well when everything was stated in one message, then fed the same information in pieces over several turns, the way people actually chat. Across six kinds of task, performance dropped by 39 percent on average.
The cause was a context problem. Models made assumptions in early turns and tried to produce a full answer before they had all the facts, then leaned on those early attempts. The wrong guesses stayed in the history and shaped everything that followed. The researchers' advice to users was practical: if a conversation goes off track, starting a new one that repeats the same information may work much better than continuing, and it helps to ask the model to consolidate everything you've said so far, then paste that summary into a fresh chat. That is context engineering by hand: trimming a messy history down to a clean brief.
Sharing context versus splitting it (June 2025)
The day after Cognition's essay, Anthropic published an account of the multi-agent research system behind Claude's research feature. A lead agent sends subagents off to explore different parts of a question, each in its own context window, and they return condensed findings. Anthropic reported that this setup outperformed a single Claude Opus 4 agent by 90.2 percent on its internal research test, and also that multi-agent systems used about 15 times as many tokens as ordinary chats.
The two posts are often presented as opposites, but they agree on the core point. Cognition warned that splitting a task loses shared context and causes conflicting decisions. Anthropic used splitting precisely to keep each context small and focused, with the lead agent receiving only the distilled results. Both are arguments about who needs to see what, which is the central question of context engineering. The right answer depends on the task: research that breaks into independent questions suits splitting, while building one coherent thing, like a single program or a single novel, usually needs one shared picture.
An everyday scenario: the newsletter that finally sounded right
This is an illustration, not a documented case. A garden-centre owner asks a chatbot each week to write her customer newsletter. Her prompt is carefully worded, but the results sound like any garden centre anywhere. One week, instead of rewording the prompt again, she changes what she gives it: a five-line note on her voice (warm, a bit cheeky, never says "must-have"), two past newsletters customers replied to, and this week's facts (the tulip delivery, the Saturday workshop, the closing time change). She also deletes a line from her old prompt listing twenty possible topics, which kept dragging in things she wasn't selling. The prompt barely changed. The context did, and the newsletter finally sounds like her.
Try it yourself
You need any AI chatbot and a task you do regularly, such as a weekly email, product descriptions, social posts, or chapter summaries. Allow half an hour. You'll build a "context pack": a short, reusable bundle of the information the AI needs for this task, and compare results with and without it.
- Pick one recurring task. Something you've asked an AI to do more than twice and weren't fully happy with.
- Run a baseline. Open a fresh chat and ask for the task the way you usually would, in one or two lines. Save the result.
- Write a style sheet of five to eight lines. Who the audience is, the tone, words you use and words you never use, typical length, and any formatting habits. Short, specific rules beat long essays.
- Choose two examples. Pick two real pieces you've written for this task that you're proud of. Two is usually enough; more can make the AI copy them too closely. Choose two that differ from each other, so it learns the style rather than one template.
- List the key facts. Only the facts this particular piece needs: names, dates, prices, details. Leave out anything that's merely nice to know.
- Assemble the pack with clear labels. Put the reference material first and the request last, and label each part so the AI can tell them apart. Headings work, and so do XML tags. Copy this layout:
Below is my context pack for this task. Read it all before answering.
<style_sheet>
[your five to eight lines]
</style_sheet>
<example_1>
[a past piece you like]
</example_1>
<example_2>
[another past piece, different from the first]
</example_2>
<key_facts>
[only the facts this piece needs]
</key_facts>
Task: [the same request you used for the baseline]
Use only the facts in key_facts. If something you need is missing, ask me instead of inventing it.
- Run it in a fresh chat and compare. Put the baseline and the new version side by side. Which sounds more like you? Which has fewer invented details? Which needed less editing?
- Trim and test. Now remove one part of the pack, say the second example, and run it again. If quality holds, you didn't need it. If it drops, it stays. This is how you learn which ingredients actually earn their place.
- Save the pack. Keep it in a note or document. Many chatbots also have a "projects" or custom instructions feature where a pack like this can be stored and reused; features and their limits vary by product and change often, so check what yours offers at the time of reading.
If a long chat has gone off track, try this before you start again:
Summarise everything I've told you in this conversation that matters for the task:
the goal, the facts, my preferences, and any decisions we've made.
Leave out anything we tried and rejected. Write it as a brief I can paste into a new chat.
Then open a fresh chat, paste the brief, and continue from there. You've just done compaction by hand.
Common mistakes and misunderstandings
"More context is always better." It isn't. Irrelevant material distracts, outdated material contradicts, and a very long input is read less reliably than a short one. The model can see everything in the window, but that doesn't mean it weighs everything well. Include what the task needs and stop.
Thinking it's only for developers. The term came from people building AI products, and much of the writing about it is technical. But anyone who attaches a file, pastes an example, or starts a fresh chat to clear out a muddled one is doing context engineering. The principles are the same with a chatbot as with a complex agent.
Treating it as a replacement for good prompts. Context engineering includes the prompt; it doesn't abolish it. Clear instructions still matter. They're simply one ingredient among several, and often not the one causing the problem.
Leaving mistakes in the history. If the AI got a fact wrong three messages ago and you corrected it, the wrong version is still in the conversation. It may resurface. For anything important, start a new chat with a clean summary rather than correcting the same error over and over.
Pasting a whole document when a section would do. Giving the model a 200-page report to answer a question about one chapter makes the job harder, not easier. Cut to the relevant part, or ask the AI to find it first and then answer from only that part.
Mixing instructions into the material. If your instructions sit in the middle of pasted text, the model can confuse what to read with what to do. Worse, text inside a document can be mistaken for instructions. Keep the two clearly separated and labelled.
Giving too many examples, or examples that are all alike. A dozen near-identical samples teach the model to copy one pattern, including its quirks. A couple of good, varied examples usually do more.
Forgetting that memory is context too. When a chatbot remembers things about you, those notes are being added to its context, whether or not they fit today's task. If answers keep drifting towards an old project, check what the product has stored and clear anything stale.
Assuming a bigger context window fixes everything. A larger window means more fits, not that more gets used well. The need to choose doesn't go away as windows grow; if anything, the temptation to include everything makes it more important.
Related elements
- Context Window: the limited space that context engineering is filling.
- Prompt: the request itself, one ingredient within the wider context.
- System Prompt: the standing instructions that sit at the top of every conversation.
- Few-shot: adding worked examples, one of the most effective things to put in context.
- XML Tags: labels that keep instructions, documents, and examples clearly apart.
- Grounding: tying answers to trusted material you supply.
- RAG: fetching only the relevant passages from a large library and adding those to the context.
- Memory: notes carried between sessions, which a product chooses to put back into context.
- Subagents: helpers with their own clean context windows, used to keep the main one focused.
- Summarization: the tool behind compaction, shrinking long history into a short brief.
- Prompt Templates: a fixed layout with slots, a natural home for a reusable context pack.
- Tokens: the units every piece of context is measured and paid for in.
- Hallucination: what often happens when the facts the model needs aren't in its context.
- Agent: the kind of AI system where managing context matters most.