All AI guides
Buyer's guide13 min read

Context Engineering, Explained: What It Is and How to Do It in 2026

Context engineering is the practice of choosing which system instructions, tools, examples, history and retrieved data enter an LLM context window at each inference step. Anthropic defines it as finding the smallest set of high-signal tokens that makes the desired behavior likely, because accuracy drops as context grows.

The short version

Context engineering means curating the tokens a model sees at every step, not just writing a good prompt. Keep the window small, stable and fetched on demand, use compaction, notes and sub-agents for long jobs, and skip all of it for short chats that a person reviews.

Want this decided for your own case? Find your tools with Smart Match, starting from this guide's question.

In July 2025, the team behind Manus said it had rebuilt its agent framework four times, and each rewrite changed what the model reads, not what the model is. That is context engineering in one sentence. It is the work of deciding which tokens sit in front of a language model at every step of a task.

Anthropic's applied AI team put it as a shift from finding the right words for a prompt to answering a wider question: what configuration of context is most likely to produce the behavior you want. This guide explains the idea, the techniques that hold up in production, the tools that do each job, and the point where you should skip all of it.

Context engineering is choosing what the model reads on every turn

A prompt is one block of text you write once. Context is everything the model sees when it generates a reply: the system instructions, the tool definitions, the examples, the message history, files, search results and whatever your tools return.

Anthropic's engineering post draws the line this way. Prompt engineering covers writing and organizing instructions. Context engineering covers the whole set of tokens at inference time, including everything that arrives from outside the prompt.

The distinction matters because agents run in loops. An agent that calls tools generates new data on every turn, and some of it could be useful on the next one. Someone has to decide what stays, what goes and what is fetched again.

That someone is you, and the decision repeats on every step. Prompt engineering is a draft you polish. Context engineering is a process you run.

Three practical consequences follow:

  • Your prompt is now one input among several, and often not the largest one.
  • Tool output can fill the window faster than anything you typed.
  • Quality problems that look like "the model got dumber" are often a context that grew past the point where the model could use it.

If you build with one of the orchestration frameworks, you are already making these choices, whether the framework shows them or hides them.

Why a bigger window does not fix a messy context

The obvious answer to a crowded window is a larger window. It does not work, and the reason is measurable.

Chroma's July 2025 technical report, titled Context Rot, tested 18 models, including GPT-4.1, Claude 4, Gemini 2.5 and Qwen3. Its authors found that performance grows less reliable as input length grows, even on simple tasks. The report says models do not use their context uniformly.

Anthropic's post gives a mechanism. Every token can attend to every other token, which produces n² pairwise relationships for n tokens. As the window grows, that attention gets stretched thin. Models also train mostly on shorter sequences, so they have less practice with dependencies that span a whole long window.

The result, Anthropic says, is a gradient and not a cliff. Models stay capable at long lengths but lose precision on retrieval and long-range reasoning. Its term for the budget is "attention budget": each new token spends some of it.

Manus reached the same place from the practical side. Its post lists three pain points with large windows: observations from web pages and PDFs can blow past the limit, performance degrades beyond a certain length, and long inputs are expensive even with caching.

So the working rule is the one Anthropic states: find the smallest set of high-signal tokens that makes the desired outcome likely. Smallest does not mean shortest. It means nothing in the window that is not earning its place.

For a sense of how window size and price interact across models, read the guide to the Claude 1M-token context window and the cheapest LLM API comparison.

How to decide what goes into the window

Before you reach for a tool, run each component of your context through four questions. This is the part of context engineering that costs nothing and fixes the most.

  1. Needed every turn, or only sometimes? Every-turn items go in the system prompt. The rest sit behind a tool call.
  2. Can the model fetch it later from a stable pointer? A file path or URL costs a handful of tokens. The full page costs thousands.
  3. Would a person on your team know when to use it? Anthropic's test for tools: if a human engineer cannot say which fits, the agent will not do better.
  4. What breaks if it is wrong or stale? Old tool results are the usual offender.

Then apply the five components in turn. Anthropic's post gives specific guidance for each:

  • System prompt: clear, direct language at "the right altitude", between brittle hard-coded logic and vague guidance.
  • Tools: self-contained, with minimal overlap. The post names bloated tool sets as a common failure mode.
  • Examples: a small set of diverse, canonical ones beats a long list of edge cases.
  • Message history: keep it tight, and clear raw tool results once they have been used.
  • Retrieved data: load it just in time, not up front, wherever the task allows.

