← Table of Contents · Page 219 of 868
COMPACTION AND SUMMARIZATION
Part 3 of 10
KEEPING RECENT MESSAGES, SUMMARIZING OLDER ONES
A standard compaction strategy draws a line through the history.
Messages after the line are kept in full detail.
Messages before the line are replaced by a summary.
Why keep recent messages in full?
Because the agent is in the middle of its work, and the latest steps contain exact details it is actively using: the precise file content it just read, the exact error it is fixing, the last thing the user said.
Summarizing those would risk losing precision at the worst moment.
Older messages are less likely to be needed word for word, and their gist is usually enough.
Where should the line go?
A simple rule is to keep the last N messages or the last X tokens in full.
A smarter rule keeps whole logical units together, such as a complete tool call and its result, because splitting them can leave the model confused.
For instance, if the model asked for a file and the file's contents arrived in the next message, both should be kept or both should be summarized together.
The result of compaction looks like this: the system prompt stays at the top, followed by a message containing the summary of the older history, followed by the recent messages in full, followed by the new input.
From the model's point of view, it sees a short briefing and then the live conversation.
Advertisement
Read Aloud:
0:00 / 0:00