On this page · 12 sections

A customer has been chatting with a support assistant for twenty turns. In the first two, they gave an order number, got it wrong, and corrected it: not FW-20417 but FW-20471. Since then they have talked about photos, a return label, cleaning the glaze, a discount code, a change of colour, and a neighbour who can take the parcel. Now they ask: “Sorry, which order number did we end up using for this?”

The assistant answers correctly. It feels as if it remembered. It didn’t. In the version of the demo that sends the full history, the application sent all twenty turns again with the question, and the model answered from that. It had no memory of the previous nineteen turns apart from what came with the request.

So “conversation memory” is something the application builds on every request. It decides which messages go into the request, in what form, and what gets left out when the conversation no longer fits. This article is about that decision:

  • What the model actually keeps between calls, and what resending the history costs.
  • What happens when the history no longer fits the context window, which turned out to be quieter than I expected.
  • Four ways to make it fit: the last N turns, a token budget, a running summary, and a structured case record, and which facts each one loses.

The companion demo measures all three on twelve scripted support chats. The scope is one conversation. What an application carries between separate conversations is the subject of “Memory in AI Agents: What Does an Agent Actually Need to Remember? (opens in a new tab)”.

Try to Understand It This Way

Imagine a support desk where every message from the customer is handled by a different colleague, someone who has never seen the case. All they get is a folder that you hand them, and they answer from what’s in it.

You decide what goes in the folder. You can put in the whole transcript. You can put in only the last few pages. You can write a summary on the first page, or fill in a form: order number, problem, where the case stands. Your colleague can’t ask for a page you left out. And if the folder is too thick for their desk, the mail room removes pages from the front before it reaches them, and nobody tells you.

The colleague is a model call. The folder is the request. What you put in it is conversation state. The mail room is the model server enforcing its context window, and as we’ll see, on the server I measured, it really does remove pages without saying so.

The strategies in this article are different ways of filling the folder, and each one decides in advance what the next colleague will be unable to know.

The Model Keeps Nothing

OpenAI’s guide to conversation state says it directly: “While each text generation request is independent and stateless, you can still implement multi-turn conversations by providing additional messages as parameters to your text generation request.” The same is true of a local model behind Ollama: a request is the whole of what the model sees.

One distinction is worth making early, because it comes up again below. A model server may keep the computation it did for an earlier request and reuse it when the next request starts the same way. That makes a repeated beginning cheaper to process. It isn’t the model remembering the conversation: the conversation still has to be in the request.

The demo’s first measurement makes that concrete. The same 48 test questions, asked at the end of eight conversations (more on the setup below):

Test, 48 probes Correct Stale Both Not stated Wrong Invented
No history 0 0 0 48 0 0
Full history 43 2 1 1 1 0

With no history, the model said it didn’t have the information every time, 48 of 48. That’s the right behaviour, and also the whole point: everything it “knew” in the second row came from the request.

Hosted APIs can store the history for you. OpenAI’s Responses API can chain a request to the previous response with previous_response_id, or keep a conversation object. That changes how the application stores and refers to the conversation, not what the model needs: the earlier messages are still part of the input for every later response. The same guide says: “Even when using previous_response_id, all previous input tokens for responses in the chain are billed as input tokens in the API.” The history is still processed on every turn.

What resending costs

If the application sends the whole history every time, each request is bigger than the last. In the demo’s conversations, the request grows from about 170 tokens at turn 1 to about 2,700 at turn 20. Over twenty turns, a conversation sends between 10.6 and 11.4 times the size of its final request, because every earlier turn is sent again on every later one.

That sounds expensive, and in tokens sent and billed it is. But it isn’t necessarily expensive to compute. A model server can keep the processed state of a prompt and reuse it when the next request starts with the same messages. “How LLM Inference Works (opens in a new tab)” measured this prompt cache on its own. Here it shows up in the conversation itself: Ollama’s server log records how many tokens it actually evaluated for each request, and for the eight test conversations, sent one turn after another, it evaluated a median of 9% of each request. At turn 20 that was 112 to 133 tokens of 2,672 to 2,796. The rest came from the cache.

Two things to keep apart here:

  • What is sent grows with every turn. It’s what a hosted API bills as input and what has to fit in the context window. Ollama’s prompt_eval_count reports this whole number even when most of it came from the cache.
  • What is recomputed depends on the server’s cache. The 9% is a measurement of Ollama 0.40.16 on these requests, sent back to back, not a general saving. A request that arrives after the cache was evicted pays for everything again, and one whose beginning changed pays again from the first changed token on.

