← All questions
AgentsMedium· Memory in Agents

What is the "memory overflow" problem, and how do you s...

Every model has a finite context window, and a conversation or task that runs long enough will eventually generate more content than fits inside it — that’s the memory overflow problem, and it’s not solved by just picking a model with a bigger window, since conversations can always grow to fill whatever’s available.

The standard fix is tiering by recency rather than trying to keep everything at full fidelity:

  • Keep the most recent turns verbatim, in full detail.
  • Summarize older turns progressively — the further back something is, the more compressed its representation becomes.
  • For anything stored externally rather than kept in context at all, retrieve only what’s relevant to the current query via similarity search, rather than loading the entire store.

A hundred-message conversation against a small token budget might keep the last five messages in full, summarize the previous twenty-five into a few bullet points, and compress everything before that into a single paragraph — the same principle as database indexing: you don’t load every row into memory, you query for what you actually need right now.

Code playground (Python)