Skip to main content

MemoryStore

Trait MemoryStore 

Source
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§

Source

fn name(&self) -> &str

The store’s unique name, used to target it in the search and add tools.

Source

fn writable(&self) -> bool

Whether the store accepts writes. A writable store implements at least one write method.

Source

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,

Searches the store, most relevant first.

Provided Methods§

Source

fn description(&self) -> Option<&str>

What the store contains; included in the tool descriptions.

Source

fn max_search_results(&self) -> Option<usize>

The default maximum number of results per search when the caller passes none.

Source

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.

Source

fn implements_add(&self) -> bool

Whether the store implements add.

Source

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.

Source

fn implements_add_messages(&self) -> bool

Whether the store implements add_messages.

Source

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.

Source

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.

Source

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".

Implementors§