Lab

Context engineering

Context engineering: Choosing what goes into a model's context on each turn, from instructions and tool descriptions to retrieved passages and earlier results, and what is left out.

A model can only work with what is in front of it. In a single chat that is mostly your prompt. In an agent it is much more: standing instructions, descriptions of every tool, the task, retrieved passages, and the result of every tool call so far. Context engineering is the work of choosing all of that.

The choices pull against each other. Leave something out and the model cannot use it. Put too much in and the context fills up, every turn costs more to read, and the passage that matters is buried among ones that do not. Text that does not change between turns can be cached, so the order things go in matters too.

Common moves include retrieving only the passages that match the task, as in retrieval-augmented generation; trimming or summarising old tool results; describing only the tools this task needs; and marking text that came from outside as material to read, not instructions to follow. The last one helps, but it does not stop prompt injection on its own.

The survey by Mei et al. treats context engineering as a discipline wider than writing prompts: the systematic work of choosing what information a model is given while it runs. In an agent that work happens inside the harness, on every turn of the loop.

The explainer shows the context growing turn by turn, and what changes when the harness lets in more or less.

See it working

Explore it in How an AI agent works

Step through a model calling tools in a loop, and see how the harness around it decides what it sees, what it may touch and when it stops.

Open the explainer