pub struct SummarizationStrategy<P: Provider> { /* private fields */ }Expand description
Summarizes old messages using an LLM provider, preserving recent messages verbatim.
When compaction is triggered, messages older than preserve_recent are sent
to the provider with a summarization prompt. The response replaces the old
messages with a single User message containing the summary, followed by
the preserved recent messages.
§Example
ⓘ
use neuron_context::SummarizationStrategy;
let strategy = SummarizationStrategy::new(provider, 5, 100_000);Implementations§
Source§impl<P: Provider> SummarizationStrategy<P>
impl<P: Provider> SummarizationStrategy<P>
Sourcepub fn new(provider: P, preserve_recent: usize, max_tokens: usize) -> Self
pub fn new(provider: P, preserve_recent: usize, max_tokens: usize) -> Self
Creates a new SummarizationStrategy.
§Arguments
provider— the LLM provider used for summarizationpreserve_recent— number of most-recent messages to keep verbatimmax_tokens— token threshold above which compaction is triggered
Sourcepub fn with_counter(
provider: P,
preserve_recent: usize,
max_tokens: usize,
counter: TokenCounter,
) -> Self
pub fn with_counter( provider: P, preserve_recent: usize, max_tokens: usize, counter: TokenCounter, ) -> Self
Creates a new SummarizationStrategy with a custom TokenCounter.
Trait Implementations§
Source§impl<P: Provider> ContextStrategy for SummarizationStrategy<P>
impl<P: Provider> ContextStrategy for SummarizationStrategy<P>
Source§fn should_compact(&self, messages: &[Message], token_count: usize) -> bool
fn should_compact(&self, messages: &[Message], token_count: usize) -> bool
Whether compaction should be triggered given the current messages and token count.
Source§fn compact(
&self,
messages: Vec<Message>,
) -> impl Future<Output = Result<Vec<Message>, ContextError>> + WasmCompatSend
fn compact( &self, messages: Vec<Message>, ) -> impl Future<Output = Result<Vec<Message>, ContextError>> + WasmCompatSend
Compact the message list to reduce token usage.
Source§fn token_estimate(&self, messages: &[Message]) -> usize
fn token_estimate(&self, messages: &[Message]) -> usize
Estimate the token count for a list of messages.
Auto Trait Implementations§
impl<P> Freeze for SummarizationStrategy<P>where
P: Freeze,
impl<P> RefUnwindSafe for SummarizationStrategy<P>where
P: RefUnwindSafe,
impl<P> Send for SummarizationStrategy<P>
impl<P> Sync for SummarizationStrategy<P>
impl<P> Unpin for SummarizationStrategy<P>where
P: Unpin,
impl<P> UnsafeUnpin for SummarizationStrategy<P>where
P: UnsafeUnpin,
impl<P> UnwindSafe for SummarizationStrategy<P>where
P: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more