pub struct SummarizingCompactor { /* private fields */ }Expand description
Summarization-aware context compactor.
Combines the core sliding_window strategy with an optional summary
that replaces dropped messages. The summary is stored externally via
set_summary and injected after the anchor
messages during the next compaction pass.
§Usage
let compactor = SummarizingCompactor::new(100_000, 50_000, 2);
let agent = Agent::new()
.with_transform_context(compactor.compaction_fn());
// After each turn, if messages were dropped:
compactor.set_summary("Summary of earlier conversation...");Implementations§
Source§impl SummarizingCompactor
impl SummarizingCompactor
Sourcepub fn new(normal_budget: usize, overflow_budget: usize, anchor: usize) -> Self
pub fn new(normal_budget: usize, overflow_budget: usize, anchor: usize) -> Self
Create a new compactor with the given budget parameters.
Sourcepub fn compaction_fn(
&self,
) -> impl Fn(&mut Vec<AgentMessage>, bool) + Send + Sync
pub fn compaction_fn( &self, ) -> impl Fn(&mut Vec<AgentMessage>, bool) + Send + Sync
Returns a closure compatible with Agent::with_transform_context().
Behaves like sliding_window but injects a stored summary after
the anchor messages when compaction occurs. If no summary is stored,
behaves identically to sliding_window.
The summary is consumed after injection — it will not be re-injected on subsequent compaction passes.
Sourcepub fn set_summary(&self, text: impl Into<String>)
pub fn set_summary(&self, text: impl Into<String>)
Store a summary to be injected on the next compaction pass.
This should be called after each turn where context was compacted, passing a summary of the messages that were dropped. In the future this will be generated via an LLM call; for now callers provide the text directly.
Sourcepub fn clear_summary(&self)
pub fn clear_summary(&self)
Clear the stored summary.
Sourcepub fn has_summary(&self) -> bool
pub fn has_summary(&self) -> bool
Returns true if a summary is currently stored.
Auto Trait Implementations§
impl Freeze for SummarizingCompactor
impl RefUnwindSafe for SummarizingCompactor
impl Send for SummarizingCompactor
impl Sync for SummarizingCompactor
impl Unpin for SummarizingCompactor
impl UnsafeUnpin for SummarizingCompactor
impl UnwindSafe for SummarizingCompactor
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> Fruit for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more