The second point matters for the strategies later. A strategy that changes the beginning of the request, such as a summary placed right after the system prompt, makes the server recompute everything after it whenever the summary is rewritten. I didn’t measure that cost here; it follows from how a prefix cache works.

The Experiment

The demo uses a fictional online homeware shop, Fernwick Goods, and twelve scripted support chats of 20 turns each. Every message is written in advance, the assistant’s included, so every strategy builds its request from exactly the same transcript. With the system prompt, each chat is 2,612 to 2,880 tokens: too long for a 2,048-token context window (see “Tokens, Context Windows, and Why They Matter (opens in a new tab)”), comfortable in an 8,192-token one.

After turn 20, six probe questions ask the model for facts from the chat, one at a time:

  • The order number, which was corrected in half of the chats.
  • The issue, such as damaged or wrong item, which also changed in three.
  • The status of the case, which moves on as the chat goes (return label sent, replacement sent, and so on).
  • Three other details: a date, a colour, a delivery instruction, an amount.

Each fact has a position: the last turn in which its current value is mentioned. Early is turns 1 to 5, middle 6 to 15, late 16 to 20. Positions are computed from the text, not declared.

Four of the chats were used to develop the prompts; the other eight were held out and used for nothing until the final run. The numbers in this article are from those eight: 48 probes per strategy. Every answer was first graded mechanically, against the accepted forms of the fact’s current and earlier values. Then, across the whole run, 310 answers were read and labelled by hand: every answer the check didn’t grade correct, every answer about the status, and a fixed random sample of ten of the remaining correct answers for each strategy and experiment. The final grade is the hand label where an answer was read; the rest are answers that passed the mechanical check. Reading the sample caught one mechanical false positive, which is why the hand labels decide.

Implementation note: the setup, the grades, and what's frozen
Model llama3.2:3b (ID a80c4f17acd5, Q4_K_M), temperature 0, seed 1
Server Ollama 0.40.16, /api/chat without streaming
Windows num_ctx 8192 for the full history and the growth measurement; 2048 for the experiment past the window, the strategies, and the summary and record updates
Prompt limit 1,920 tokens, the whole rendered request, leaving 128 for the answer
Token counts Llama 3.2’s tokenizer on the request rendered as the model’s chat template renders it; equal to Ollama’s prompt_eval_count in all 880 requests per run that fit the window
Machine Apple M4 Pro (24 GB), macOS 26.6.2
Runs Python and JavaScript, 952 model calls each, 2026-11-16; all records and both reports identical outside timings

Grades. Correct; stale (an earlier value given as the current one); both (current and earlier, without saying which is current); not stated (says it doesn’t know); wrong (another value from what the model was sent, including a summary or a case record); invented (a value in neither the conversation nor what the model saw). For status, an answer that says the case is closed counts as correct only where the conversation says so. 310 answers were read by hand; the final grade is the hand label where an answer was read, and otherwise the mechanical “correct”.

What was frozen, and when. The conversations, facts, probes, and settings were committed before any code. A first step checked the instruments on this Ollama version before any experiment. The prompts were developed on the four development chats in three rounds and frozen by a rule set in advance, and N for the recent-turns strategy was computed from those chats. An earlier Python run was stopped from outside after 334 of its 952 calls; it was kept and excluded, and the run was started again from the beginning.

Two limits of the instruments. In four conditions where the model never saw it, an answer still gave the right size of a mirror, “60 cm”: a guess (it’s a common size), not memory. And the check of whether a value was in the request matches the accepted forms only, so it misses a value that a summary paraphrased; this happened three times.

Past the Window

Start with the simplest strategy, sending everything, and give it a window too small for it. Each request is 2,632 to 2,908 tokens; the window, set with num_ctx, is 2,048.

I expected an error. Anthropic’s API, for example, documents one: “If the input alone already exceeds the model’s context window, the API returns a 400 invalid_request_error (“prompt is too long”) on every model.” Ollama 0.40.16 accepted all 72 requests (test and development chats together) with no error and no warning, in the response or in its log, and answered every one.

What it did instead is visible only in a number. Ollama’s prompt_eval_count came back as 1,951 to 2,047, well under what was sent. The prompt the model evaluated matched exactly one ending of the conversation: the system prompt followed by every message from turn 5, 6, or 7 onward. So the server dropped the first turns, whole messages from the start, and kept the system prompt. Nobody was told.

