Blog

Context engineering, or deciding what your AI should know

Context engineering is deciding what an AI model sees each time it answers: its instructions, the tools it can call, what it remembers about the user, passages from documents and the conversation so far. The model knows only what is in its context window, and every extra token costs money and attention. The goal is to give the model what the task needs and leave out the rest.

We build CrystalBrain, one memory that your AI apps share. Assembling the memory part of that context is our daily work, and the last section shows how we do it.

What is context engineering?

Context engineering is the practice of choosing and maintaining all the information an AI model receives when it runs. The prompt you write is one part of it. Anthropic defines it as “the set of strategies for curating and maintaining the optimal set of tokens (information) during LLM inference” (Anthropic Engineering, September 2025, checked November 24, 2026).

The term spread in June 2025. Shopify’s CEO Tobi Lütke wrote that he preferred it to prompt engineering because it describes “the art of providing all the context for the task to be plausibly solvable by the LLM”. Andrej Karpathy agreed and called it “the delicate art and science of filling the context window with just the right information for the next step” (both quoted by Simon Willison, June 27, 2025).

The words “for the next step” matter. An agent that works through a task calls the model many times, and the right context changes at each call.

How is context engineering different from prompt engineering?

Prompt engineering is writing good instructions. Context engineering decides everything else that sits next to them, again for every request. Anthropic describes prompt engineering as “methods for writing and organizing LLM instructions for optimal outcomes”. Context engineering, in their words, “is iterative and the curation phase happens each time we decide what to pass to the model”.

Take a support assistant inside a SaaS product. The prompt says how to answer, for example the tone, the format and when to hand over to a person. You write it once and change it now and then. The context differs for each message. For “Can I get a refund on my annual plan?”, the model needs the refund policy, the customer’s plan and start date, and the language they prefer. It does not need the rest of the help center, the customer’s old tickets about other problems, or the definitions of tools it will not use.

So prompt engineering is part of context engineering. A good prompt still fails when the facts around it are missing, out of date or lost among unrelated text.

What goes into an AI model’s context?

Everything the model reads in one request. Anthropic lists “system instructions, tools, Model Context Protocol (MCP), external data, message history” as parts of the context an agent has to manage. In practice, a request is built from six kinds of content:

  • Instructions. The system prompt holds the rules and a few examples.
  • Tool definitions. Each tool the model may call has a name, a description and parameters, tools from MCP servers included.
  • Memory. The app adds what it knows about this user or this task from earlier sessions.
  • Retrieved documents. A search adds passages from a knowledge base, a wiki or uploaded files.
  • Conversation history and tool results. They record what was said and done so far in the session.
  • The request. This is the user’s message.

Each kind changes at its own pace. Instructions stay the same for weeks. Memory changes when the user tells you something new. Retrieved passages and tool results change with every request. That pace tells you where each piece belongs, as the section on deciding what to include shows.

Why can more context make answers worse?

Models do not read a long context equally well from start to end. Anthropic calls the effect context rot. In their words, “as the number of tokens in the context window increases, the model’s ability to accurately recall information” goes down. Their conclusion is that “context, therefore, must be treated as a finite resource with diminishing marginal returns”.

Chroma’s 2025 report Context Rot measured the effect. The authors found that “model performance varies significantly as input length changes, even on simple tasks”. The common assumption is that a model handles “the 10,000th token just as reliably as the 100th” (Hong, Troynikov and Huber, Chroma, July 2025).

The second limit is cost. The provider bills every input token, and whatever you put in the context is sent again with each request of the session. Our token counter for Claude splits a request into system prompt, memory, history and message, and shows what each part takes from the window and from your bill.

A larger context window removes neither limit. You can send more, but the model still has to find the few facts that matter among everything else you sent, and you pay for all of it.

What are the main context engineering strategies?

LangChain sorts the techniques into four groups: write, select, compress and isolate (langchain-ai/context_engineering, checked November 24, 2026). Anthropic’s guide describes several of the same techniques with examples from its own products. The table puts the two together, with what each strategy looks like in CrystalBrain.

StrategyWhat it doesExample from Anthropic or GoogleIn CrystalBrain
WriteSaves information outside the context window to help with a taskIn structured note-taking, the agent writes notes to a memory outside the window and reads them back laterYour AI apps save memories through MCP or the REST API
SelectPulls information into the context window when the task needs itClaude Code loads CLAUDE.md files up front and finds other files with glob and grep when needed. Gemini’s Tool Retrieval loads a tool’s full schema only when the model asks for itA search returns only the memories and document passages close to the request
CompressKeeps only the tokens the task needsCompaction summarizes a conversation that nears the window limit and starts a new window with the summary. Tool result clearing removes old tool outputsOne short line per memory, and near-duplicates left out of the answer
IsolateSplits the context across separate unitsSub-agents work in clean context windows and return a condensed summary of their workOne memory per user, and one brain per topic
Four context engineering strategies, as LangChain names them, with examples from Anthropic’s and Google’s documentation, checked November 24, 2026.

Select only what the request needs

