Skip to main content

StateStore

Trait StateStore 

Source
pub trait StateStore:
    Send
    + Sync
    + 'static {
    // Required methods
    fn append(
        &self,
        entry: PortValue,
    ) -> Pin<Box<dyn Future<Output = Result<PortId, SdkError>> + Send + '_>>;
    fn load(
        &self,
        id: &PortId,
    ) -> Pin<Box<dyn Future<Output = Result<Option<PortValue>, SdkError>> + Send + '_>>;
    fn list(
        &self,
        prefix: &str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<PortId>, SdkError>> + Send + '_>>;
    fn delete(
        &self,
        id: &PortId,
    ) -> Pin<Box<dyn Future<Output = Result<(), SdkError>> + Send + '_>>;

    // Provided method
    fn load_all(
        &self,
        _prefix: &str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<(PortId, PortValue)>, SdkError>> + Send + '_>> { ... }
}
Expand description

Append-only / key-value durable state.

Each entry is a PortValue (typically a JSON object). Implementations decide the storage backend (file, SQLite, Redis, S3, in-memory…).

§Use cases

  • Persist session history (append)
  • Persist agent state snapshots
  • Persist skill registries
  • Persist audit chains

§Default

If not registered with the SDK, NoopStateStore is used. Calling append returns an error; calling load returns Ok(None).

Required Methods§

Source

fn append( &self, entry: PortValue, ) -> Pin<Box<dyn Future<Output = Result<PortId, SdkError>> + Send + '_>>

Persist an entry. Returns the assigned identifier.

Source

fn load( &self, id: &PortId, ) -> Pin<Box<dyn Future<Output = Result<Option<PortValue>, SdkError>> + Send + '_>>

Load an entry by id.

Source

fn list( &self, prefix: &str, ) -> Pin<Box<dyn Future<Output = Result<Vec<PortId>, SdkError>> + Send + '_>>

List all entry ids matching the given prefix (e.g. "session:").

Source

fn delete( &self, id: &PortId, ) -> Pin<Box<dyn Future<Output = Result<(), SdkError>> + Send + '_>>

Delete an entry by id.

Provided Methods§

Source

fn load_all( &self, _prefix: &str, ) -> Pin<Box<dyn Future<Output = Result<Vec<(PortId, PortValue)>, SdkError>> + Send + '_>>

Optional bulk-load of entries for a prefix. Default: None (impl may not support efficient bulk reads).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§