# Context engineering

> Choosing what goes into a model's context so it has what it needs and nothing more.

- Level: Intermediate
- Topics: AI
- URL: https://tidbit.legios.com.ar/context-engineering/
- In Spanish: [Ingeniería de contexto](https://tidbit.legios.com.ar/es/context-engineering/)

An LLM works with two things: what it learned in training and what sits in its context window right now. **Context engineering** is the job of deciding what goes into that window at each step: the instructions, the relevant documents, the conversation so far, the tool definitions, the results of earlier tool calls. The term spread in 2025 as a broader cousin of prompt engineering, which focuses on wording a single request well.

It matters most for AI agents that work through many steps. Every tool result, file and message piles up, and even with a huge context window, more is not better: as the window fills, models get slower and more expensive, and they can lose track of details buried in the middle. A well-built agent keeps its context lean and relevant.

Common techniques: fetch only the relevant pieces with RAG or search instead of pasting whole documents; summarize or compact old turns of the conversation; let the agent write notes to a file and read them back later; give a sub-agent its own clean context for a side task and keep only its summary; load detailed tool instructions only when they are needed. The guiding question is always the same: what is the smallest set of information that lets the model do this step well?

## An analogy

Briefing a surgeon before an operation. You do not hand over the patient's whole life story; you give the scans, the allergies and today's plan, clearly organized. Too little and they have to guess; too much and the one line that matters gets lost.

## Keep in mind

- It decides which instructions, data and history the model sees at each step.
- More context is not always better: it costs money, time and attention.
- Key techniques: retrieval, summarizing, notes and sub-agents.
- Prompt engineering is about wording; context engineering is about the whole input.

## Go deeper

- [Effective context engineering for AI agents (Anthropic)](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents)
- [Context engineering on Wikipedia](https://en.wikipedia.org/wiki/Context_engineering)

## Related terms

- [LLM](https://tidbit.legios.com.ar/llm/): A neural network trained on huge amounts of text to predict the next word.
- [Training and inference](https://tidbit.legios.com.ar/training-and-inference/): Training builds the model once; inference is using it, millions of times a day.
- [Context window](https://tidbit.legios.com.ar/context-window/): How much text an AI model can take into account at once, measured in tokens.
- [Function calling](https://tidbit.legios.com.ar/function-calling/): How an AI model asks your code to run a tool and then uses the result.
- [Prompt engineering](https://tidbit.legios.com.ar/prompt-engineering/): Writing instructions for an AI model so it gives you what you actually need.
- [AI agent](https://tidbit.legios.com.ar/ai-agent/): An LLM that can take actions, check the results and keep going until the job is done.
- [RAG](https://tidbit.legios.com.ar/rag/): Let the model look things up in your documents before it answers.
