Perfect Recall, Rising Cost
Keeping every word of the conversation, and understanding exactly what that costs you.
Prerequisites: You know what a language model does and have called one at least once.
Free chapter
Keeping every word of the conversation, and understanding exactly what that costs you.
Prerequisites: You know what a language model does and have called one at least once.
A language model has no memory between calls. This is the single most surprising fact for people new to building agents, because the products built on top of models hide it so well.
Here is what actually happens. You send a message. The model reads it, produces a reply, and returns it. Then the model forgets. Completely. Not gradually, not partially. The next call starts from nothing. If you send “My name is Alice” and then send “What is my name?”, the second call arrives at a model that has never heard of Alice.
Try it once without any memory layer and the effect is comic:
You: My name is Alice and I work on agent systems.
Agent: Nice to meet you, Alice.
You: What do I work on?
Agent: I don't have that information. Could you tell me?
The agent is not being difficult. From its side, the second question arrived alone, with no history attached. Every turn is a first turn. The illustration below shows the shape of the problem: two calls, no thread between them.
Something has to carry the conversation forward, and that something lives in your application, not in the model.
Conversation buffer memory is the simplest possible answer: keep every message, and send all of them on every call.
Think of a court stenographer. They type every word spoken in the room, without judgment about what matters. When a lawyer asks “what did the witness say about the timeline,” the stenographer does not summarize or recall from memory. They read the transcript back from the beginning. The record is complete and the reading takes as long as the record is long.
That is buffer memory. There is no cleverness in it. The agent appears to remember because the entire past is placed in front of the model again, every single time. This gives perfect recall, and the cost of that recall grows with every word spoken.
The model does not remember the conversation. Your application remembers it and re-reads it aloud on every turn.
Buffer memory has one data structure and one rule. The structure is an ordered list. The rule is: append, then send everything.
Each entry in the list has two fields. Role says who
spoke: user for the person, assistant for the
agent. Many systems add a third role, system, for standing
instructions that sit at the top and describe how the agent should
behave. Content is the text itself.
The roles matter more than they look. The model uses them to reconstruct who said what. A list where the roles are wrong, or where two user messages appear in a row without a reply between them, produces confused output. Correct alternation is part of the data structure, not a formatting detail.
One turn is one user message plus the reply it produces. The list therefore grows by two entries per turn. After ten turns, twenty entries.
When a new user message arrives, it is appended to the end of the list. The complete list, from the first message to the one just added, is sent to the model. The model reads all of it and produces a reply. That reply is appended too, and the system waits for the next message.
The diagram below traces three turns. Notice that the arrow into the model gets thicker each time: turn one sends one message, turn two sends three, turn three sends five.
Algorithm Sketch: Buffer Memory Turn
1. Receive the user message
2. Append it to the list with role "user"
3. Send the entire list to the model
4. Receive the reply
5. Append the reply to the list with role "assistant"
6. Return the reply to the user
That is the whole technique. It can be built in an afternoon, and almost every agent starts here.
The list lives in memory while the process runs. Restart the process and it is gone. Writing it to a file or a database on each turn, and loading it when the conversation resumes, gives the agent continuity across restarts. This is the humblest possible form of persistence, and it already puts you ahead of most demos.
Note what it does not give you. Reloading the list restores one specific conversation. It does not let the agent recall something the user said in a different conversation, and it does not scale past the point where the list stops fitting in a single call. Chapter 21 handles the first problem properly. The rest of this part handles the second.
Buffer memory has exactly one failure mode, and it is worth understanding precisely, because every technique in the next four chapters is a different response to it.
Everything in the list is re-read by the model on every call, and models bill for what they read. Turn one sends one message. Turn two sends three. Turn ten sends nineteen. The per-turn cost climbs in a straight line.
This is the part that surprises people. Because each turn is more expensive than the last, the running total does not climb in a straight line. It curves upward. A conversation twice as long does not cost twice as much. It costs roughly four times as much.
Put concrete numbers on it. Say each turn adds about 100 tokens of new text. At turn 10, you are sending roughly 1,000 tokens per call. At turn 50, roughly 5,000. But the cumulative spend across those 50 turns is around 125,000 tokens, not 5,000. The chart below shows both curves side by side: the straight line is what you pay per turn, and the curve behind it is what you have paid in total.
The context window is the maximum amount of text the model can read in one call. Buffer memory grows without limit, so eventually the list will not fit. When that happens there is no graceful degradation. The call fails, or the system silently drops the beginning of the conversation, which is worse because it fails quietly and the agent starts contradicting things it agreed to an hour earlier.
There is no warning built into the technique. You get flawless recall right up until you get an error. The illustration below shows the shape of that ending: a container filling steadily with no valve, no overflow pipe, and a hard ceiling.
Bigger context windows push the wall further out. They do not remove it, and they do nothing about the cost curve, which is usually the constraint that bites first.
Best for:
Overkill when:
Tradeoffs:
| Factor | Impact |
|---|---|
| Latency | Low at first, then rising as the model reads more each turn |
| Complexity | Lowest of any technique in this book |
| Cost | Linear per turn, quadratic across the conversation |
| Recall quality | Perfect, until the context window overflows and it becomes zero |
Compared to doing nothing: An agent with no memory layer cannot hold a conversation at all, so buffer memory is not optional, it is the floor. The real question is never whether to keep history but how much of it to keep and in what form. Every remaining chapter in this part answers that question differently: keep only the recent turns, replace old turns with a summary, do both, or trim to an exact budget.
Companion Notebook
The working implementation of this technique is in
conversation_buffer_memory.ipynbin the Agent Memory Techniques repository.