The model then answered from what was left:

  • Asked for the order number, given in turn 2 of that chat and dropped: “The order number for the broken mirror is #FWG001234.”
  • Asked for a loyalty card number from turn 2: “I don’t have that information. I can check your account details for you, though. Let me just check… Your loyalty card number is LW123456.”

Across the 72 requests, 16 probes asked for a value that had been sent but dropped. One of those answers was correct, and it was the “60 cm” guess. Where the value survived the cut, 42 of 56 answers were correct.

A second cut, during the answer

There was a second, smaller surprise. Ollama trimmed each request to just under 2,048 tokens, which left 1 to 97 tokens of room for the answer. In 22 of the 72 answers that wasn’t enough, and the server’s log shows what it did when an answer reached the end of the window (two lines from one request’s log, the timestamps removed):

slot context shift, n_keep = 5, n_left = 2042, n_discard = 1021
slot      release: id  0 | task 773 | stop processing: n_tokens = 1075, truncated = 1

It discarded 1,021 tokens of what the model was reading, about half the window, and carried on writing. The response doesn’t mention it. Twelve of those 22 answers were still correct, but each was finished by a model that had lost half of its input partway through.

So on this server, an oversized conversation fails silently twice: messages are dropped before the answer, and context can be dropped during it. The first shows up only as a prompt_eval_count smaller than what you sent. The second shows up only in the server’s log.

This is one server’s behaviour, and providers differ. Anthropic documents an error for oversized input. OpenAI’s guide warns that exceeding the window “might result in truncated outputs”. Ollama’s documentation of context length explains how to set it but doesn’t describe what happens to a request that is longer. The general lesson isn’t “servers truncate”. It’s that an application shouldn’t leave this decision to the server, because it won’t necessarily hear about it.

Four Ways to Make It Fit

The application can make the decision itself. Each of these strategies keeps the request under 1,920 tokens (the window minus 128 tokens for the answer), and each decides what the next call will be unable to see.

  • Last N turns. Keep the 13 most recent turns. 13 is the largest N that fit for every development chat; on the test chats it sent 1,731 to 1,888 tokens.
  • Token budget. Add messages from the newest backwards until the next one doesn’t fit. This fills the space more precisely than a fixed N.
  • Summary plus recent turns. Keep the last 4 turns as they are, and replace everything before them with a running summary written by the model. The summary is updated every 4 turns, by a separate call that rewrites the previous summary with the turns leaving the window.
  • Case record plus recent turns. Keep the last 4 turns, and replace everything before them with a small structured record: order number, issue, and status. A separate call updates the record after every turn.

Here is what each one got right on the 48 test probes:

Strategy Prompt tokens (median) Correct Stale Both Not stated Wrong Invented
Full history, 8,192 window (reference) 2,808 43 2 1 1 1 0
Last 13 turns 1,802 28 1 0 12 6 1
Token budget 1,894 30 1 0 5 8 4
Summary + last 4 turns 919 33 2 0 7 3 3
Case record + last 4 turns 662 18 0 0 15 12 3

And by where the fact sat in the conversation:

Correct, by position Early (of 11) Middle (of 20) Late (of 17)
Full history 11 19 13
Last 13 turns 1 15 12
Token budget 1 16 13
Summary + last 4 turns 9 14 10
Case record + last 4 turns 4 4 10

Windows lose the beginning

The two window strategies behave almost identically, and the reason is simple: on the test chats both kept the last 13 or 14 turns, so a fact stated in the first five turns was never in the request. One of 11 early facts was answered correctly by each, and in both cases it was the “60 cm” guess.

What the model does with a missing fact matters as much as the loss. Often it said it didn’t have the information, which is the honest failure. Sometimes it answered from whatever was left. Asked where big parcels are usually left (behind the blue bin, turn 4), the last-13-turns request produced: “You said big parcels usually get left at the front step next to a green door with a brass number 12, which is two streets over from your actual house.” That’s a detail from a later turn about a misdelivery, presented as the answer.

Windows have one strength the table shows: everything they keep, they keep word for word. Late facts did as well as with the full history, and middle facts only a little worse.

A summary keeps the beginning, roughly

The summary recovered 9 of 11 early facts with half the tokens of a window (a median 919 against about 1,800 to 1,900). That’s the case for summaries, and it’s real.

