pub struct CompactionContext {
pub tokens_before: u64,
pub reason: CompactReason,
pub context_window: u64,
pub turn: usize,
pub counter: Arc<dyn TokenCounter>,
}Expand description
Metadata passed to ContextCompactor::compact
describing the compaction trigger and current state.
Compactors can use this information to decide how aggressively to compact — e.g. an emergency compaction may use more aggressive summarization than a routine threshold check.
Fields§
§tokens_before: u64Estimated token count before compaction.
The compactor’s input size, computed by the configured
TokenCounter. Compaction aims to bring the post-compaction size
below this so the conversation fits with headroom for the next turn.
reason: CompactReasonWhy compaction was triggered.
Compactors may use the trigger to pick a strategy — an
Emergency trigger warrants more aggressive
summarization than a routine ThresholdExceeded.
context_window: u64The model’s context window size.
The hard upper bound on tokens the model accepts in one request. This is the denominator every compaction threshold and target is expressed against, so the compactor can decide how much to keep.
turn: usizeThe current turn number in the session.
Zero-indexed within the run. Useful for compaction strategies that weight recent turns more heavily, or for correlating a compaction pass back to the turn that triggered it in logs.
counter: Arc<dyn TokenCounter>The token counter for estimating message sizes.
The same counter the driver uses for its compaction trigger — so the
compactor can self-report tokens_after consistently. Compact
implementations should use context.counter.count(&messages) instead
of the static CompactionOutcome::estimate_tokens to match the
driver’s configured counter.
Trait Implementations§
Source§impl Clone for CompactionContext
impl Clone for CompactionContext
Source§fn clone(&self) -> CompactionContext
fn clone(&self) -> CompactionContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more