This is also where model choice enters. A model with a larger window forgives sloppy context for longer, but it still degrades. Our guide to picking the right LLM and the Claude model chooser cover the trade-offs by use case.

What Manus learned from rebuilding its agent four times

Manus is the most useful public case study, because its team wrote down specific rules and the reasons for them. Its post, published on 18 July 2025 by Yichao "Peak" Ji, calls the process "Stochastic Graduate Descent": architecture searching, prompt fiddling and empirical guesswork.

The rules fall into five groups.

Design around the KV-cache. The post calls the cache hit rate the single most important metric for a production agent. Agents read far more than they write: the average input-to-output ratio in Manus is about 100:1. At the time of the post, cached input tokens on Claude Sonnet cost 0.30 USD per million, against 3 USD uncached. That is a 10x gap.

To protect the cache, keep the prompt prefix stable, make the context append-only and mark cache breakpoints when the provider needs them. One small mistake wrecks it: a timestamp, precise to the second, at the start of the system prompt.

Mask tools, do not remove them. Changing the tool list mid-task invalidates the cache and confuses the model about past calls to tools that no longer exist. Manus keeps the list fixed and constrains which tools can be chosen at each state.

Use the file system as context. Manus treats files as unlimited, persistent memory the agent can read and write. Its compression is always restorable: a web page can be dropped from context if the URL stays, and a document if its path stays.

Recite the goal. A typical Manus task takes around 50 tool calls. The agent keeps rewriting a todo.md file, which pushes the plan to the end of the context, where attention is strongest.

Keep failures in. Leaving a failed action and its error in the trace helps the model avoid repeating it. Manus also warns against uniform past actions, because a context full of similar pairs makes the model mimic the pattern.

If you want to see how this plays out in a product, our Manus versus ChatGPT agent comparison tests the result, and the best agentic AI roundup places it among alternatives.

Compaction, notes and sub-agents for long jobs

Some tasks run past any window. Anthropic describes three techniques for them, and the post is clear that the right one depends on the work.

Compaction summarizes a conversation that is near the limit and restarts with the summary. In Claude Code, Anthropic says, the model keeps architectural decisions, unresolved bugs and implementation details, drops redundant tool output, and continues with the five most recently accessed files. The lightest version is clearing old tool results, since a result buried deep in the history is rarely needed again.

Structured note-taking has the agent write notes to storage outside the window and read them back later. Anthropic's example is a NOTES.md file or a to-do list. Its September 2025 release added a memory tool that stores information in files you control.

Sub-agents split a job so that each worker uses a clean window. A worker may spend tens of thousands of tokens exploring and returns a summary of often 1,000 to 2,000 tokens.

Anthropic's rule of thumb:

  • Compaction fits long back-and-forth conversations.
  • Note-taking fits iterative work with clear milestones.
  • Sub-agents fit research and analysis where parallel exploration pays off.

On the product side, Augment Code's HokAI profile records up to 10 parallel Remote Agents in isolated cloud sandboxes, which is the sub-agent pattern sold as a coding product. The OpenAI Agents API lists hosted sandboxes and subagents in public beta, and our pricing breakdown covers what that costs. For coding agents in general, start with the best AI coding assistants.

The shortlist: one tool per context job

You do not need a product for each technique. Many teams do all of this with files and a prompt. When you do reach for a product, match it to the job, not to a category name.

Context jobToolWhat it does
Persistent memoryMem0Memory layer for agents across sessions
Vector storageLanceDBOpen-source embedded vector database
Web pages to MarkdownFirecrawlSearch, scrape and crawl into LLM-ready text
Search for agentsExaRanks the web by meaning through an API
Agent frameworkMastraTypeScript framework for agents and workflows
Local document chatAnythingLLMFree desktop app for chatting with documents

Here is how to read the table. Each row is a source of tokens, a store for tokens, or a switch that controls which tokens enter. The tools do not replace the thinking in the earlier sections.

Mem0 is the memory pick. Its homepage describes a memory compression engine that condenses chat history into compact memories, and says it is benchmarked on LoCoMo, LongMemEval and BEAM. Treat vendor benchmarks as a starting point and run your own conversations through it.

