AI "Forgetting" is Actually Context Overflow (How to Code Eviction)

AI agents do not have memory, they have a budget that gets repaid every single turn, and what looks like forgetting is actually that budget running out.

3:30 video3 min readWatch on YouTube

An AI agent losing the thread halfway through a long task looks like forgetting, but that framing is misleading. Agents don't have memory at all in the way people assume. What they have is a budget, and that budget gets repaid in full at every single turn.

Why agents don't actually forget

The full model, before any example, comes down to three things competing for one fixed budget on every turn: instructions and tool definitions, which are fixed but resent in full every time; history, everything said and observed so far, which only grows; and whatever budget is left over, which is where the model's actual answer has to fit. The part people consistently miss is that nothing persists on the model's side between turns. Every single turn, the entire package, instructions, tool definitions, and the full history, gets packed up and sent again from scratch. The model isn't remembering the last turn. It's being retold everything at full price, every time.

Counting the actual cost in code

Making this concrete: two tools plus one system prompt already adds up to 93 characters of instructions before an agent has done anything at all, and every subsequent observation adds roughly 88 more characters on top. The room available to actually answer isn't a constant, it shrinks turn by turn as instructions and history eat into the shared budget. That reframes the common complaint about an agent losing the thread partway through a task: it didn't forget anything. It ran out of room, and something had to be dropped. That's overflow, not amnesia. The tracking logic itself is short, about ten lines of code, and the key comment sits on the line explaining that instructions are fixed and paid again every turn while history only grows and room is just subtraction.

The four eviction strategies

When the budget doesn't have room for everything, something has to give, and there are four real options for handling that: drop the oldest turns, summarize history and accept some loss of detail, leave older content out and fetch it back on demand when needed, or refuse to proceed and fail loudly rather than silently dropping context. There's no fifth option where everything simply fits forever.

Why a bigger context window doesn't fix it

The obvious objection is to just get a bigger window, so that idea gets tested directly. Doubling the budget moves the point of overflow from turn 13 to turn 36. Doubling it again moves it to turn 81. It never goes away entirely, because history grows linearly while the budget stays a fixed size. Every budget eventually overflows. A bigger window buys more turns before that happens. It does not buy a permanent fix.

Three questions worth asking of any agent

Given all this, there are three questions worth asking about any agent on any project: what's fixed here, and are you repaying for it every single turn? What's growing, and how fast? And when it doesn't fit, what actually gets dropped, and did you choose that deliberately or did a library choose it for you without your input? That third question is what separates people who ship agents that hold up under load from people debugging mysterious failures at midnight. Eviction is a design decision. If you didn't make it explicitly, it still got made, just not by you.

Key takeaways

  • AI agents have no persistent memory; every turn resends instructions, tool definitions, and full history from scratch.
  • What looks like an agent forgetting mid-task is actually the context budget running out, causing something to be dropped.
  • The four eviction strategies are dropping old turns, summarizing history, fetching on demand, and failing loudly.
  • Doubling the context window only delays overflow (from turn 13 to 36, then to 81 in testing); it doesn't eliminate it.
  • Eviction is a deliberate design decision. If you don't choose the strategy, a default library behavior chooses it for you.

Try it yourself

Take an agent you're building and count the characters in your system prompt and every tool definition, then estimate how much each turn adds to history. Figure out which turn you'll run out of room on, and check what your current code actually drops when that happens, rather than assuming it's handled.

Chapters

  1. 0:00Why AI agents have context budgets instead of memory
  2. 0:45Breaking down the 10 lines of code tracking your context window
  3. 1:30Calculating the linear growth of conversation history
  4. 2:10The 4 eviction strategies to handle context overflow
  5. 3:00Why a larger context window is a temporary patch, not a fix
Full transcript(auto-generated, with timestamps)

Why AI agents have context budgets instead of memory

[0:00]Hi, I am Edwait Changen and this video is about why agents do not actually forget. Today we are going to learn where an agent's memory really lives and it is not where most people think. Last week we counted what a single tool costs to describe. Now we add them up across a whole run and find that an agent has no memory at all. It has a budget and it repays that budget every single turn. Here is the whole model before any example. Every turn, three things compete for one budget. Your instructions and tool definitions fixed but resent every single time. the history, everything said and observed so far which only grows and whatever is left over. That last one is where the answer has to fit. And here is the part people miss. Nothing persists on the model's side. Every turn, the entire thing, instructions, tool definitions, the full history is packed up and sent

Breaking down the 10 lines of code tracking your context window

[0:45]Again from scratch. The model is not remembering your last turn. You are retelling it at full price every time. So, let us actually count it. Two tools from last week plus one system prompt. 93 characters of instructions before the agent has done anything at all. Then every observation adds 88 more. Watch the right-hand column. Room to answer is not a constant. It is being spent turn by turn. Which reframes the whole complaint. When an agent loses the thread halfway through a long task it did not forget anything. It ran out of room and something had to be dropped. That is not amnesia. That is overflow. 10 lines and the comment on line four is the one that costs people money. Instructions are fixed and paid again every turn. History only grows. Room is just subtraction. Notice there is no

Calculating the linear growth of conversation history

[1:31]Memory anywhere in this function because there is no memory anywhere in the system. So when it does not fit, something gets dropped and you are the one who chooses what? Drop the oldest turns, summarize them and lose the evidence. Leave them out and fetch on demand or refuse and fail loudly. There is no fifth option where everything simply fits forever. Now the obvious objection, just get a bigger window. So we tested it. Double the budget and the overflow moves from turn 13 to turn 36. Double it again, turn 81. It never goes away. History grows linearly and the budget is a constant. So every budget overflows eventually. A bigger window buys you turns. It does not buy a fix. Which gives you three questions to ask of any agent turn on any project? What

The 4 eviction strategies to handle context overflow

[2:12]Is fixed here and am I repaying for it every turn? What is growing and how fast? And when it does not fit, what gets dropped? Did I choose that or did a library choose it for me? And that third question separates the people who ship agents from the people who debug them at midnight. Eviction is a design decision. If you did not make it, it was still made, just not by you. So the verdict, an agent has no memory. It has a context window and every turn rescends the whole thing from scratch. Instructions, tool definitions, and all of the history. What looks like forgetting is overflow. The history grows, the budget does not, and something has to give. A bigger window does not fix that. In our own measurement, it moved the overflow from turn 13 to turn 81 and no further. So, eviction is the real design decision. Choose what gets dropped deliberately or a default will choose it for you. Your turn. Here is the prompt. Take the agent

Why a larger context window is a temporary patch, not a fix

[3:00]I am building. Count the characters in my system prompt. And in every tool definition, then estimate how much each turn adds to the history. Tell me which turn I run out of room on and what my current code drops when that happens. Run that against your own agent. Most people have never measured the fixed cost and are surprised how much of the budget is gone before the first turn even starts. That was memory and context. Next time, planning when breaking a task into steps actually helps and when it is pure overhead. Adwight Changen for humanitarians AI.

More from Humanitarians AI Fellows

Humanitarians AI Lyrical Literacy Project