---
title: "Context engineering"
type: "glossary term"
url: "https://aifordevs.org/glossary#context-engineering"
markdown: "https://aifordevs.org/glossary/context-engineering.md"
publisher: "AI for Devs"
license: "https://aifordevs.org/reuse"
attribution: "Credit AI for Devs and link to https://aifordevs.org/glossary#context-engineering"
---

# Context engineering

Context engineering is the practice of choosing what goes into a model's context window for each call, and in what order: instructions, examples, retrieved documents, tool results, and memory. You treat the window as a limited budget and spend it on what the next step needs.

Anthropic defines it as curating and maintaining the best set of tokens during inference, which extends prompt engineering to tools, external data, and message history. Its working rule is the smallest set of high-signal tokens that makes the desired outcome likely. Long agent runs need compaction or tool-result clearing to stay inside the window.

## Example

An agent that loads a 20,000-token log and needs three error lines should keep those lines and clear the raw result. Every later call then carries a few hundred tokens instead of 20,000.

## Source

[Anthropic, Effective context engineering for AI agents (2025)](https://www.anthropic.com/research/effective-context-engineering-for-ai-agents)

## Related terms

- [Context window](https://aifordevs.org/glossary#context-window)
- [System prompt](https://aifordevs.org/glossary#system-prompt)
- [RAG](https://aifordevs.org/glossary#rag)
- [Prompt caching](https://aifordevs.org/glossary#prompt-caching)

## Read the article

[Context engineering: budget and order the context window](https://aifordevs.org/articles/context-engineering)

## Cite this term

AI for Devs. "Context engineering." https://aifordevs.org/glossary#context-engineering

- Page: https://aifordevs.org/glossary#context-engineering
- Markdown: https://aifordevs.org/glossary/context-engineering.md
- Reuse: Quote or summarize with a link to this page. Terms: https://aifordevs.org/reuse
- Publisher: AI for Devs
