SlidingWindowMemory

Struct SlidingWindowMemory 

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

Simple sliding window memory that keeps the N most recent messages.

This implementation uses a FIFO strategy where old messages are automatically removed when the window size limit is reached. It’s suitable for:

  • Simple conversation contexts
  • Memory-constrained environments
  • Cases where only recent context matters

Implementations§

Source§

impl SlidingWindowMemory

Source

pub fn new(window_size: usize) -> Self

Create a new sliding window memory with the specified window size.

§Arguments
  • window_size - Maximum number of messages to keep in memory
§Panics

Panics if window_size is 0

Source

pub fn with_strategy(window_size: usize, strategy: TrimStrategy) -> Self

Create a new sliding window memory with specified trim strategy

§Arguments
  • window_size - Maximum number of messages to keep in memory
  • strategy - How to handle overflow when window is full
Source

pub fn window_size(&self) -> usize

Get the configured window size.

§Returns

The maximum number of messages this memory can hold

Source

pub fn messages(&self) -> Vec<ChatMessage>

Get all stored messages in chronological order.

§Returns

A vector containing all messages from oldest to newest

Source

pub fn recent_messages(&self, limit: usize) -> Vec<ChatMessage>

Get the most recent N messages.

§Arguments
  • limit - Maximum number of recent messages to return
§Returns

A vector containing the most recent messages, up to limit

Source

pub fn needs_summary(&self) -> bool

Check if memory needs summarization

Source

pub fn mark_for_summary(&mut self)

Mark memory as needing summarization

Source

pub fn replace_with_summary(&mut self, summary: String)

Replace all messages with a summary

§Arguments
  • summary - The summary text to replace all messages with

Trait Implementations§

Source§

impl Clone for SlidingWindowMemory

Source§

fn clone(&self) -> SlidingWindowMemory

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SlidingWindowMemory

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl MemoryProvider for SlidingWindowMemory

Source§

fn remember<'life0, 'life1, 'async_trait>( &'life0 mut self, message: &'life1 ChatMessage, ) -> Pin<Box<dyn Future<Output = Result<(), LLMError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Store a message in memory. Read more
Source§

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

Retrieve relevant messages from memory based on a query. Read more
Source§

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

Clear all stored messages from memory. Read more
Source§

fn memory_type(&self) -> MemoryType

Get the type of this memory provider. Read more
Source§

fn size(&self) -> usize

Get the current number of stored messages. Read more
Source§

fn needs_summary(&self) -> bool

Check if memory needs summarization
Source§

fn mark_for_summary(&mut self)

Mark memory as needing summarization
Source§

fn replace_with_summary(&mut self, summary: String)

Replace all messages with a summary
Source§

fn is_empty(&self) -> bool

Check if the memory is empty. Read more
Source§

fn get_event_receiver(&self) -> Option<Receiver<MessageEvent>>

Get a receiver for reactive events if this memory supports them
Source§

fn remember_with_role<'life0, 'life1, 'async_trait>( &'life0 mut self, message: &'life1 ChatMessage, _role: String, ) -> Pin<Box<dyn Future<Output = Result<(), LLMError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Remember a message with a specific role for reactive memory

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Message for T
where T: Any + Send + 'static,

Source§

fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>

Convert a BoxedMessage to this concrete type
Source§

fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>

Convert this message to a BoxedMessage
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> OutputMessage for T
where T: Message + Clone,

Source§

impl<T> State for T
where T: Any + Send + 'static,