pub struct InMemoryMemory { /* private fields */ }Expand description
In-memory implementation: stores all messages verbatim.
The simplest Memory implementation: all messages are kept in memory with
no trimming, no summarization, and no persistence; context() returns a
full clone. Default constructs an empty session.
§Comparison
Compared to WindowMemory: the latter trims
to a recent window on retrieval, suiting long conversations (the model’s
context window is finite); this implementation has no budget control —
messages only grow — suiting small conversations that need the full history.
§Example
use molo::memory::{InMemoryMemory, Memory};
let mut memory = InMemoryMemory::default();
memory.record(molo::Message::system("setup")).await?;
memory.record(molo::Message::user("hello")).await?;
memory.record(molo::Message::assistant("hello!")).await?;
let context = memory.context().await?;
assert_eq!(context.len(), 3);
assert_eq!(context[0], molo::Message::System("setup".into()));Trait Implementations§
Source§impl Debug for InMemoryMemory
impl Debug for InMemoryMemory
Source§impl Default for InMemoryMemory
impl Default for InMemoryMemory
Source§fn default() -> InMemoryMemory
fn default() -> InMemoryMemory
Returns the “default value” for a type. Read more
Source§impl Memory for InMemoryMemory
impl Memory for InMemoryMemory
Source§fn record<'life0, 'async_trait>(
&'life0 mut self,
message: Message,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn record<'life0, 'async_trait>(
&'life0 mut self,
message: Message,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Records a message, appending it to the end of the session context. Read more
Source§fn context<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Message>, MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn context<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Message>, MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Returns the full message sequence of the current context (in order of
occurrence), which the agent hands to the Provider as-is. Read more
Source§fn record_protected<'life0, 'async_trait>(
&'life0 mut self,
message: Message,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn record_protected<'life0, 'async_trait>(
&'life0 mut self,
message: Message,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Records a protected message: implementations must not remove it when
trimming. Read more
Auto Trait Implementations§
impl Freeze for InMemoryMemory
impl RefUnwindSafe for InMemoryMemory
impl Send for InMemoryMemory
impl Sync for InMemoryMemory
impl Unpin for InMemoryMemory
impl UnsafeUnpin for InMemoryMemory
impl UnwindSafe for InMemoryMemory
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