# Context engineering

Context engineering is deciding what goes into a model's context window at each step of an
agent run, and what stays out. The context is everything the model reads on a call: the system
prompt, tool definitions, retrieved documents, memory, earlier turns, and the results of
earlier tool calls. Prompt engineering is the part of this that writes the instructions.
Context engineering covers all of it, and it happens again on every call, because each step
adds to what the agent has seen.

It exists because the context window is a finite budget, and filling it costs more than
tokens. As the context grows, a model gets worse at recalling and using what is in it, a
decline called context rot. Every token attends to every other token, so attention spreads
thinner as the context grows.

The main techniques trade completeness for focus. Compaction summarizes a conversation that is
close to the limit and starts a fresh window from the summary; clearing old tool results is a
lighter form of it. Note-taking writes progress to memory outside the window and reads it back
when needed. Just-in-time retrieval keeps references, such as file paths or queries, and loads
the content through a tool only when a step needs it. Sub-agents do focused work in their own
clean windows and return a short summary to the lead agent.

Each technique can drop something that turns out to matter. A summary can lose an instruction
or a constraint, and an agent that no longer sees a fact acts as if it never knew it. These
failures look like the agent forgetting, not like an error, so they are found by reading what
the model actually received.

---

Source: https://tessary.ai/answers/context-engineering
All concepts: https://tessary.ai/answers
From Tessary, agent reliability for AI agents in production: https://tessary.ai
