Sub topic 12
What summaries lose and how they go wrong
This chapter assumes you can write the compact and build_request functions from earlier chapters and know how a rolling summary is built. Here you will look at what a summary drops and how to limit the damage.
Why summaries are lossy
A summary is a model's rewrite of older messages in fewer tokens. The model decides what matters, and it decides without knowing what the user will ask next. Anything it leaves out is gone, because compaction discards the original messages.
A rolling summary makes this worse. Each pass summarizes the previous summary plus new messages. A detail dropped in pass 2 can never return in pass 5.
Common failure modes
| Failure | What happens | Example |
|---|---|---|
| Dropped detail | An exact value is left out | The summary says "user chose a database" but not which one |
| Rounded value | A precise value becomes vague | "port 8443" becomes "a custom port" |
| Invented fact | The model adds something never said | The summary claims the user "prefers Postgres" |
| Wrong attribution | A suggestion is recorded as a decision | The assistant proposed Redis, the summary says the user picked it |
| Lost constraint | A stated rule disappears | "Never modify the `prod` folder" is not carried forward |
| Drift | Repeated rewrites blur earlier facts | A deadline moves from "Friday" to "soon" over several passes |
Wrong attribution and invented facts are the most harmful. The assistant treats the summary as true and builds on it, and nothing signals that it is wrong.
How the loss accumulates
Reducing the risk
Several changes to your design help. None removes the risk completely.
- Name what to keep in the prompt. The summarization prompt from the earlier chapter lists names, numbers, file paths, and constraints. Keep that list specific to your application.
- Forbid invention. Tell the model not to add facts that are not in the conversation.
- Cap the length. A cap forces choices, so pair it with a strong keep list.
- Pin critical facts. Put hard constraints and key decisions in a pinned message instead of relying on the summary to carry them.
- Keep the originals. Write the full history to storage before compacting. You can then audit a summary or rebuild it with a better prompt.
- Label the summary. The
build_requestfunction prefixes it with "Summary of the earlier conversation:". This tells the model it is reading a compressed record, not a verbatim one.
Storing originals before compaction
This wrapper archives the messages that are about to be folded away. It reuses compact from the earlier chapter.
def compact_with_archive(history, summary, trigger_tokens, keep_recent, summarize, archive):
# archive is a list that receives every message removed from the live history.
new_summary, recent = compact(history, summary, trigger_tokens, keep_recent, summarize)
removed_count = len(history) - len(recent)
if removed_count > 0:
archive.extend(history[:removed_count])
return new_summary, recentThe recent list is always a suffix of history, so everything before it was folded into the summary. The archive keeps those messages in order. In production, write them to a database or file instead of a list.
The next chapter turns this manual check into an automated test.
Exercise
A user said "Deploy only to the staging server, never production." After three rolling summaries, the summary reads "The user is working on deployment." Name the failure mode, and give two design changes that would have prevented it.
Show answer
This is a lost constraint, made worse by drift across repeated rewrites. Two preventions: pin the deployment rule in a pinned message so it never passes through the summarizer, and add "constraints and preferences the user stated" to the keep list in the summarization prompt. Archiving the originals would also let you rebuild the summary.