Skip to main content

Compactor

Struct Compactor 

Source
pub struct Compactor { /* private fields */ }
Expand description

Compactor - applies compaction strategies to segments

Implementations§

Source§

impl Compactor

Source

pub fn new(strategy: CompactionStrategy) -> Self

Create a new compactor with the given strategy

Source

pub fn truncate(target_tokens: usize) -> Self

Create a truncation compactor

Source

pub fn sliding_window(target_tokens: usize, window_size: usize) -> Self

Create a sliding window compactor

Source

pub fn strategy(&self) -> &CompactionStrategy

Get the strategy

Source

pub fn compact_truncate( &self, segments: &mut Vec<ContextSegment>, current_tokens: usize, ) -> Result<usize, CompactionError>

Compact segments using truncation strategy

Removes oldest segments (lowest priority first) until target is reached.

Source

pub fn compact_sliding_window( &self, segments: &mut Vec<ContextSegment>, ) -> Result<usize, CompactionError>

Compact using sliding window strategy

Keeps only the most recent N messages in the history.

Source

pub fn summarize(target_tokens: usize, summary_max_tokens: usize) -> Self

Create a summarize compactor

Source

pub fn compact_summarize( &self, segments: &mut Vec<ContextSegment>, current_tokens: usize, ) -> Result<usize, CompactionError>

Compact using summarization strategy

This performs extractive summarization by:

  1. Identifying compactible segments (History, ToolResults)
  2. Extracting key sentences from each segment
  3. Truncating to fit within the summary token budget

Note: For true abstractive summarization (using an LLM), integrate with an external summarization service. This implementation provides a local extractive approach that doesn’t require external API calls.

Source

pub fn compact_extract_key_points( &self, _segments: &mut Vec<ContextSegment>, _current_tokens: usize, ) -> Result<usize, CompactionError>

Compact using key points extraction strategy (not yet implemented)

§Future Implementation

This strategy would:

  1. Identify key decision points, outcomes, and learnings
  2. Extract structured bullet points from conversation
  3. Preserve causal chains and reasoning

Requires integration with an LLM for semantic understanding.

Source

pub fn compact_importance_weighted( &self, _segments: &mut Vec<ContextSegment>, _current_tokens: usize, ) -> Result<usize, CompactionError>

Compact using importance-weighted strategy (not yet implemented)

§Future Implementation

This strategy would:

  1. Score each segment based on semantic importance
  2. Use embedding similarity to current task
  3. Weight by recency, reference count, and explicit importance markers
  4. Remove lowest-scored segments until target is reached

Requires embedding model integration for semantic scoring.

Source

pub fn compact_hybrid( &self, _segments: &mut Vec<ContextSegment>, _current_tokens: usize, ) -> Result<usize, CompactionError>

Compact using hybrid strategy (not yet implemented)

§Future Implementation

This strategy would combine multiple approaches:

  1. First pass: Remove lowest-importance segments (truncate)
  2. Second pass: Summarize remaining compressible content
  3. Third pass: Apply sliding window to history if needed

Requires all component strategies to be implemented.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more