pub trait MemoryStore:
Send
+ Sync
+ 'static {
// Required methods
fn name(&self) -> &str;
fn writable(&self) -> bool;
fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
options: SearchOptions,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn description(&self) -> Option<&str> { ... }
fn max_search_results(&self) -> Option<usize> { ... }
fn extraction(&self) -> Option<ExtractionConfig> { ... }
fn implements_add(&self) -> bool { ... }
fn add<'life0, 'life1, 'async_trait>(
&'life0 self,
content: &'life1 str,
metadata: Option<JsonObject>,
) -> Pin<Box<dyn Future<Output = Result<JsonValue>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn implements_add_messages(&self) -> bool { ... }
fn add_messages<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
context: AddMessagesContext,
) -> Pin<Box<dyn Future<Output = Result<JsonValue>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn initialize<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn get_tools(&self) -> Vec<ToolSource> { ... }
}Expand description
A memory store backend (MemoryStore, with the declarative MemoryStoreConfig properties as
methods).
Every store is searchable. A writable store also accepts writes through add,
add_messages or both; each write method has an implements_* flag the
manager reads at construction, so set the flag of every write method you implement.
use strands::memory::{MemoryEntry, MemoryStore, SearchOptions};
struct Notes;
#[strands::async_trait]
impl MemoryStore for Notes {
fn name(&self) -> &str {
"notes"
}
fn writable(&self) -> bool {
false
}
async fn search(&self, _query: &str, _options: SearchOptions) -> strands::Result<Vec<MemoryEntry>> {
Ok(vec![MemoryEntry::new("User prefers dark mode")])
}
}Required Methods§
Provided Methods§
Sourcefn description(&self) -> Option<&str>
fn description(&self) -> Option<&str>
What the store contains; included in the tool descriptions.
Sourcefn max_search_results(&self) -> Option<usize>
fn max_search_results(&self) -> Option<usize>
The default maximum number of results per search when the caller passes none.
Sourcefn extraction(&self) -> Option<ExtractionConfig>
fn extraction(&self) -> Option<ExtractionConfig>
Automatic extraction for this writable store; None is off. The defaults run every 5
turns: a store implementing add_messages gets the raw messages (server-side extraction),
one implementing only add gets facts a ModelExtractor distills
with agent.aux_model.
Sourcefn implements_add(&self) -> bool
fn implements_add(&self) -> bool
Whether the store implements add.
Sourcefn add<'life0, 'life1, 'async_trait>(
&'life0 self,
content: &'life1 str,
metadata: Option<JsonObject>,
) -> Pin<Box<dyn Future<Output = Result<JsonValue>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn add<'life0, 'life1, 'async_trait>(
&'life0 self,
content: &'life1 str,
metadata: Option<JsonObject>,
) -> Pin<Box<dyn Future<Output = Result<JsonValue>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Adds one piece of content (add); used by the add_memory tool, MemoryManager::add
and extraction with an extractor. Extraction writes are at-least-once, so tolerate
duplicates. The returned value is store-specific and not read by the manager.
Sourcefn implements_add_messages(&self) -> bool
fn implements_add_messages(&self) -> bool
Whether the store implements add_messages.
Sourcefn add_messages<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
context: AddMessagesContext,
) -> Pin<Box<dyn Future<Output = Result<JsonValue>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn add_messages<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
context: AddMessagesContext,
) -> Pin<Box<dyn Future<Output = Result<JsonValue>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Ingests a batch of conversation messages with their roles (addMessages): the sink for
extraction without an extractor.
Sourcefn initialize<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn initialize<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Async setup that must succeed before the agent runs; the manager calls it in init_agent.
Sourcefn get_tools(&self) -> Vec<ToolSource>
fn get_tools(&self) -> Vec<ToolSource>
Store-specific tools the manager registers next to its own.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".