Your chatbot starts losing the thread after about ten turns. What are your options for managing conversation history?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
First, diagnose before fixing, because "loses the thread at ten turns" is almost never the context window filling up. Ten turns of chat is a few thousand tokens against a window of hundreds of thousands. The usual causes are that you are truncating history somewhere and did not realise, that the important fact was stated at turn 3 and is now buried under low-signal chatter, or that your system prompt is being diluted.
Full worked answer with diagram
First, diagnose before fixing, because "loses the thread at ten turns" is almost never the context window filling up. Ten turns of chat is a few thousand tokens against a window of hundreds of thousands. The usual causes are that you are truncating history somewhere and did not realise, that the important fact was stated at turn 3 and is now buried under low-signal chatter, or that your system prompt is being diluted.
The standard strategies, roughly in order of sophistication:
- Full history. Send everything. Correct until it is not. Cheap to build, and prefix caching makes it cheaper than people expect, since each turn extends a prefix you already paid to cache.
- Sliding window. Keep the last N turns. Simple, and it loses exactly the durable facts you care about. It also invalidates your cache every turn, because dropping from the front changes the prefix.
- Summary buffer. Summarise older turns into a running summary, keep recent turns verbatim. This is the workhorse. Compact in large chunks rather than every turn, so you amortise both the summarisation call and the cache invalidation.
- Retrieval over history. Embed past turns, pull back the relevant ones. Useful for very long-lived threads, and it breaks temporal coherence if you are not careful.
The move that actually fixes the reported symptom is different from all four: extract durable state into a structured object and re-render it every turn. The user's name, their constraints, decisions already made, the current task. A ~200 token <session_state> block at a stable position beats hoping the model re-reads turn 3 of a 40-turn transcript. It also makes the state inspectable and testable, which a transcript never is.
Summarisation is lossy in an adversarial way: the detail you dropped is the one the next turn needed. So keep recent turns verbatim, and never summarise the current user request.
Worth sketching. Draw the assembled prompt top to bottom and the state block stops sounding like a fifth strategy and starts looking like a separate lane.
flowchart TD
A["System prompt"] --> B["Running summary<br/>of older turns"]
B --> C["session_state:<br/>facts, constraints, decisions"]
C --> D["Last N turns verbatim"]
D --> E["Current user turn"]
F["State extractor<br/>runs every turn"] --> C
G["Compaction at a threshold,<br/>in large chunks"] --> B
What a good answer covers
- First, diagnose before fixing, because "loses the thread at ten turns" is almost never the context…
- Ten turns of chat is a few thousand tokens against a window of hundreds of thousands
- The usual causes are that you are truncating history somewhere and did not realise, that the important…
- Full history
- Sliding window
Key terms: Full history · Sliding window · Summary buffer · Retrieval over history
In the glossary: Prefix caching · Compaction
Interviewer follow-ups to expect
Where would you place the summary and the recent turns to keep prefix caching effective?
What breaks when you summarise a conversation that contains tool calls and their results?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep