What is context engineering? Techniques and the controls providers ship

Improve prompts and agents
HoneyHive Engineering

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

Context engineering is the work of deciding what a model sees at each step of a run. Anthropic defines it as “the set of strategies for curating and maintaining the optimal set of tokens (information) during LLM inference”. That covers the system prompt, tool definitions, examples, retrieved documents and the message history, which together fill the 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. This page covers the techniques and the controls each major provider ships for them.

Four moves

LangChain’s team sorts 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 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 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: files under /memories, run by your application Conversations API holds state under a durable ID Session state and artifacts: state with app:, user: and temp: prefixes, save_artifact
Select Memory reads, and tools that fetch on demand You choose which items go in the input array search_memory(query) on the tool context
Compress Context editing clears old tool results or thinking blocks; compaction summarizes Compaction: compact_threshold on a Responses request, or the /responses/compact endpoint Context compaction with EventsCompactionConfig, by event count or token threshold
Isolate Sub-agents with clean windows, as Anthropic’s post 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 the two: context editing clears specific content by rule, while compaction summarizes the whole history. Anthropic’s engineering post calls tool result clearing one of the lightest forms of compaction.
  • Who can read the result. OpenAI’s compaction item is encrypted 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, 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 against storage you control. You own retention, size caps and path validation.

What to put in the window

Anthropic’s post 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 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 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 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 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 for the wider picture.

Patterns from practitioners

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

  • Recite the plan. Manus rewrites 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 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.

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 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 describe capturing model and tool spans for this, and agent tracing covers the method. Then change one technique at a time and compare runs with an evaluation set, as in LLM evaluation metrics.

FAQ

What is context engineering?

Anthropic defines 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 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 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, OpenAI's guide and Google's ADK docs each ship a version of it.

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

No. The Claude docs say response quality degrades as a conversation grows, which is why compaction exists. See context rot.

Share