It also showed the costs of letting a model rewrite the history:

  • Summaries grow until they’re cut off. The summary call has an output limit of 300 tokens. The prompt asks for at most 150 words, and the model mostly ignored it, adding notes on every update. 29 of 48 updates reached the limit and were cut mid-sentence, including 9 of the 12 final summaries. The summaries here listed facts in the order they came up, so the cut removed the most recent additions first.
  • A summary can keep the wrong version of a fact. In one chat the customer first described the towels as stained, then realised they were simply the wrong colour. The summary kept the first description, and the answer followed it: “The towels you received had a bluish tinge and were discolored.”
  • A summary can lose what it once had. On the test chats, 12 facts appeared in the input of a summary update and were missing from the final summary.
  • And the answer can still invent. Asked for the status of a refund, one answer said: “The latest is that the Orrin floor lamp has been shipped out.” The customer hadn’t ordered it.

A case record is only as good as its extraction

The structured record was the smallest request, a median 662 tokens, and the worst overall: 18 of 48. Two things went wrong.

First, it holds only what it has fields for. The three “other” facts of each chat, such as dates and delivery instructions, weren’t in it, so for those the answer depended on the last 4 turns; on the 24 test facts outside the record, it said “not stated” 14 times.

Second, and more interesting, the extraction was wrong in ways the answers then repeated as fact. The record’s status is a judgment (“where does the case stand?”), made by a 3B model after every turn. It ended “resolved” in 10 of the 12 chats, and only one of those cases had been closed. In 6 of the 10, the change to “resolved” came at a turn where the customer said thanks. The answers quoted it back: “The issue has been marked as resolved, and the case record now reads: {“order_id”: “FW-90385”, “issue”: “wrong item”, “status”: “resolved”}“. The refund had been issued, but the conversation never closed the case, and no wrong item was ever sent.

The order number shows the same thing on a field that should be easy. In one chat the customer corrected the order number at turn 14, from FW-60744 to FW-60474. The record took the correction and wrote FW-06047, a number that appears nowhere in the conversation, and the answer repeated it: “The rug is on order FW-06047.” Compressing the history into fields doesn’t remove the risk of losing information. It moves the risk into the extraction step, where the error becomes part of every later request.

What maintaining them costs

The two compressed strategies send smaller prompts for each answer, but keeping them up to date has a cost the answer’s prompt doesn’t show:

Per conversation Summary Case record
Model calls to maintain it 4 20
Input tokens for those calls (median) 3,609 12,591
Output tokens (median) 1,086 502
Time (median, Python run) 23.9 s 10.1 s

Every update is also another chance to introduce an error, which the answers inherit.

Two caveats before reading too much into the ranking. These are eight conversations and one small model. And on the four development chats, graded the same way, the order was less clear: the full history first again (22 of 24), but the summary only tied the token budget (16 each), and the case record tied the last 13 turns (13 each). What I’d take from the results is the shape of each failure, not the ranking.

What Breaks

  • Silent truncation. The server drops the start of the conversation and answers anyway. The only sign is a prompt token count smaller than what you sent.
  • A second cut during the answer. When the trimmed request leaves no room, the server can discard context mid-answer. Only the server log says so.
  • Early facts disappear first. Any window that keeps the most recent turns loses the order number, the original problem, and anything else said at the start: often the most important facts in a support conversation.
  • Corrections get lost or reversed. Even with the full history, one answer gave the colour the customer had changed away from: “The curtains I’m sending you in the exchange are cream, as originally ordered.” A summary can keep the first version of a fact; a record can garble the correction itself.
  • Derived state becomes fact. A wrong summary note or record field gets repeated in later answers, because it’s what the model was given.
  • Summaries outgrow their limit. A summary that adds a line on every update gets cut off, and the newest facts go first.
  • Missing facts get filled in. When the value isn’t in the request, the model sometimes says so, and sometimes produces a plausible order number, card number, or amount.
  • A correct answer can be a guess. “60 cm” was right four times without the model seeing it. A test that only checks answers can’t tell memory from luck; check what was in the request too.

Engineering Decisions

1. Count the request the way the model reads it

A context limit is only useful if your count matches the server’s. The demo renders each request through the model’s chat template, special tokens and all, and counts it with the model’s tokenizer; that count equalled Ollama’s in all 880 requests per run that fit the window. A count of the message text alone would have been short by the template’s tokens on every turn.

