Conversation History & Trimming
Appending every turn forever is simple but eventually expensive, slow and noisy. History management decides which turns remain verbatim, which are summarized, and which can be dropped.
function keepRecent<T>(items: T[], count: number) {
return items.slice(Math.max(0, items.length - count));
}
A real policy should be token-aware and importance-aware, not only turn-count based.
Failure modes
- summaries can introduce hallucinated state;
- dropping a user's constraint can violate intent;
- keeping secret-bearing old tool output may expose data unnecessarily;
- repeated summarization can drift.
Practice
- What information should be preserved verbatim?
- Why can recursive summarization drift?
- How would you test a history-trimming policy?
- When is server-side durable state better than keeping facts in chat history?