Context Compaction
In this article
- Plan a compaction pass that applies the techniques in order of what each one loses and stops at the first step that brings the history under its target.
- Say which items of a long history stay word for word, which become placeholders that name their source, and which become a structured summary.
- Explain why a second summary written from the first one can drop a fact the first one kept.
- Terms defined here: context compaction, summary drift.
Overview
Forty turns into a support chat, the history that the application sends with every request has grown to 19,000 tokens of turns and tool results. The application has a rule: past 17,500 tokens, the history must shrink before the next model call. The company is Brightline, the invented home-internet provider of the earlier lessons, and every page and number here is made up.
Its support assistant is a chat assistant on Brightline's website that can look up an order, issue a refund up to an approved limit and search help pages, through the tools lookup_order, issue_refund and search_help. The question is practical: how do you shrink the history without losing what later turns need?
The short answer is a ranking: apply the ways of shrinking in order of what each loses, and stop as soon as the history fits.
Sign in to keep reading
The rest of this article opens with an account. An account also keeps your progress and quiz results on every device, and lets you follow news for up to five topics.
Still to read in this article
- What compaction is
- When it runs
- The order of loss
- A structured summary
- How a summary becomes the history
- Summary drift
- Common mistakes
- Sources
- Check yourself, 4 questions