2. Never let the server decide what to drop

Choose what leaves the request before you send it, and leave room for the answer. Then check: if the server reports fewer prompt tokens than you sent, something was cut that you didn’t choose. That check costs nothing and would have flagged every oversized request in this experiment.

3. Keep the transcript; treat summaries and records as caches

A summary or a record is derived from the transcript, and both were wrong in ways the transcript wasn’t. Keep the full transcript as the record of what was said, and treat compressed state as something you can rebuild or check against it. Don’t overwrite the source with the compression.

4. Don’t extract what the application already knows

The order number and the case status lived in the conversation only because this demo had nothing else. In a real support system they live in the order system and the ticket system, and the application can read them. From an engineering perspective, a field that the model has to infer from chat, such as “status”, should come from the system that changes the status, not from a model’s reading of the conversation. What the conversation adds (preferences, corrections, things the customer said) is what’s worth summarizing.

5. Test what survives

The probes in this demo are a cheap test you can run on any strategy: script a conversation, plant facts at different turns, correct some of them, and ask for them at the end. Measure the answers, but also whether the fact was in the request, so you can tell a strategy that lost a fact from a model that ignored it.

6. Combine strategies deliberately

Each strategy here failed differently: windows lose the beginning, summaries lose and blur, records hold only their fields and repeat their mistakes. A common design keeps the last turns verbatim, a summary of the rest, and a few critical facts read from the application’s own systems. I didn’t measure that combination, so treat it as a design to test, not a result.

When to Use What

For a short conversation, send the whole history. It was the most accurate strategy by a wide margin, and with a prompt cache, much of the cost of resending may never be recomputed.

When conversations outgrow the window, a recent-turns window is the simplest choice if the important facts are recent, as in a chat about the question just asked. If facts from the start matter later, as in most support and task conversations, a window alone will lose them.

A running summary is worth its maintenance cost when early facts matter and the conversation is long, but only with a length limit that the summary actually respects, and with tests for what it keeps.

A structured record is worth it for a small number of fields that can be extracted reliably, ideally checked against a system of record. For judgments like “status”, I would lean toward reading the system that owns the state rather than asking a model to infer it from chat.

What to Take Away

  • Treat conversation state as the application’s job. The model answers from the request; decide on every turn what goes into it.
  • Keep the transcript as the source of truth. Summaries and records are derived from it and can be wrong; rebuild or check them against it.
  • Decide what to drop before the server does, and leave room for the answer. Compare the server’s prompt token count with yours to catch a cut you didn’t choose.
  • Read facts the application already owns from the system that owns them, instead of asking a model to infer them from the chat.
  • Test what survives: plant facts, correct some, ask for them later, and check both the answer and whether the fact was in the request.

Think About These Use Cases

  • A coding assistant in a long session: The user set a constraint in the first message (“never change the public API”). Forty turns later, the window no longer includes it. Which strategy would keep it, and how would you test that it did?

  • A support chat that hands over to a human agent: The human sees a summary written by the model. What should the summary be checked against, and what should it never be trusted for?

  • A voice assistant with short turns: Hundreds of turns, each a sentence. Would you summarize, window, or extract fields? What changes when a turn is a few tokens rather than a few hundred?

  • A hosted API that stores the conversation for you: You pass a conversation identifier instead of the messages. What does that change about cost, latency, and what the model sees, and what doesn’t it change?

  • A conversation that suddenly gets worse after turn 30: Users say the assistant “forgets” things. What would you log on every request to find out why?

If you want to work through one of these, take it to GPT along with this article. Ask GPT ↗️

  • conversation-state: The companion demo, in Python and JavaScript: the twelve frozen conversations and their probes, the four strategies, the check of what the model saw after Ollama’s truncation, the hand labels, and both runs.
  • Conversation state (OpenAI API documentation): Multi-turn conversations by resending messages, previous_response_id, the Conversations API, and how chained input tokens are billed.
  • Context windows (Claude documentation): How conversation history accumulates in the window, and what the API does when a request is too long.
  • Context length (Ollama documentation): Ollama’s default context lengths and how to change them.

What’s Next?

This article kept the model’s job simple: read the request, answer the question. The application decided everything else, including what the model would see.

In the next article, we’ll start giving the model more of those decisions: “What Is an AI Agent? (opens in a new tab)”, a practical definition of a system in which the model chooses its next step.

← All articles