Skip to main content

CompactAlgorithm

Trait CompactAlgorithm 

Source
pub trait CompactAlgorithm: Send + Sync {
    // Required method
    fn name(&self) -> &str;

    // Provided methods
    fn decide_compact<'life0, 'life1, 'async_trait>(
        &'life0 self,
        context_tokens: u64,
        context_window: u32,
        settings: &'life1 CompactionSettings,
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn select_cut_point<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        entries: &'life1 [SessionTreeEntry],
        settings: &'life2 CompactionSettings,
    ) -> Pin<Box<dyn Future<Output = CutPointResult> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn summarize_prefix<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        request: &'life1 SummarizeRequest<'life2>,
    ) -> Pin<Box<dyn Future<Output = Result<SummaryOutcome, SummarizeError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

Custom compaction algorithm — the extension point behind issue #4.

Every method has a default that reproduces the builtin behavior, so an implementation only overrides the hooks it wants to customize. All methods are async so a future host (e.g. one that calls the LLM from inside the extension) can block on IO.

Required Methods§

Source

fn name(&self) -> &str

Canonical name — matched against CompactionSettings.algorithm.

Provided Methods§

Source

fn decide_compact<'life0, 'life1, 'async_trait>( &'life0 self, context_tokens: u64, context_window: u32, settings: &'life1 CompactionSettings, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Decide whether a compaction should trigger at this context level. Default: the builtin 80%-of-window heuristic.

Source

fn select_cut_point<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, entries: &'life1 [SessionTreeEntry], settings: &'life2 CompactionSettings, ) -> Pin<Box<dyn Future<Output = CutPointResult> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Choose the cut point (entries[..cut] get folded). Must land on a valid index in [0, entries.len()]. Default: turn-boundary-safe keep_recent_tokens walk.

Source

fn summarize_prefix<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, request: &'life1 SummarizeRequest<'life2>, ) -> Pin<Box<dyn Future<Output = Result<SummaryOutcome, SummarizeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Summarize the folded prefix. Default: LLM summarization with the budget-retry loop.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§