Anthropic recommends a “just in time” approach. The agent keeps “lightweight identifiers” such as file paths, stored queries or web links, and loads the data behind them with tools when it needs it. Google applied the same idea to tools. Tool Retrieval, in preview in the Gemini Interactions API since November 19, 2026, keeps a large tool library out of the prompt. The model “still sees the name and description of every deferred tool”, and the API loads a tool’s full schema when the model asks for it (Google). Google gives no savings figure and advises measuring on your own traffic.

Compress what stays

Compaction is for long sessions. Instructions sent with every request are a different case. The same text is paid again on every call, so shortening it once saves on all of them. Our prompt compressor rewrites a prompt as compact Markdown and lists any number, address or identifier it cannot find in the result, so you can check that no rule was lost.

Isolate unrelated work

A sub-agent that reads fifty files to answer one question returns a summary, not the fifty files. Knowledge works the same way. Facts about one client should not end up in a request about another client.

How do you decide what goes into the context?

Start from the task, then sort each piece of information by how often it changes and how often it is needed. Anthropic’s guiding principle is to find “the smallest set of high-signal tokens that maximize the likelihood of your desired outcome”. Five steps get you there.

  1. List what the task needs. Write down what a capable new colleague would need to know to handle the request. Anything not on the list is a candidate to leave out.
  2. Put stable rules in the instructions. Tone, format and limits that apply to every request belong in the system prompt. Anthropic asks for clear, direct language at the “right altitude”. The prompt should be specific enough to guide the model, without hard-coding every case.
  3. Send what matters about the user every time. A few facts shape every answer, such as the user’s language or a limit like “never suggest paid tools”. A search may not find them, because they are rarely close in meaning to the request. Send them with every request, and keep them short.
  4. Search for the rest. Memories and document passages that matter for some requests only should come from a search. Filter it by user and by topic, and set a minimum relevance so off-topic entries stay out.
  5. Measure and prune. Log what each request contained, in tokens, and check which pieces the model actually used. Entries that are never used, or that repeat each other, can go.

Step 4 is where long-term memory comes in. Our guide to how AI memory works in agents and apps covers how a memory is written, stored and searched. Context engineering decides how much of it reaches the model, and in what order.

How we assemble context in CrystalBrain

CrystalBrain is one memory your AI apps share. Claude, ChatGPT, Gemini, your agents and your own app read and write it, and you can see and fix every memory. When an app searches the memory of one user, it gets back one block of text to add to its context, the context block. We built the context block with the steps above, and changed it as we watched real searches.

1Profile card
Who the user is, in up to 10 lines
2Brain framing and summary
How to behave on this topic
3Standing rules
The user’s hard limits, every time
4Memories
Those close to the request, one line each
5Document passages
Up to 4, from the user’s files
The order of the context block that a CrystalBrain search returns. The brain’s framing and summary come only when the search is limited to one brain.
  • Profile card. The card holds a few lines on who the user is: role, company, language and lasting preferences. Claude writes it at night from the user’s memories, or you type it on the user’s page in the dashboard. It is capped at 10 lines and 800 characters, about 200 tokens, and opens the context block. We added it because a preference like “answers in French” is never close in meaning to the request it should shape.
  • Brain framing and summary. A brain is one topic of a user, such as a client, a market or a product. When a search is limited to one brain, the brain framing comes first. It says how the AI should behave on this topic. The brain summary follows, then the memories. The brains page of the user guide shows where to write both.
  • Standing rules. Memories of type constraint are the user’s hard limits. Up to five come back with every search, whatever the request says, unless the search is filtered by type or tag.
  • Memories. A search returns 8 memories by default and 20 at most. A memory below a minimum relevance is left out, and so is one that says almost the same thing as a better-ranked memory. Each memory takes one line, with its type and its brain. A long request can mix several topics, which lowers the relevance of a memory about only one of them. So a memory that contains a name from the request, such as a person, a company or a ticket code, is kept with a lower minimum relevance.
  • Document passages. Files attached to a brain are cut into passages of about 1,200 characters. A search adds up to four of them, and only those close enough to the request, so many searches return none.

On the Insights page, Tokens per search shows what CrystalBrain sent per search, as a median and as the level that one search in ten exceeds. It is an estimate, at about four characters per token. We explain how to read it in measuring whether your AI memory works.

CrystalBrain covers one part of the context, what the AI knows about the user and their topics. The system prompt, the tool definitions and the conversation history stay in your app or your assistant. Through MCP, the assistant decides when to search, so the instruction from the Connections page matters. Your own code can call the REST API before every answer instead. The CrystalBrain home page describes the product and its plans, including the free plan.

FAQ

Is context engineering the same as RAG?

No. RAG, or retrieval-augmented generation, is one technique within it: a search that adds document passages to the prompt. Context engineering also decides the instructions, the tools, the memory and the history, and how much of each the model gets.

Does context engineering replace prompt engineering?

It includes it. Writing clear instructions is still the first step. Context engineering adds the choice of everything else the model reads, made again for every request.

What is context rot?

Context rot is the drop in a model’s accuracy as its input grows longer. Chroma’s 2025 report found that performance varies significantly with input length, even on simple tasks. It is the main reason to keep the context short rather than send everything the window can hold.

Does a bigger context window make context engineering unnecessary?

No. A bigger window lets you send more, but every token is still billed on each request, and accuracy still drops as the input grows. Choosing what to send matters as much with a large window as with a small one.

Sources

Free up to 25 tracked users, no card.

Start free