Specialty Digest

Global English editionLearners’ Study Dashboard — in development
The Knowledge Library for All

Context Engineering

nounEmerging AI Researchalso context management for LLMs, prompt context design, agent context engineering

In one line

Context engineering is the practice of designing and managing everything a language model sees when it answers, including instructions, retrieved documents, tool results, memory and conversation history, so that the model has the right information in its limited context window to perform a task reliably.

Context engineering is the practice of deciding what information a large language model receives at each step of a task, and in what form. A model has no memory of its own beyond what is placed in its context window, the limited amount of text it can consider at one time. Instructions, the user’s request, retrieved documents, results of tool calls, earlier conversation and stored notes all compete for that space. Context engineering treats this space as a scarce resource to be designed carefully. It extends prompt engineering, which focuses on wording a single instruction, to the whole information environment of a system, especially for AI agents. The phrase gained wide use in mid-2025 among developers of agentic systems. It is closely tied to the AI harness, retrieval-augmented generation and memory in AI agents.

From prompt engineering to context engineering

Early work on chatbots stressed clever phrasing of prompts. As applications grew into agents that run for many steps, search files, call tools and collaborate with other agents, the main problem became choosing which information to include at each moment. A perfectly worded prompt cannot help if the model lacks the needed facts or is distracted by too much irrelevant material. Anthropic described context engineering in 2025 as curating and maintaining the best set of tokens during model inference [3].

Why context needs engineering

  • Limited window. Even large windows are finite, and costs and delay rise with length.
  • Lost in the middle. Liu and colleagues found in 2023 that models often use information in the middle of a long input less reliably than information at the start or end [1].
  • Context rot. A 2025 study from Chroma found that performance of many models declines as input length grows, even on simple tasks [2]. More text is not always better.
  • Distraction and conflict. Irrelevant or contradictory material can mislead the model.
  • Cost and speed. Every token processed costs money and time, so efficient context lowers cost; see LLMOps.
  • Security. Untrusted text placed in context can contain hidden instructions; see AI cybersecurity.

Key techniques

### Clear instructions and structure

System prompts should be specific, organized in labeled sections and free of contradictions. Examples of desired output can be more effective than long descriptions.

### Retrieval

Instead of pasting everything, a system retrieves only relevant passages using search or embeddings; see retrieval-augmented generation, embeddings and vector databases.

### Just-in-time loading

Agents can keep lightweight references such as file names or links and load details only when needed, much as a person opens a file when required rather than memorizing it. Standards such as the Model Context Protocol and agent skills support loading tools and instructions on demand.

### Compaction and summarization

When a conversation nears the window limit, the system summarizes earlier content, keeping key decisions, open questions and important details while discarding clutter, then continues with the summary.

### External notes and memory

An agent can write notes to a file or database and read them later, so progress survives across steps and sessions; see memory in AI agents.

### Sub-agents

A lead agent can delegate a sub-task to another model instance with its own clean context, which returns a short summary. This keeps the main context focused.

### Tool design

Tools should have clear names, concise descriptions and outputs that are compact and informative. Tools that return huge raw outputs waste context.

### Ordering and caching

Placing stable material first allows providers to cache it, cutting cost and latency. Important instructions are often repeated near the end of the prompt.

### Pruning and clearing

Old tool results and failed attempts can be removed once they are no longer useful.

Applications

  • Coding agents that navigate large repositories; see AI harness.
  • Customer support assistants that draw on policies and account data; see AI in business.
  • Deep research agents that process hundreds of pages; see deep research.
  • Enterprise assistants over internal documents, with access controls; see data governance.
  • Personal assistants that remember preferences while respecting privacy; see AI privacy.

Evaluating context choices

Teams test context designs by running fixed task sets and measuring accuracy, cost, time and failure types as they change what is included. They look for cases where models ignore provided facts, repeat old mistakes or get stuck, and they compare several retrieval and summarization settings. Tracing tools that show the exact context sent at each step are essential for diagnosis; see AI evaluation.

Challenges and risks

  • Information loss. Summaries can drop details that later matter.
  • Prompt injection and data leakage. Retrieved or tool-provided text may carry malicious instructions or expose confidential data; see data leakage.
  • Access control. Context must respect who is allowed to see which documents.
  • Staleness. Stored notes and cached data can become outdated.
  • Complexity. Many moving parts make systems hard to debug.
  • Bias in retrieval. Search choices can favor some sources over others; see algorithmic bias.

A worked example

A support assistant for a software company receives a question about a billing error. A poorly designed system pastes the full customer history and the entire policy manual into the prompt, so the model misses the key detail buried in the middle. A context-engineered system first retrieves the three most relevant policy sections, fetches only the customer’s last two invoices through a tool, and summarizes earlier chat turns into a short note. It places the instructions and the invoices clearly labeled in the prompt and asks the model to cite the policy section it uses. Answers become more accurate and cost less, and a trace shows exactly what the model saw.

Good practice checklist

Teams that build with language models often adopt a short checklist. Decide what the model must know to do the task and what it can look up on demand. Keep standing instructions concise and consistent. Retrieve narrowly and label sources. Summarize long histories rather than carrying them forward whole. Store durable facts outside the window. Limit tool outputs. Separate trusted instructions from untrusted data, and test with realistic, messy inputs. Review traces regularly, since the best context design usually emerges from watching where the model goes wrong; see AI risk management.

Further reading and next steps

Readers can continue with multimodal reasoning, on-device AI and human-AI collaboration to see how context and model capabilities shape real applications.

FAQs

What is context engineering? It is the practice of deciding what information goes into a model’s context window and how it is arranged, so the model can do its task reliably.

How is it different from prompt engineering? Prompt engineering focuses on wording instructions, while context engineering manages all information the model sees, including retrieval, memory and tool outputs.

Does a bigger context window solve the problem? Not fully. Studies show that long inputs can reduce accuracy and raise cost, so selection and structure still matter.

What is context rot? It is the decline in model performance as the amount of text in the context grows.

What is compaction? It is summarizing earlier parts of a long task so the agent can continue within its context limit.

Key facts

  • Liu and colleagues reported in 2023 that language models often use information in the middle of long inputs less well than information at the beginning or end, a finding known as lost in the middle1.
  • Chroma researchers published a 2025 study titled Context Rot showing that performance of many large language models degrades as input length grows, even on simple tasks2.
  • Anthropic published guidance in 2025 describing context engineering as curating and maintaining the optimal set of tokens during model inference, and described techniques such as compaction, note-taking and sub-agents for long-running tasks3.

Related concepts

Quick checkWhat is context engineering?Show answer

Context engineering is the practice of designing and managing everything a language model sees when it answers, including instructions, retrieved documents, tool results, memory and conversation history, so that the model has the right information in its limited context window to perform a task reliably.

Sources

  1. Liu et al., Lost in the Middle: How Language Models Use Long Contexts, Transactions of the Association for Computational Linguistics, https://arxiv.org/abs/2307.03172
  2. Hong, Troynikov and Huber, Context Rot: How Increasing Input Tokens Impacts LLM Performance, Chroma Research, https://research.trychroma.com/context-rot
  3. Anthropic, Effective context engineering for AI agents, https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents

Editorially reviewed by Specialty Digest Editorial TeamLast reviewed November 17, 2026Researched and drafted with AI assistanceReport an issue