LanceDB covers storage. Its site says CrewAI rebuilt agent memory on it, shipping by default across 12 million monthly downloads and more than 2 billion agent executions. That is a claim from LanceDB's own writing about a customer, so check it before relying on it.

Firecrawl turns messy pages into clean Markdown, which is a context-engineering job in itself: a page that arrives as clean text costs far fewer tokens than the raw HTML. Exa is the alternative when you need search results, not page contents. Browse more options in the search and retrieval directory.

Other retrieval products worth a look: LlamaIndex for document pipelines, Glean for enterprise search, Dosu and kapa.ai for answering from documentation.

If you are not sure which of these fits your stack, Smart Match asks about your workload and narrows the list.

What context engineering costs in tokens and money

The costs are not only the tools. The expensive part is tokens, and the cache decides how many of them you pay full price for.

Manus's numbers show the scale. If cached tokens cost a tenth of uncached ones, an agent that keeps a stable prefix pays a fraction of one that does not. With a 100:1 input-to-output ratio, nearly all of an agent's spend is input, so the prefix is where the money is.

Anthropic reports what its own context tools did on an internal evaluation of agentic search. Combining the memory tool with context editing improved performance by 39% over baseline. Context editing alone delivered 29%. In a 100-turn web search evaluation, context editing cut token consumption by 84% and let agents finish workflows that would otherwise fail from context exhaustion. These are Anthropic's own results on its own tests, so they show direction, not a guarantee for your workload.

Tool prices are small by comparison. Firecrawl's pricing page lists a free plan of 1,000 credits a month, 500 searches or 1,000 scraped pages. The Hobby plan is 5,000 credits at $16 a month billed yearly, and the Standard plan is 100,000 credits at $83 a month billed yearly. Check the page before you budget, as plans move.

To keep spend in check:

  1. Measure tokens per task before you change anything.
  2. Fix the biggest source first, which is usually tool output.
  3. Stabilize the prefix so the cache hits.
  4. Only then add a memory or retrieval product.

Model price is the other half. The LLM leaderboard shows price against benchmark scores, and Claude Sonnet 5.5 is a typical mid-priced option to compare against.

Memory is also a data liability

Every technique above puts more of your data somewhere. A memory store holds what users said. A file system holds what tools returned. A summary holds a lossy version of both.

Ask these questions before you ship:

  • Where does the memory live, and who can read it?
  • Can a user ask you to delete what the agent remembers about them?
  • Does a tool result contain secrets, and does compaction copy them into a summary?
  • Do sub-agents inherit more access than their task needs?

Anthropic notes that its memory tool runs client-side through tool calls and that developers manage the storage backend, so you decide where the data sits. That gives you control and the responsibility that comes with it. A hosted memory service moves that decision to a vendor, which is fine when you have read its retention terms and not otherwise.

We did not test the privacy terms of the memory products listed here. Check each vendor's documentation, and for regulated data prefer a store you host yourself, such as an embedded database.

There is also a quality risk. A memory that stores a wrong fact will repeat it with confidence in every later session. Manus's advice to keep errors in the trace applies to memory too: keep the evidence, and have a way to correct it.

Who should skip this and keep prompting

Most chat use does not need context engineering. If you ask a model a question, paste a document and read the answer, you are in prompt territory. The window is small relative to the limit and a bad answer costs you one retry.

You can stay with plain prompting when:

  • The task finishes in one or two turns.
  • Nothing is persisted between runs.
  • A person reads every output before it matters.

Context engineering starts to pay when an agent takes many steps, runs unattended or must remember across sessions. Anthropic's "do the simplest thing that works" line is the right tiebreaker. Add a technique when you can name the failure it fixes.

Teams that only need a chat assistant over their own files can use something like AnythingLLM and stop there. If the main job is writing code with an assistant, the context management is already inside the product, and your effort is better spent on a clear repository setup.

A caution on shortcuts. Searches for a "context engineering skill" for Claude turn up community packages. We did not test them, and we cannot tell you what they do to your window.

What would change this verdict

The best objection to the whole practice is that models will absorb the problem. Anthropic itself says that smarter models need less prescriptive engineering and allow agents to act with more autonomy. If that holds, hand-built context management is a temporary patch.

