pub trait Memory: Send + Sync {
// Required methods
fn add_message(
&self,
message: &Message,
) -> impl Future<Output = Result<()>> + Send;
fn get_messages(&self) -> impl Future<Output = Result<Vec<Message>>> + Send;
fn clear(&self) -> impl Future<Output = Result<()>> + Send;
// Provided method
fn with_messages<R, F>(
&self,
f: F,
) -> impl Future<Output = Result<R>> + Send
where F: FnOnce(&[Message]) -> R + Send,
R: Send { ... }
}Expand description
Trait for conversation memory backends. Stores and retrieves messages for agent context.
Required Methods§
Sourcefn add_message(
&self,
message: &Message,
) -> impl Future<Output = Result<()>> + Send
fn add_message( &self, message: &Message, ) -> impl Future<Output = Result<()>> + Send
Appends a message to the history. Order is preserved.
Takes a borrow so callers that keep the message (the agent runner appends it to its working log after persisting) don’t clone it per iteration. Backends that store owned messages clone internally; serializing backends (Redis, SQLite) never need ownership at all.
Provided Methods§
Sourcefn with_messages<R, F>(&self, f: F) -> impl Future<Output = Result<R>> + Send
fn with_messages<R, F>(&self, f: F) -> impl Future<Output = Result<R>> + Send
Runs f over the stored messages without handing out an owned copy.
The default implementation falls back to Memory::get_messages
(one full clone); in-process backends override it to borrow their
storage under the lock, so read-only consumers (serializing history
to disk, measuring it, rendering it) don’t pay an O(history) deep
copy per call.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".