Class WindowCompactionStrategy
java.lang.Object
org.springframework.ai.session.compaction.WindowCompactionStrategy
- All Implemented Interfaces:
CompactionStrategy
Keeps the recent conversation in the view and covers the rest: the one compaction
strategy, configured by a
CompactionWindow, the last events, the last turns or
a token budget, and optionally a CompactionSummarizer that condenses what
leaves the view into a summary turn.
One pass, whatever the window:
- The latest stored system message, the system prompt, is pinned at the front of the view and never summarized; every earlier stored system message is superseded and leaves the view with a pass that cuts, wherever it sits.
- The events before the first turn, a pre-seeded preamble, are pinned too: they are not a turn and are never cut.
- Without a summarizer, the summary a previous pass left is pinned and carried forward; with one, it is handed to the summarizer as the prior summary and covered by the new summary.
- The window gives the raw cut among the turns. The cut moves forward to the next turn start, so a turn is never split, and back to the newest turn when it would cover everything, so the newest turn stays even when it alone exceeds the window.
- The turns before the cut leave the view, the rest stay. With a summarizer, the summary turn stands in for the covered events; a summarizer that returns nothing leaves the view unchanged.
SessionService.compact(java.lang.String, org.springframework.ai.session.compaction.CompactionTrigger, org.springframework.ai.session.compaction.CompactionStrategy) records the result as an
appended boundary.- Since:
- 2.1.0
- Author:
- Christian Tzolov
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CompactionWindowThe window of a strategy built without one: the last 20 events. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()compact(CompactionRequest request) Decides how to compact the view.The rule this strategy cuts by.
-
Field Details
-
DEFAULT_WINDOW
The window of a strategy built without one: the last 20 events.
-
-
Method Details
-
builder
-
getWindow
The rule this strategy cuts by. -
compact
Description copied from interface:CompactionStrategyDecides how to compact the view.- Specified by:
compactin interfaceCompactionStrategy- Parameters:
request- the session, its active view and the view's turn count- Returns:
- the decision;
CompactionResult.unchanged()when nothing should leave the view
-