When to reach for it
- User context must be maintained across multiple turns.
- References to prior statements are expected.
- Conversational flow is critical.
The running message history the agent reads each turn.
Recent conversation turns are retained and replayed so the model has context for the next turn — as a full transcript, a fixed-size window of the last N turns, or a running summary once the raw history outgrows the budget. This is the short-term tier of agent memory.
In practiceA travel-planning chatbot replays the last 20 turns at the start of each response so the model remembers the user said 'window seat only' three messages ago.
Every turn runs the same loop: load the history of this thread, put it in front of the new message, call the model, store what was said. A second step keeps the history inside the token budget.
1 · Every turn
2 · When the history grows too long
| Strategy | In context | Tokens | Seat wish |
|---|---|---|---|
| Full history | Turns 1 to 40 | 12,400 | Yes |
| Last 20 turns | Turns 21 to 40 | 6,100 | No |
| Summary and last 20 turns | A summary of turns 1 to 20, then turns 21 to 40 | 6,500 | Only if the summary kept it |
def reply(thread_id, user_message):
history = store.get_items(thread_id) # before the run
if count_tokens(history) > 4000:
old, recent = history[:-20], history[-20:]
# earlier turns become one summary
history = [summarize(old)] + recent
answer = model(history + [user_message])
store.add_items(thread_id, [user_message, answer]) # after the run
return answerWhen to reach for it
When it backfires
Every turn appends to the buffer; eventually the prompt is mostly stale dialogue and the model truncates the most recent — and most relevant — turns.
Countermeasure
Cap the buffer by token budget. Summarize older turns into a single block, or fall back to retrieval against an episodic store.
To stay under budget, older turns are compressed into a summary. The one concrete fact a later turn depends on — a booking code, an exact figure — is exactly what the summary paraphrases away.
Countermeasure
Extract and pin durable facts (IDs, preferences, commitments) to a structured slot before summarizing the prose, so compaction never touches them.
Threat exposure
Adopting this pattern opens these attack surfaces. Each links to its entry in the threat model.
Full threat model →EU law
Duties from EU law that this pattern helps meet, or that land on it. A reading aid, not legal advice.
An engineer's reading aid, not legal advice. The legal texts and their interpretation are authoritative.
Keep going
Search patterns, frameworks, and pages.