# What is context engineering? Techniques and the controls providers ship

> Context engineering is choosing what goes into a model's context at each step. Techniques, and the Anthropic, OpenAI and Google controls for each.

Source: https://www.honeyhive.ai/learn/context-engineering (updated 2026-11-06)

Context engineering is the work of deciding what a model sees at each step of a run. Anthropic [defines](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents) it as "the set of strategies for curating and maintaining the optimal set of tokens (information) during LLM inference". That covers the [system prompt](/learn/system-prompt), tool definitions, examples, retrieved documents and the message history, which together fill the [context window](/learn/context-window).

The idea matters most for agents, because an agent's context grows with every tool call. For how the term differs from writing a good prompt, see [context engineering vs prompt engineering](/learn/context-engineering-vs-prompt-engineering). This page covers the techniques and the controls each major provider ships for them.

## Four moves

LangChain's team [sorts](https://www.langchain.com/blog/context-engineering-for-agents) the techniques into four groups. They compare the model to a CPU and the context window to RAM, an analogy they tie to Andrej Karpathy's description of the job as filling the window with "just the right information for the next step".

| Move | LangChain's definition | Typical form |
|---|---|---|
| Write | Saving context outside the window | Notes, scratchpads, [memory](/learn/agent-memory) files |
| Select | Pulling context into the window | Retrieval, tool lookups, loading memory |
| Compress | Retaining only the tokens required | Summaries, clearing old tool results |
| Isolate | Splitting context up | Sub-agents with their own windows |

Anthropic's [post](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents) names the same ideas with different words: just-in-time retrieval, compaction, structured note-taking and sub-agents.

## What each provider ships

Provider docs now cover most of these moves as API features. The table lists only what the docs describe, so check them for model support and beta status, which change.

