Skip to main content

Module memory

Module memory 

Source
Expand description

Agent memory trait — interface for agent memory systems.

Memory allows agents to learn from past interactions and retrieve relevant context for future tasks. Defines the core LoopMemory trait that all memory backends implement, along with the MemoryEntry value type and supporting enumerations.

§Provided Implementations

  • InMemoryStore — Records tool-execution trajectories and retrieves relevant past experiences.

§Quick Start

use loopctl::memory::{LoopMemory, MemoryEntry, MemoryCategory, ConsolidationStats};
use loopctl::error::LoopError;
use std::future::Future;
use std::pin::Pin;
use std::sync::RwLock;

struct MyStore {
    entries: RwLock<Vec<MemoryEntry>>,
}

impl LoopMemory for MyStore {
    fn store(&self, entry: MemoryEntry)
        -> Pin<Box<dyn Future<Output = Result<(), LoopError>> + Send + '_>>
    {
        Box::pin(async move {
            self.entries.write().unwrap().push(entry);
            Ok(())
        })
    }
    fn retrieve(&self, query: &str, limit: usize)
        -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>, LoopError>> + Send + '_>>
    {
        let query = query.to_string();
        Box::pin(async move {
            let entries = self.entries.read().unwrap();
            Ok(entries.iter()
                .filter(|e| e.memory.contains(&query))
                .take(limit)
                .cloned()
                .collect())
        })
    }
    fn consolidate(&self)
        -> Pin<Box<dyn Future<Output = Result<ConsolidationStats, LoopError>> + Send + '_>>
    {
        Box::pin(async move { Ok(ConsolidationStats::default()) })
    }
    fn len(&self) -> usize {
        self.entries.read().unwrap().len()
    }
}

Re-exports§

pub use builtin::InMemoryStore;
pub use entry::ConsolidationStats;
pub use entry::MemoryCategory;
pub use entry::MemoryEntry;

Modules§

builtin
Reference memory implementation — in-memory LoopMemory backend.
entry
Memory entry types — MemoryEntry, MemoryCategory, ConsolidationStats.

Traits§

LoopMemory
A memory system for agent loops.