Package org.springframework.ai.session.compaction
@NullMarked
package org.springframework.ai.session.compaction
-
ClassDescriptionA
CompactionSummarizerthat asks aChatModelfor a rolling summary of the covered conversation: the prior summary is fed back as context, so each summary builds on its predecessors, and the firstoverlapSizepreserved events are quoted for continuity.The record of one compaction: the payload of aEventType.COMPACTIONevent, typed.What aCompactionTriggerand aCompactionStrategydecide on.What aCompactionStrategydecided for the active view it was given: which events leave the view, which are kept, and the summary that stands in for the ones that leave.Decides what leaves a session's active view.Writes the summary that stands in for the events aWindowCompactionStrategycovers.Decides whether a session's active view is compacted.The rule aWindowCompactionStrategycuts by: how much of the recent conversation stays in the view, measured in events, in turns or in estimated tokens.What the size of a window counts.Fires when any of its triggers fires.One line of text for an event or a message: what compaction counts tokens on, and what a summarizer puts in its prompt.What aCompactionSummarizeris asked to summarize.Fires when the estimated tokens of the view reach a threshold: the latest stored system message, the summaries and the conversation, measured onEventTextwith aTokenCountEstimator, JTokkit by default.Fires when the view holds more than a number of turns: a user message and everything up to the next one.Keeps the recent conversation in the view and covers the rest: the one compaction strategy, configured by aCompactionWindow, the last events, the last turns or a token budget, and optionally aCompactionSummarizerthat condenses what leaves the view into a summary turn.