TokenThresholdEventCompactor
An EventCompactor that compacts events once the most recent prompt reaches a token threshold, keeping a tail of recent events raw (tail retention).
It is intended to run intra-invocation, before each model call: when the most recently observed prompt token count reaches tokenThreshold, every event older than the last eventRetentionSize events (since the previous compaction) is summarized into a single event, while the most recent events are preserved raw to maintain continuity.
Safety net
The window never strands an open interaction: the window is shrunk to its longestSelfContainedPrefix.
Parameters
The compaction configuration; must have token-threshold fields set.
The current agent name, used when estimating the prompt token count.
The current invocation branch, used when estimating the prompt token count.
Functions
Compacts events in the given session. If compaction happened, the new compaction event will be appended to the given sessionService.