Skip to main content

AgentMemory

Trait AgentMemory 

Source
pub trait AgentMemory: Send + Sync {
Show 25 methods // Required methods fn name(&self) -> &str; fn store_resource<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, ns: &'life1 str, resource_type: &'life2 str, content: &'life3 str, metadata: Value, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait; fn list_resources<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ns: &'life1 str, resource_type: Option<&'life2 str>, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryResource>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn store_item<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, ns: &'life1 str, fact: &'life2 str, category: &'life3 str, confidence: f32, source_resource_id: Option<&'life4 str>, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait; fn search_items<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ns: &'life1 str, query: &'life2 str, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryItem>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn list_items_by_category<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ns: &'life1 str, category: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryItem>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn touch_item<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn delete_item<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn delete_stale_items<'life0, 'life1, 'async_trait>( &'life0 self, ns: &'life1 str, older_than_days: u32, min_access: u32, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_summary<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ns: &'life1 str, category: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Option<MemorySummary>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn upsert_summary<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, ns: &'life1 str, category: &'life2 str, text: &'life3 str, item_count: u32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait; fn list_summaries<'life0, 'life1, 'async_trait>( &'life0 self, ns: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemorySummary>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn list_all_namespaces<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn count_items<'life0, 'life1, 'async_trait>( &'life0 self, ns: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; // Provided methods fn update_item_status<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _id: &'life1 str, _status: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn update_item_confidence<'life0, 'life1, 'async_trait>( &'life0 self, _id: &'life1 str, _confidence: f32, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn find_similar_items<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _ns: &'life1 str, _fact: &'life2 str, _threshold: f32, _limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryItem>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn decay_confidence<'life0, 'life1, 'async_trait>( &'life0 self, _ns: &'life1 str, _older_than_hours: u32, _factor: f32, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn search_items_filtered<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, ns: &'life1 str, query: &'life2 str, limit: usize, _filters: &'life3 SearchFilters, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryItem>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... } fn add_relation<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _source_id: &'life1 str, _target_id: &'life2 str, _relation: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... } fn get_relations<'life0, 'life1, 'async_trait>( &'life0 self, _item_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryRelation>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn get_related_items<'life0, 'life1, 'async_trait>( &'life0 self, _item_id: &'life1 str, _limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryItem>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn delete_summary<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _ns: &'life1 str, _category: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn count_items_by_category<'life0, 'life1, 'async_trait>( &'life0 self, _ns: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<(String, usize)>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... }
}
Expand description

Namespace-aware, three-layer memory backend.

All operations are scoped by namespace (ns parameter) to isolate per-role and per-project memory. The three layers are:

  • Resource (Layer 1): Raw immutable conversation/event logs.
  • Item (Layer 2): Extracted atomic facts with embeddings.
  • Summary (Layer 3): Evolving category summaries.

Required Methods§

Source

fn name(&self) -> &str

Backend name (e.g. “sqlite”, “none”).

Source

fn store_resource<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, ns: &'life1 str, resource_type: &'life2 str, content: &'life3 str, metadata: Value, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Store a raw resource (conversation log, event record). Returns the generated resource ID.

Source

fn list_resources<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ns: &'life1 str, resource_type: Option<&'life2 str>, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryResource>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

List resources in a namespace, optionally filtered by type.

Source

fn store_item<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, ns: &'life1 str, fact: &'life2 str, category: &'life3 str, confidence: f32, source_resource_id: Option<&'life4 str>, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Store an extracted fact. Returns the generated item ID.

Source

fn search_items<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ns: &'life1 str, query: &'life2 str, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryItem>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Hybrid search items (FTS5 BM25 + vector cosine) scoped to namespace.

Source

fn list_items_by_category<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ns: &'life1 str, category: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryItem>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

List all items in a category within a namespace.

Source

fn touch_item<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Bump access_count and last_accessed_at for an item.

Source

fn delete_item<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete an item by ID. Returns true if found and deleted.

Source

fn delete_stale_items<'life0, 'life1, 'async_trait>( &'life0 self, ns: &'life1 str, older_than_days: u32, min_access: u32, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete items older than older_than_days with access_count < min_access. Returns the number of items deleted.

Source

fn get_summary<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ns: &'life1 str, category: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Option<MemorySummary>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Get the current summary for a category in a namespace.

Source

fn upsert_summary<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, ns: &'life1 str, category: &'life2 str, text: &'life3 str, item_count: u32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Insert or update a category summary.

Source

fn list_summaries<'life0, 'life1, 'async_trait>( &'life0 self, ns: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemorySummary>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

List all summaries in a namespace.

Source

fn list_all_namespaces<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List all distinct namespaces that have data.

Source

fn count_items<'life0, 'life1, 'async_trait>( &'life0 self, ns: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Count total items in a namespace.

Source

fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Quick health check (e.g. SELECT 1).

Provided Methods§

Source

fn update_item_status<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _id: &'life1 str, _status: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Update the status of a memory item (active, superseded, archived, unverified).

Source

fn update_item_confidence<'life0, 'life1, 'async_trait>( &'life0 self, _id: &'life1 str, _confidence: f32, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Update the confidence score of a memory item (used for dedup merge + decay).

Source

fn find_similar_items<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _ns: &'life1 str, _fact: &'life2 str, _threshold: f32, _limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryItem>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Find items similar to a given fact text using vector similarity. Returns items with cosine similarity above threshold.

Source

fn decay_confidence<'life0, 'life1, 'async_trait>( &'life0 self, _ns: &'life1 str, _older_than_hours: u32, _factor: f32, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Decay confidence of items not accessed in older_than_hours by factor. Returns the number of items decayed.

Source

fn search_items_filtered<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, ns: &'life1 str, query: &'life2 str, limit: usize, _filters: &'life3 SearchFilters, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryItem>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Search items with additional filters (category, confidence, age, status).

Source

fn add_relation<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _source_id: &'life1 str, _target_id: &'life2 str, _relation: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Create a relation between two memory items. Returns the relation ID.

Source

fn get_relations<'life0, 'life1, 'async_trait>( &'life0 self, _item_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryRelation>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get all relations for a memory item (as source or target).

Get items related to a given item, traversing through relations.

Source

fn delete_summary<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _ns: &'life1 str, _category: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Delete a category summary. Returns true if found and deleted.

Source

fn count_items_by_category<'life0, 'life1, 'async_trait>( &'life0 self, _ns: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<(String, usize)>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Count items grouped by category in a namespace.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§