Skip to main content

Module store

Module store 

Source
Expand description

Session persistence layer

Provides pluggable session storage via the SessionStore trait.

§Default Implementation

FileSessionStore stores each session as a JSON file:

  • Session metadata (id, name, timestamps)
  • Configuration (system prompt, policies)
  • Conversation history (messages)
  • Context usage statistics

§Custom Backends

Implement SessionStore trait for custom backends (Redis, PostgreSQL, etc.):

use a3s_code::store::{
    SessionData, SessionSnapshotV1, SessionStore, SessionStoreCapabilities,
};

struct RedisStore { /* ... */ }

#[async_trait::async_trait]
impl SessionStore for RedisStore {
    // Required by AgentSession::save: commit the entire value in one
    // backend transaction / atomic replacement.
    async fn save_snapshot(&self, snapshot: &SessionSnapshotV1) -> Result<()> { /* ... */ }
    async fn load_snapshot(&self, id: &str) -> Result<Option<SessionSnapshotV1>> { /* ... */ }
    fn capabilities(&self) -> SessionStoreCapabilities {
        SessionStoreCapabilities { atomic_session_snapshots: true }
    }

    // Legacy fragment APIs remain available for migration compatibility.
    async fn save(&self, session: &SessionData) -> Result<()> { /* ... */ }
    async fn load(&self, id: &str) -> Result<Option<SessionData>> { /* ... */ }
    async fn delete(&self, id: &str) -> Result<()> { /* ... */ }
    async fn list(&self) -> Result<Vec<String>> { /* ... */ }
    async fn exists(&self, id: &str) -> Result<bool> { /* ... */ }
}

Structs§

ContextUsage
Context usage statistics persisted with saved sessions.
FileSessionStore
File-based session store.
LlmConfigData
Serializable LLM configuration
MemorySessionStore
In-memory session store for testing
SessionConfig
Serializable session configuration.
SessionData
Serializable session data for persistence
SessionSnapshotV1
A complete, versioned persistence generation for one session.
SessionStoreCapabilities
Persistence guarantees advertised by a session store implementation.

Enums§

SessionState
Session state persisted with saved sessions.

Constants§

DEFAULT_AUTO_COMPACT_THRESHOLD
Default auto-compact threshold (80% of context window).
SESSION_SNAPSHOT_SCHEMA_VERSION
Schema version written by SessionSnapshotV1.

Traits§

SessionStore
Session storage trait