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

config

The compaction configuration; must have token-threshold fields set.

agentName

The current agent name, used when estimating the prompt token count.

branch

The current invocation branch, used when estimating the prompt token count.

Constructors

Link copied to clipboard
constructor(config: EventsCompactionConfig, agentName: String, branch: String?)

Functions

Link copied to clipboard
open suspend override fun compact(session: Session, sessionService: SessionService)

Compacts events in the given session. If compaction happened, the new compaction event will be appended to the given sessionService.