There is truth in it. The formatting of prompts matters less than it did, and Anthropic says as much. The answer is that the problem moves instead of vanishing. Even with perfect models, an agent still has to decide what to read, what to remember and what to forget. Chroma's tests found degradation on simple tasks, which is not a problem a smarter planner removes.

Three things would change our view:

  1. Evidence that long-context degradation disappears on a new generation of models across independent tests, not only vendor ones.
  2. Providers that manage compaction and memory so well by default that your own code adds nothing.
  3. A cheaper cache that makes a messy prefix as affordable as a clean one.

Watch the model leaderboard and Anthropic's engineering posts, and ask whether the next release of your model of choice needs less of this work. For now, the cheapest improvement is still the oldest one: read what your agent actually sees on step forty, and cut whatever should not be there.

Frequently asked questions

What is the difference between prompt engineering and context engineering?

Prompt engineering is writing and organizing the instructions you give a model. Context engineering covers every token the model sees at inference time, including tools, history and retrieved data. It repeats on each step of an agent loop instead of happening once.

Why does a long context window make answers worse?

Chroma tested 18 models and found performance grew less reliable as input length grew, even on simple tasks. Anthropic explains that attention is spread across n squared token pairs, so precision falls as the window fills.

What is compaction in an AI agent?

Compaction summarizes a conversation that is near the context limit and restarts with the summary. Anthropic says Claude Code keeps decisions, unresolved bugs and recent files while dropping redundant tool output.

Does context engineering lower costs?

It can. Manus reports that cached input tokens cost a tenth of uncached ones on Claude Sonnet, and Anthropic reports an 84% token reduction in one 100-turn test using context editing. Both are vendor results on their own workloads.

When can I skip context engineering?

Skip it for short chats where a person reads every answer and nothing is stored between runs. It starts to pay for agents that take many steps, run unattended or must remember across sessions.

Covered in this guide

  • anythingllm: Free MIT-licensed desktop app that chats with your documents and runs agents on local models, no account needed. About 66,700 GitHub stars.
  • augment-code: Augment Code is an AI coding agent for enterprise teams, running up to 10 autonomous Remote Agents in parallel inside isolated cloud sandboxes.
  • claude-sonnet-5.5: Anthropic's fastest Sonnet-class model, launched in September 2026, with a 1M context and output more than 30% faster than Sonnet 5.
  • dosu: AI knowledge layer for coding agents. Captures what engineers and agents learn across GitHub, Slack and Notion, shares it via MCP, and auto-syncs docs. Free plan covers public repos only.
  • exa: Search API that ranks the web by meaning for AI agents and retrieval pipelines, with six search types, an asynchronous research Agent and an official MCP server. A free Starter plan with monthly credits needs no payment method.
  • firecrawl: Web data API for AI agents: search, scrape, crawl and interact, returning LLM-ready Markdown. Open source core with a free plan and an MCP server.
  • glean: Enterprise AI search platform at $300M ARR in 2026, connecting 100+ apps with permissions-aware results, AI agents, and MCP support from ~$50/user/month.
  • kapa-ai: AI documentation and knowledge-retrieval assistant used by companies like OpenAI and Docker to auto-answer technical support questions from their own docs.
  • lancedb: LanceDB stores 100M+ vectors on a single node as an open-source, embedded database built on Apache Arrow, backed by $41M in funding.
  • llamaindex: The world's most accurate agentic OCR and document-specific AI workflows for enterprise automation
  • Manus: Autonomous AI agent that plans and executes multi-step work from one prompt: research, documents, apps and video. The September 2026 release adds Cascade, Automations and Studio. Free tier available.
  • mastra: Open-source TypeScript framework for building AI agents and workflows, routing to 90+ model providers through one interface.
  • Mem0: Mem0 gives AI agents persistent memory through one API, scoring 92.5 on the LoCoMo benchmark with its V3 algorithm released in 2026.
  • openai-agents-api: Managed API for cloud agents on the Codex runtime: hosted sandboxes, 9 sandbox partners, subagents and computer use, in public beta since Sept 2026.

Sources

Still deciding?

This guide covers a handful of options. Smart Match checks every listing in the directory against how you actually work and what you can spend, then hands you the shortlist and the reason behind each pick.

Find your tools

Related guides

Find your toolsAll AI guidesBrowse the AI directory