pub trait Memory: Send + Sync {
// Required methods
fn get(&self, key: &str) -> Option<String>;
fn entries(&self) -> Vec<(String, String)>;
fn set(
&self,
key: impl Into<String>,
value: impl Into<String>,
) -> Option<String>;
fn remove(&self, key: &str) -> Option<String>;
// Provided methods
fn compile(&self) -> String { ... }
fn store(
&self,
key: impl Into<String> + Send,
value: impl Into<String> + Send,
) -> impl Future<Output = Result<(), Error>> + Send { ... }
fn recall(
&self,
_query: &str,
_options: RecallOptions,
) -> impl Future<Output = Result<Vec<MemoryEntry>, Error>> + Send { ... }
fn compile_relevant(
&self,
_query: &str,
) -> impl Future<Output = String> + Send { ... }
}Expand description
Structured knowledge memory for LLM agents.
Implementations store named key-value pairs that get compiled
into the system prompt via compile().
Uses &self for all methods — implementations must handle
interior mutability (e.g. via Mutex).
Required Methods§
Provided Methods§
Sourcefn store(
&self,
key: impl Into<String> + Send,
value: impl Into<String> + Send,
) -> impl Future<Output = Result<(), Error>> + Send
fn store( &self, key: impl Into<String> + Send, value: impl Into<String> + Send, ) -> impl Future<Output = Result<(), Error>> + Send
Store a key-value pair (async). Default delegates to set.
Sourcefn recall(
&self,
_query: &str,
_options: RecallOptions,
) -> impl Future<Output = Result<Vec<MemoryEntry>, Error>> + Send
fn recall( &self, _query: &str, _options: RecallOptions, ) -> impl Future<Output = Result<Vec<MemoryEntry>, Error>> + Send
Search for relevant entries (async). Default returns empty.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".