pub trait Compactor:
Send
+ Sync
+ 'static {
// Required method
fn compact<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
events: &'life1 [GraphEvent],
budget_chars: usize,
ctx: &'life2 ExecutionContext,
) -> Pin<Box<dyn Future<Output = Result<CompactedHistory>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
}Expand description
Operator-supplied compaction strategy.
Receives the full event log plus a character-budget hint and
returns the trimmed view. Async by default so summary-style
implementations can dispatch a ChatModel call (SummaryCompactor
in entelix-agents is the canonical reference); pure-retention
strategies (HeadDropCompactor) simply ignore the future point
and return synchronously inside the async fn body.
Implementations must preserve the ToolCall / ToolResult pair
invariant — the CompactedHistory return type enforces that
structurally; trait authors only need to choose which turns to
retain.
Required Methods§
Sourcefn compact<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
events: &'life1 [GraphEvent],
budget_chars: usize,
ctx: &'life2 ExecutionContext,
) -> Pin<Box<dyn Future<Output = Result<CompactedHistory>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn compact<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
events: &'life1 [GraphEvent],
budget_chars: usize,
ctx: &'life2 ExecutionContext,
) -> Pin<Box<dyn Future<Output = Result<CompactedHistory>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Compact events to fit within budget_chars. The budget is
approximate — implementations measure character length of
the rendered text (closest free proxy for token count
without pulling a tokenizer dependency). The
ExecutionContext carries cancellation + deadline so a
long-running summarisation respects the same lifetime as the
dispatch that triggered it. Returns Error::Config when
the event log violates the pair invariant before
compaction (e.g. ToolResult without a preceding
ToolCall); a well-formed SessionGraph never hits this
path.