| Move | Anthropic (Claude) | OpenAI | Google (ADK) |
|---|---|---|---|
| Write | [Memory tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/memory-tool): files under `/memories`, run by your application | [Conversations API](https://developers.openai.com/api/docs/guides/conversation-state) holds state under a durable ID | [Session state and artifacts](https://adk.dev/context/): `state` with `app:`, `user:` and `temp:` prefixes, `save_artifact` |
| Select | Memory reads, and tools that fetch on demand | You [choose](https://developers.openai.com/api/docs/guides/conversation-state) which items go in the `input` array | `search_memory(query)` on the tool context |
| Compress | [Context editing](https://platform.claude.com/docs/en/build-with-claude/context-editing) clears old tool results or thinking blocks; [compaction](https://platform.claude.com/docs/en/build-with-claude/compaction) summarizes | [Compaction](https://developers.openai.com/api/docs/guides/compaction): `compact_threshold` on a Responses request, or the `/responses/compact` endpoint | [Context compaction](https://adk.dev/context/compaction/) with `EventsCompactionConfig`, by event count or token threshold |
| Isolate | Sub-agents with clean windows, as Anthropic's [post](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents) describes | Not covered in the pages read | Not covered in the pages read |

Three differences matter when you pick one.

- **Clear or summarize.** Claude's docs [separate](https://platform.claude.com/docs/en/build-with-claude/context-editing) the two: context editing clears specific content by rule, while compaction summarizes the whole history. Anthropic's engineering post [calls](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents) tool result clearing one of the lightest forms of compaction.
- **Who can read the result.** OpenAI's compaction item is [encrypted](https://developers.openai.com/api/docs/guides/compaction) and "opaque and not intended to be human-interpretable". You pass it back rather than inspecting it. Claude's on-demand compaction lets you [write your own summarization prompt](https://platform.claude.com/docs/en/build-with-claude/compaction), and ADK lets you set the summarizer model.
- **Where memory lives.** Claude's memory tool is client-side: Claude requests file operations and your application [runs them](https://platform.claude.com/docs/en/agents-and-tools/tool-use/memory-tool) against storage you control. You own retention, size caps and path validation.

## What to put in the window

Anthropic's [post](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents) gives concrete guidance for each part of the context.

- **System prompt.** Aim for "the right altitude", between brittle hard-coded logic and vague guidance. Start with a minimal prompt and add instructions when you see failures.
- **Tools.** They should be "self-contained, robust to error, and extremely clear with respect to their intended use". A bloated tool set with overlapping choices confuses the agent.
- **Examples.** Curate a small set of diverse, canonical examples rather than every edge case.
- **Tool output.** Anthropic's [tool-writing guide](https://www.anthropic.com/engineering/writing-tools-for-agents) says to return only high-signal information. Its `response_format` example lets the agent ask for concise or detailed results, and concise used about a third of the tokens. Claude Code caps tool responses at 25,000 tokens by default.
- **Retrieval.** Keep lightweight identifiers such as file paths and links, and load data at runtime. Anthropic notes this is slower than pre-computed retrieval and needs good guidance, so some tasks suit a hybrid.

## Cost and cache

Context engineering is also a cost control. Manus's Yichao "Peak" Ji [wrote](https://manus.im/blog/Context-Engineering-for-AI-Agents-Lessons-from-Building-Manus) in July 2025 that KV-cache hit rate is "the single most important metric for a production-stage AI agent", with an average input-to-output ratio around 100:1 in Manus. His advice: keep the prompt prefix stable and the context append-only.

The Claude [caching docs](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) explain the mechanics. The cache covers the prefix in the order tools, system, messages, a hit needs an exact match, and a change at one level invalidates it and everything after. They advise putting the breakpoint on the last block that stays identical across requests, not on one holding timestamps.

This creates a tension. Clearing old tool results shrinks the window, but the context editing docs [warn](https://platform.claude.com/docs/en/build-with-claude/context-editing) that it invalidates cached prefixes, which is why they offer `clear_at_least`. Manus's answer is to mask tool choices rather than add or remove tools mid-task. See [LLM cost optimization](/learn/llm-cost-optimization) for the wider picture.

## Patterns from practitioners

Beyond the API features, two teams describe habits worth copying.

- **Recite the plan.** Manus [rewrites](https://manus.im/blog/Context-Engineering-for-AI-Agents-Lessons-from-Building-Manus) a todo list as it works, which it describes as reciting objectives into the end of the context so the goal stays in recent attention.
- **Keep failures visible.** Manus leaves failed actions and error traces in context so the model updates its beliefs. It also warns against repeating one pattern so often that the agent copies it.
- **Resume from files.** For work across sessions, the memory tool docs [describe](https://platform.claude.com/docs/en/agents-and-tools/tool-use/memory-tool) an initializer session that writes a progress log and a feature checklist, which each later session reads first.

For splitting work across agents, see [multi-agent systems](/learn/multi-agent-systems).

## Measure what the model saw

Context problems show up as wrong answers, not errors, so you need to see the context. Long inputs can degrade accuracy on their own; the [context rot](/learn/context-rot) page covers the studies. To debug, record each step's full input, the token count and what was cleared or summarized. HoneyHive's [tracing docs](https://docs.honeyhive.ai/v2/tracing/concepts.md) describe capturing model and tool spans for this, and [agent tracing](/learn/agent-tracing) covers the method. Then change one technique at a time and compare runs with an evaluation set, as in [LLM evaluation metrics](/learn/llm-evaluation-metrics).

## FAQ

### What is context engineering?

Anthropic [defines](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents) it as the set of strategies for curating and maintaining the optimal set of tokens during LLM inference. In practice it covers everything the model sees at each step: instructions, tools, examples, retrieved data and message history.

### What are the main context engineering techniques?

LangChain's [grouping](https://www.langchain.com/blog/context-engineering-for-agents) is write, select, compress and isolate. Write saves context outside the window, select pulls it in, compress keeps only the tokens needed, and isolate splits context across agents or environments.

### How is context engineering different from prompt engineering?

Prompt engineering writes the instructions. Context engineering manages everything the model sees across a run. The two overlap, and the [comparison page](/learn/context-engineering-vs-prompt-engineering) lays out how sources draw the line.

### What is context compaction?

Compaction replaces older turns with a summary so a long task fits the window. The Claude [docs](https://platform.claude.com/docs/en/build-with-claude/compaction), OpenAI's [guide](https://developers.openai.com/api/docs/guides/compaction) and Google's [ADK docs](https://adk.dev/context/compaction/) each ship a version of it.

### Does a bigger context window remove the need for context engineering?

No. The Claude docs [say](https://platform.claude.com/docs/en/build-with-claude/compaction) response quality degrades as a conversation grows, which is why compaction exists. See [context rot](/learn/context-rot).
