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<()>> + Send { ... }
fn recall(
&self,
_query: &str,
_options: RecallOptions,
) -> impl Future<Output = Result<Vec<MemoryEntry>>> + 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 compile(&self) -> String
fn compile(&self) -> String
Compile memory into a string for system prompt injection.
Always returns the memory usage instructions. Appends a ## Your profile
section containing only user.* and soul.* entries — stable identity
facts safe to embed unconditionally. All other entries are retrieval-only
and surface exclusively via the recall tool.
Sourcefn store(
&self,
key: impl Into<String> + Send,
value: impl Into<String> + Send,
) -> impl Future<Output = Result<()>> + Send
fn store( &self, key: impl Into<String> + Send, value: impl Into<String> + Send, ) -> impl Future<Output = Result<()>> + Send
Store a key-value pair (async). Default delegates to set.
Sourcefn recall(
&self,
_query: &str,
_options: RecallOptions,
) -> impl Future<Output = Result<Vec<MemoryEntry>>> + Send
fn recall( &self, _query: &str, _options: RecallOptions, ) -> impl Future<Output = Result<Vec<MemoryEntry>>> + 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", so this trait is not object safe.