Library
8 min read

Context engineering and memory

Two hours into a task, a coding agent starts acting strangely. It re-reads files it already read. It forgets the instruction "do not touch the payments module" and edits the payments module. Nothing about the model changed. Its context did: it is now 90% old tool output, a few thousand lines of logs and file contents, with the original instructions buried somewhere near the top.

Prompting is about writing one good instruction. Context engineering, a name that caught on in 2025, is the bigger job: deciding what goes into the window on every single call of a long running system, and what stays out.

Your answer

An agent has made 60 tool calls and its context is almost full. What would you remove first? What must never be removed?

Agents fill the window fast#

A chat grows by one short message per turn. An agent grows by whatever its tools return, and tools return a lot: a file is thousands of tokens, a search result page is thousands more, a stack trace is hundreds.

When does the window run out?
200 K tokens
12 K tokens
2500 tokens
Room left for the task200K - 12K = 188K tokens
Per step: tool result plus the call2500 + ~150 = 2650 tokens
Steps before half full35
Steps before the window is full70
70 steps
and then the agent cannot take another one

Long before the window is full, quality slips: the original instructions are far away, and most of the context is stale output the model still has to read on every call. This is why tools that return a short summary instead of a raw dump make an agent both cheaper and smarter.