Skip to main content

PersistenceBackend

Trait PersistenceBackend 

Source
pub trait PersistenceBackend: Send + Sync {
    // Required methods
    fn save<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        value: &'life2 [u8],
    ) -> Pin<Box<dyn Future<Output = Result<(), AgentRuntimeError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn load<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, AgentRuntimeError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn delete<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), AgentRuntimeError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn batch_save<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        items: &'life1 [(&'life2 str, &'life3 [u8])],
    ) -> Pin<Box<dyn Future<Output = Result<(), AgentRuntimeError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
    fn batch_load<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        keys: &'life1 [&'life2 str],
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Option<Vec<u8>>>, AgentRuntimeError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

Pluggable storage backend for agent state (memory, graph, session checkpoints).

Implement this trait to persist agent state to any storage system (disk, Redis, S3, databases, etc.).

Required Methods§

Source

fn save<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key: &'life1 str, value: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<(), AgentRuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Persist raw bytes under the given key.

Source

fn load<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, AgentRuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Load raw bytes for the given key.

Returns None if no data has been stored under this key.

Source

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

Delete the entry for the given key. No-op if the key does not exist.

Provided Methods§

Source

fn batch_save<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, items: &'life1 [(&'life2 str, &'life3 [u8])], ) -> Pin<Box<dyn Future<Output = Result<(), AgentRuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Save multiple key-value pairs concurrently.

The default implementation issues all save calls concurrently using [futures::future::try_join_all] so backends that incur per-call I/O latency benefit without any additional code. Backends with their own native batch API should override this method.

Source

fn batch_load<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, keys: &'life1 [&'life2 str], ) -> Pin<Box<dyn Future<Output = Result<Vec<Option<Vec<u8>>>, AgentRuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Load multiple keys concurrently. Returns a vec of Option<Vec<u8>> in the same order.

The default implementation issues all load calls concurrently using [futures::future::try_join_all]. Backends with a native multi-get API should override this method.

Implementors§