Skip to main content

StorageBackend

Trait StorageBackend 

Source
pub trait StorageBackend:
    Send
    + Sync
    + 'static {
    // Required methods
    fn load_transcript<'life0, 'life1, 'async_trait>(
        &'life0 self,
        session_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Message>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn save_transcript<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        session_id: &'life1 str,
        messages: &'life2 [Message],
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn load_memory<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn save_memory<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        value: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

Persistent storage for session transcript and memory entries.

§Semantics

  • load_transcript returns an empty Vec (not an error) when the session does not yet exist.
  • load_memory returns None (not an error) when the key does not exist.
  • Implementations must be safe to call concurrently from multiple async tasks (Send + Sync + 'static).

The trait uses #[async_trait] so it is dyn-compatible and can be stored as Arc<dyn StorageBackend> without generics spreading to callers.

Required Methods§

Source

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

Load the full transcript for a session.

Returns Ok(vec![]) if the session has no persisted transcript yet.

Source

fn save_transcript<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, session_id: &'life1 str, messages: &'life2 [Message], ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Persist the full transcript for a session.

This is a full overwrite — the caller is responsible for appending new messages before calling this.

Source

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

Load a named memory entry (e.g. "user.md", "project.md").

Returns Ok(None) if the key has never been written.

Source

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

Store a named memory entry.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§