# Context engineering

> VI: https://5ac.vn/wiki/context-engineering/ · EN: https://5ac.vn/en/wiki/context-engineering/ · lang: en · spec_as_of 2026-10-18 (spec no formal spec) · cluster C4

The discipline of picking the exact tokens that enter a model's context window each turn, treating context as a finite resource that depletes as it grows.

---
## Definition

Context engineering is choosing and maintaining the exact set of tokens that enters a model's context window on every inference turn, rather than polishing the prompt alone. Context is a finite resource: each new token spends part of an attention budget, so the win comes from a small set of high-signal tokens.

## Mechanism

Anthropic splits context into parts that each need their own tuning:

| Component | Principle | Common trap |
| --- | --- | --- |
| System prompt | specific enough to steer, loose enough for the model to decide | brittle hardcoded if-else, or vague high-level guidance |
| Tools | self-contained, little overlap, token-lean answers | oversized tool sets that blur the choice |
| Few-shot examples | few and canonical, covering the behavior you want | laundry lists of edge cases |
| Message history | compacted, or written outside the window | keeping every token, which invites context rot |

Flow: Pick sources → Load on demand → Compact → Write notes outside

Context rot describes recall getting worse as the window grows: transformer attention pairs every token with every other, so relationships scale with the square of the sequence and thin out as it lengthens. Position interpolation lets models handle longer sequences at a cost to positional accuracy. The shape is a slope, not a cliff: models still perform well on long context, only with less precision when digging out old details.

Anthropic pushes just-in-time loading: keep lightweight identifiers such as file paths, URLs and queries, then pull the real data when the agent needs it instead of front-loading everything. Compaction suits long back-and-forth; note-taking suits development with clear milestones; sub-agents suit research that pays for parallel exploration, each burning tens of thousands of tokens yet returning only a 1,000 to 2,000 token summary.

## Spec anchor

Context engineering has no formal spec, so the frontmatter says "no formal spec" and pins the reading date 2026-10-18. Two practical anchors: Anthropic's [Effective context engineering for AI agents](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents), published 2025-09-29, and the survey [arXiv:2507.13334](https://arxiv.org/abs/2507.13334) at v2, revised 2025-07-21. Anthropic lists MCP among context sources; the MCP [versioning page](https://modelcontextprotocol.io/specification/versioning), checked 2026-10-18, shows the current protocol version is 2026-07-28.

## Academic anchors

The survey [arXiv:2507.13334](https://arxiv.org/abs/2507.13334) is this entry's main academic anchor:

| Item | Figure | Measured |
| --- | --- | --- |
| [arXiv:2507.13334](https://arxiv.org/abs/2507.13334) | 166 pages, more than 1,400 papers reviewed, 1,411 citations | 2026-10-18 |
| [Anthropic engineering](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents) | original post by the Applied AI team, published 2025-09-29 | 2026-10-18 |

The survey's taxonomy splits context engineering into context retrieval and generation, context processing and context management, then composes three systems: RAG, memory systems with tool-integrated reasoning, and multi-agent setups. The gap it points to: models understand context far better than they generate equally sophisticated long-form output.

## FAQ

**How does context engineering differ from prompt engineering?** Prompt engineering is about writing instructions; context engineering manages the whole state fed to the model each turn, namely system instructions, tools, MCP, external data and message history. Anthropic frames it as the natural next step.

**What is context rot?** Recall quality slipping as the token count rises. The root cause is attention that scales with the square of the sequence, so Anthropic treats context as a limited attention budget rather than a bucket to keep filling.

**When to compact, take notes, or spawn sub-agents?** Anthropic keys it to the task: compaction keeps conversation flowing through heavy back-and-forth; note-taking fits development with clear milestones; parallel exploration pays off in multi-agent research.

**How does this relate to MCP?** MCP is one of the context sources Anthropic lists, next to system instructions, tools, external data and history. The current MCP version, checked 2026-10-18, is 2026-07-28.

**Which sources built this entry?** Three pages, all fetched on 2026-10-18: Anthropic's [context engineering post](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents), the survey [arXiv:2507.13334](https://arxiv.org/abs/2507.13334), and the MCP [versioning page](https://modelcontextprotocol.io/specification/versioning) for the protocol number.

## Related

- [Agent Skills (SKILL.md)](/en/wiki/agent-skills/)
- [What Is a Multi-Agent OS?](/en/blog/what-is-multi-agent-os/)
- [Andrew Ng's 4 AI Engineering Skills Map](/en/blog/ai-engineering-skills-map/)
