Skip to main content

CompressedMemory

Struct CompressedMemory 

Source
pub struct CompressedMemory<M: Memory> { /* private fields */ }
Expand description

A memory decorator that compresses older messages into summaries.

When the message count exceeds threshold, older messages (except the system prompt) are replaced with a single summary message, keeping only the most recent keep_recent messages intact.

The summary is generated by concatenating message content (for simplicity and zero-dependency). For LLM-powered summarization, use a custom strategy by wrapping this decorator with a provider call.

Implementations§

Source§

impl<M: Memory> CompressedMemory<M>

Source

pub fn new(inner: M, threshold: usize, keep_recent: usize) -> Self

Create a new compressed memory wrapping the given inner memory.

  • threshold: Trigger compression when message count exceeds this
  • keep_recent: Number of most recent messages to preserve uncompressed
Source

pub fn threshold(&self) -> usize

Get the compression threshold.

Source

pub fn keep_recent(&self) -> usize

Get the number of recent messages kept uncompressed.

Trait Implementations§

Source§

impl<M: Memory> Memory for CompressedMemory<M>

Source§

fn messages<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<Message>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get conversation messages for a session.
Source§

fn append<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, message: Message, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Append a message to the conversation history.
Source§

fn get_context<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, session_id: &'life1 str, key: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Option<Value>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Get a value from working memory.
Source§

fn set_context<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, session_id: &'life1 str, key: &'life2 str, value: Value, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Set a value in working memory.
Source§

fn recall<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Search for relevant memories.
Source§

fn store<'life0, 'async_trait>( &'life0 self, entry: MemoryEntry, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Store a new memory entry.
Source§

fn create_session<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Create a new session and return its ID. Read more
Source§

fn list_sessions<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List all known session IDs. Read more
Source§

fn delete_session<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete a session and all associated conversation history and working memory. Read more

Auto Trait Implementations§

§

impl<M> !Freeze for CompressedMemory<M>

§

impl<M> RefUnwindSafe for CompressedMemory<M>
where M: RefUnwindSafe,

§

impl<M> Send for CompressedMemory<M>

§

impl<M> Sync for CompressedMemory<M>

§

impl<M> Unpin for CompressedMemory<M>
where M: Unpin,

§

impl<M> UnsafeUnpin for CompressedMemory<M>
where M: UnsafeUnpin,

§

impl<M> UnwindSafe for CompressedMemory<M>
where M: UnwindSafe,

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, 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<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