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§
Provided Methods§
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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,
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".