# Context window: why the agent forgets

> You explained it at the start and, hours later, the agent did the opposite. The context window explains where what you said went, and what to do about it.

- Aguinelo Koczkodai · 2026-11-10
- https://www.codeplain.dev/en/article/context-window-why-the-agent-forgets
- From the assembly line to the software factory · Part 1: What you have in your hands · article 2 of 29

![Isometric illustration of a long tray packed with cream blocks that run up to a closed module. At the far end, a bar pushes the oldest blocks off, and a single orange block has already fallen to the floor, off the tray.](https://www.codeplain.dev/imagens/janela-de-contexto.572c15c7.webp "The desk fills up and the oldest papers slide off the end. The orange block was your warning: it fell off the desk, and for the model it never existed.")

Picture this. Right at the start of the session you tell the agent: "don't touch the
`legacy` folder, another system uses it". It agrees, works well for an hour and fixes
three bugs. Somewhere around the fourth task, it opens a file in `legacy` and changes it
without a second thought.

It's tempting to think it ignored you, but there are two more boring explanations: either
your warning was no longer in front of it, or it was and got lost among a lot of other
things. To figure out which, and what to do, let's go back to the room from the previous
article.

## The desk in the room is the context window

In article 1, the model was a person locked in a windowless room who only writes notes.
I didn't mention the desk. Everything this person knows about your task is on paper on
their desk: the instructions that came with the job, the description of the tools the
assistant knows how to use, every note exchanged so far, the files they asked to read and
your latest request.

That desk is the context window. And the person keeps nothing from one note to the next:
for every new note, they read the whole desk again and write the next one based only on
what's there. Whatever left the desk, as far as they're concerned, never existed.

## The desk fills up, and someone removes paper

The desk has a size, measured in tokens, which are pieces of words. Some models have a
bigger desk, others a smaller one, but they all have a limit: Claude, Codex, GLM, MiniMax,
DeepSeek.

In a long session the desk fills up fast, because almost everything the agent does leaves
paper behind: every file opened, every test output, every reply. When nothing else fits,
the assistant outside, the harness, has to make room. Usually it summarizes the oldest
pages and throws the originals away. The summary says "we fixed three bugs, tests pass",
and your warning about the `legacy` folder, one line in the middle of a long conversation,
may not have made it in. That's the first way to forget: the paper left the desk.

## A full desk also gets in the way: lost in the middle

The second way is sneakier, because the paper is still there. The model doesn't pay the
same attention to everything on the desk. In 2023, a study by Nelson Liu and colleagues
showed that, in long texts, models find what's at the beginning and at the end better than
what's in the middle, and the effect got a name: lost in the middle. Today's models have
improved on this, but the principle still holds: the more paper on the desk, the easier it
is for an important line to get lost in the middle of the pile.

So a big desk doesn't fix it on its own. Filling the window with the whole project "just
in case" lowers the odds that the model pays attention to exactly what matters.

## Context engineering: choosing what goes on the desk

If the model only knows what's on the desk, what you can change is what goes on it, in
what order and for how long. That has a name, context engineering, and it's work done
outside the room.

Scarlett Zhao, who runs product at NomNow, a calorie-counting app you talk to, says that
reorganizing how the user profile showed up in the context improved accuracy more than
the last model swap. It took hours, while each model swap cost two to three weeks of
tuning. Swapping the person in the room helps, and tidying their desk sometimes helps more
and costs a lot less.

## What to do about it

In practice, there are better ways to handle the `legacy` warning than saying it once in
the chat.

A rule that always applies goes in a project instructions file, like `AGENTS.md`, which
the harness puts at the top of the desk on every call. Said once in the chat, it becomes
one more paper in the pile and can vanish in the summary.

The state of the task deserves a file too. A `PROGRESS.md` with what's done and what's
left survives any summary, and the agent reads it again when it needs to. You can go
further and ask it to rewrite the plan at the end of the conversation every so often. The
Manus team calls this recitation, and it works because the end of the desk is where the
model pays the most attention.

Pointing to the two files that matter gets you more than pasting the whole folder. The
same goes for tools: each one you plug into the agent has a description that takes up
desk space on every call, even when nobody uses it.

And a new task calls for a new session. When the subject changes, starting fresh with a
short summary of what matters is cheaper and more reliable than dragging along the full
desk from the previous task.

## Where what you explained went

Back to the opening scene: your warning was either summarized off the desk or buried in
the middle of the pile. Either way, the person in the room did what they know how to do
with what they had in front of them. Repeating the warning louder doesn't fix it; what
fixes it is putting the warning somewhere it can't fall off.

One question is left. So far, the person in the room writes notes and the assistant
carries them out. Is that already an agent, or still a chat with extra steps? That's the
next article.

## To go deeper

- Scarlett Zhao, [Context Engineering Is the New Moat](https://generativeai.pub/context-engineering-is-the-new-moat-e6277e724b90), Generative AI
- Nelson F. Liu et al., [Lost in the Middle: How Language Models Use Long Contexts](https://arxiv.org/abs/2307.03172), arXiv
- Yichao Ji, [Context Engineering for AI Agents: Lessons from Building Manus](https://manus.im/blog/Context-Engineering-for-AI-Agents-Lessons-from-Building-Manus), Manus
- Ana Bildea, [How to Build Production-Ready AI Agents: MCP, CLI, and Skills](https://medium.com/agentic-builders/how-to-build-production-ready-ai-agents-mcp-cli-and-skills-the-right-tool-for-the-right-job-701dc102863f), Agentic Builders
- Pravash, [LLM vs RAG vs MCP: I Finally Know When to Use Each One](https://levelup.gitconnected.com/llm-vs-rag-vs-mcp-i-finally-know-when-to-use-each-one-77403510ba1d), Level Up Coding
