---
title: "What is context engineering in AI?"
description: "Context engineering is the practice of curating all an LLM sees at inference time: instructions, retrieved data, tools, memory, and history. How it works."
type: "glossary-term"
canonical_url: "https://theaiengineering.com/glossary/context-engineering"
markdown_url: "https://theaiengineering.com/glossary/context-engineering.md"
topic: "Prompt and context engineering"
author: "The AI Engineering Editors"
publisher: "The AI Engineering"
updated: "2026-11-06"
keywords: ["Context engineering","context management","context curation"]
citation: "The AI Engineering Editors. \"What is context engineering in AI?\" The AI Engineering, updated Nov 06, 2026. https://theaiengineering.com/glossary/context-engineering"
---

# What is context engineering in AI?

Also called context management, context curation.

> **Definition of Context engineering:** Context engineering is the practice of selecting, structuring, and pruning all the information placed in an LLM's context window at each step, including instructions, retrieved data, tool results, and memory.

Context engineering is the discipline of deciding what goes into a model's [context window](https://theaiengineering.com/glossary/context-window), in what form, and at which step. The discipline treats context as a limited resource to curate, not a container to fill. The term spread in June 2025, when Shopify CEO Tobi Lütke and Andrej Karpathy both publicly endorsed "context engineering" over "prompt engineering" as the name for this work.

## How context engineering works

At each step, an agent's context is assembled from several sources, and each source needs its own selection policy:

**Figure 1: Each slice of the context window is managed differently.**

A stack of six context window slices, from system prompt to chat history, each with its own policy: written, chosen, loaded, fetched, cleared, or compacted.

Layers, top to bottom:

1. **System prompt**: Written once
2. **Tool definitions**: Chosen per task
3. **Memory notes**: Loaded on demand
4. **Retrieved docs**: Fetched per query
5. **Tool results**: Cleared when stale
6. **Chat history**: Compacted over time

Anthropic's engineering post [Effective context engineering for AI agents](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents) (September 2025) describes four core techniques:

- **Just-in-time retrieval:** keep lightweight references such as file paths or queries, and load the data with tools only when it is needed.
- **[Compaction](https://theaiengineering.com/glossary/context-compaction):** summarize the conversation as it nears the limit, then continue in a fresh window that starts from the summary.
- **Structured note-taking:** write notes to [agent memory](https://theaiengineering.com/glossary/agent-memory) outside the window and read them back later.
- **[Sub-agents](https://theaiengineering.com/glossary/subagent):** hand focused subtasks to sub-agents with clean contexts that return condensed results.

Retrieval quality is part of the job: the retrieval step in [retrieval-augmented generation](https://theaiengineering.com/glossary/retrieval-augmented-generation) determines which chunks enter the window. Ordering matters for cost and latency too, because [prompt caching](https://theaiengineering.com/glossary/prompt-caching) reuses only an unchanged prefix, so stable content belongs at the front.

## Why context engineering matters

More context is not automatically better. Anthropic uses the term "[context rot](https://theaiengineering.com/glossary/context-rot)" for the finding that a model's ability to recall information accurately declines as its context window fills. Every irrelevant tool result or stale message competes for attention with the information that matters. Long-running [AI agents](https://theaiengineering.com/glossary/ai-agent) add context on every step, so without pruning, their windows fill with outdated tool output.

## Context engineering vs prompt engineering

[Prompt engineering](https://theaiengineering.com/glossary/prompt-engineering) is a subset of context engineering. Prompt engineering optimizes the instructions for a single call; context engineering also manages the data, tools, and history around those instructions across many turns. The [context engineering explainer](https://theaiengineering.com/articles/context-engineering) goes deeper on both.

## Related terms

- [Prompt engineering](https://theaiengineering.com/glossary/prompt-engineering): Prompt engineering is the practice of designing the instructions, examples, and formatting given to a large language model so it produces accurate, consistent output for a task, without changing model weights.
- [Context window](https://theaiengineering.com/glossary/context-window): A context window is the maximum number of tokens a language model can take into account in a single request, including the system prompt, conversation history, tool results, and the generated output.
- [Agent memory](https://theaiengineering.com/glossary/agent-memory): Agent memory is the set of mechanisms that let an AI agent keep and retrieve information beyond a single model call, from the current context window to external stores that persist across sessions.
- [Retrieval-augmented generation (RAG)](https://theaiengineering.com/glossary/retrieval-augmented-generation): Retrieval-augmented generation (RAG) is a technique that retrieves relevant passages from an external knowledge source at query time and adds them to a language model's prompt so the answer is grounded in that data.
- [Prompt caching](https://theaiengineering.com/glossary/prompt-caching): Prompt caching is an LLM API and inference-server feature that stores the computed attention state for a repeated prompt prefix, so later requests sharing that prefix skip reprocessing it.
- [Context rot](https://theaiengineering.com/glossary/context-rot): Context rot is the decline in a language model's accuracy and recall as the number of tokens in its input grows, even when the information a task needs is present in the context.
- [Context compaction](https://theaiengineering.com/glossary/context-compaction): Context compaction is a context management technique that replaces older conversation turns with a model-written summary as the context window nears its limit, so an agent can keep working.
- [System prompt](https://theaiengineering.com/glossary/system-prompt): A system prompt is the set of developer-written instructions sent to a language model ahead of the conversation, defining its role, rules, output format, and tool use for every turn that follows.

## Guides that cover context engineering

- [What is context engineering? A practical guide for AI agents](https://theaiengineering.com/articles/context-engineering): Context engineering is the practice of choosing what fills an LLM context window. Learn its components, why context rot happens, and how to measure results.
- [What are AI agents? How agents work and when to use one](https://theaiengineering.com/articles/what-are-ai-agents): AI agents are LLM systems that call tools in a loop until a task is done. Learn how the loop works, agents vs agentic AI, examples, failure modes, and limits.
- [What is retrieval-augmented generation (RAG)? How RAG works](https://theaiengineering.com/articles/what-is-rag): Retrieval-augmented generation (RAG) grounds LLM answers in your documents. Learn the RAG pipeline, hybrid search, agentic RAG, evaluation, and failure modes.
- [What is AI engineering? The discipline, the stack, and the work](https://theaiengineering.com/articles/what-is-ai-engineering): What is AI engineering? A plain definition, how it differs from ML and software engineering, the layers of the stack, and what AI engineers do day to day.

Part of the [Prompt and context engineering](https://theaiengineering.com/topics/prompt-engineering) topic hub.

## Cite this definition

The AI Engineering Editors. "What is context engineering in AI?" The AI Engineering, updated Nov 06, 2026. https://theaiengineering.com/glossary/context-engineering

- Title: What is context engineering in AI?
- Author: The AI Engineering Editors
- Publisher: The AI Engineering
- Updated: 2026-11-06
- URL: https://theaiengineering.com/glossary/context-engineering
- Markdown: https://theaiengineering.com/glossary/context-engineering.md
