Context engineering for AI agents, explained
Context engineering is the work of deciding what an AI model sees at each step: the instructions, the tool descriptions, the retrieved documents, the earlier turns and the results of tools it has already run. Anthropic defines it as "the set of strategies for curating and maintaining the optimal set of tokens (information) during LLM inference" (Anthropic, September 29, 2025). Prompt engineering is about the wording of one request. Context engineering is about everything else in the window, and for an agent that runs for an hour and calls a hundred tools, everything else is most of it.
Where the term came from
The phrase spread in June 2025. Shopify's CEO Tobi Lütke wrote on June 19 that he preferred "context engineering" to 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." Andrej Karpathy agreed six days later, arguing that people associate prompts with short task descriptions, while in "every industrial-strength LLM app, context engineering is the delicate art and science of filling the context window" with the right information for the next step.
LangChain followed in July with a post that sorted the techniques into four groups: write, select, compress and isolate. Those four are still a useful map.
Why more context is not better
Context windows have grown to hundreds of thousands of tokens, so it is tempting to put everything in. Anthropic's post explains why that backfires: "as the number of tokens in the context window increases, the model's ability to accurately recall information from that context decreases." Anthropic points to what researchers call context rot, and its working rule is to find "the smallest possible set of high-signal tokens that maximize the likelihood of some desired outcome."
Cost points the same way. Every token in the window is paid for on every turn, so a 40,000-token log pasted in early is billed again on each of the next fifty steps, at a reduced cached rate at best, unless something removes it.
The four strategies
Write: keep notes outside the window. The agent saves what it learns to files or memory and reads it back later. Anthropic calls this "structured note-taking, or agentic memory". It lets a long task survive the moment the window fills up; our post on AI agent memory covers how agents keep information between sessions.
Select: pull in only what the step needs. Instead of loading every document up front, the agent keeps "lightweight identifiers (file paths, stored queries, web links, etc.)" and loads the data with a tool when it needs it. Anthropic calls this just-in-time retrieval. Retrieval from memory, tool search and skills that load on demand are all forms of selection.
Compress: shrink what is already there. Compaction means "taking a conversation nearing the context window limit, summarizing its contents, and reinitiating a new context window with the summary." Trimming long tool output is a simpler kind of compression.
Isolate: give separate jobs separate windows. A sub-agent explores in its own context and returns a short result. In Anthropic's description, each sub-agent "might explore extensively, using tens of thousands of tokens or more, but returns only a condensed, distilled summary of its work (often 1,000-2,000 tokens)."
Context engineering vs prompt engineering
A prompt is written once, by a person, before the work starts. Context is assembled again on every turn, and much of it is chosen by the agent itself through the tools it calls: a search result here, a file it opened there, a summary of what happened an hour ago. That is why the work looks more like system design than copywriting. A clear task description still matters. It is one input among many, and usually not the largest.
What this looks like in a running agent
The strategies are easier to judge with real numbers. Here are the defaults Neotask's agent runtime ships with, as of late November 2026.
| Strategy | What Neotask does | Default |
|---|---|---|
| Write | Before heavy compaction, the agent gets a turn to write anything worth keeping to memory | Runs ahead of compaction |
| Write | Workspace files such as AGENTS.md, USER.md and MEMORY.md hold standing instructions and notes | 12,000 characters per file, 60,000 in total |
| Select | Skills are listed by name; the agent reads a skill's full SKILL.md only when the request matches it | At most one skill read up front |
| Select | Memory search mixes meaning and keyword matching over memory files | 70% vector, 30% keyword, 6 results |
| Select | Standard operating procedures relevant to the task are attached automatically | Every task, chat and coding action |
| Compress | A live tool result is cut down, with a way to read the rest | 16,000 characters, and no more than 30% of the window |
| Compress | A summary of older history is built in the background and swapped in at a turn boundary | Swaps in at 70% full, or at 150,000 tokens on very large windows; keeps the last 20,000 tokens verbatim |
| Isolate | The agent can start sub-agents for delegated work with sessions_spawn | Depth-limited |
Two details from that table matter for any agent, not only Neotask's. First, the summary is built in the background ahead of time and swapped in between turns, instead of being written at the moment the window runs out. Second, compaction keeps the most recent 20,000 tokens word for word. Summaries lose detail, and the latest turns are usually the ones the next step depends on.

The Usage page shows where tokens go each day, by agent and by model provider, so a jump in one agent's tokens is easy to spot.
Prompt caching sits beside all of this. Neotask marks where the stable part of the prompt ends so providers can cache it, with cache lifetimes of five minutes or an hour. A stable prefix (system prompt, tool list, standing files) is cheaper on every turn, which is one more reason to keep volatile content out of it. For the loop that reads all of this on each turn, see how AI agents work.
How to apply it to your own agents
You do not need to build a runtime to use these ideas. Much of it comes down to what you put in front of the agent, and how.
- Keep standing instructions short and specific. A 300-line instruction file is read on every turn. Move rarely needed procedures into separate documents the agent opens when the task calls for them.
- Give the agent identifiers, not dumps. "The Q3 report is in Drive under Finance/Reports" costs a few tokens. The report itself costs thousands and may never be needed.
- Ask for notes on long jobs. For work that runs past one session, tell the agent to keep a running file of decisions and open questions. That file survives compaction and the next session can start from it.
- Split exploration from execution. Research that reads fifty pages belongs in a sub-agent that returns a summary, so the main agent's window holds conclusions instead of raw pages.
- Trim tool output at the source. A tool that returns 200 rows when the agent needed 5 wastes the window on every later turn. Filters and limits in the tool call are cheaper than any compression afterwards.