Skip to main content

Crate adk_session

Crate adk_session 

Source
Expand description

§adk-session

Session management and state persistence for ADK agents.

§Overview

This crate provides session and state management:

  • InMemorySessionService - Simple in-memory session storage
  • SqliteSessionService, PostgresSessionService, RedisSessionService, MongoSessionService, Neo4jSessionService, FirestoreSessionService, and VertexAiSessionService - database backends, each behind its feature
  • EncryptedSession - AES-256-GCM encryption over any backend (encrypted-session feature)
  • Durable stores for every backend: spend ledgers, action ledgers, approval stores, audit log stores, the lease, run, schedule, and governance state stores of the durable runtime, and the subject registries and consent stores of adk_core::subject
  • SessionSubjectData - A subject’s sessions, exported and erased through any backend
  • archive - Archive, unarchive and export sessions on every backend
  • Session - Conversation session with state and events
  • State - Key-value state with typed prefixes
  • SessionService - Trait for custom session backends

§Quick Start

use adk_session::{CreateRequest, InMemorySessionService, SessionService};

let service = InMemorySessionService::new();

// Create the session before a Runner runs against it.
let session = service
    .create(CreateRequest {
        app_name: "my_app".into(),
        user_id: "user".into(),
        session_id: Some("session".into()),
        state: Default::default(),
    })
    .await?;
assert_eq!(session.id(), "session");

§State Prefixes

ADK uses prefixes to organize state:

PrefixConstantPurpose
user:KEY_PREFIX_USERShared by every session of the user
app:KEY_PREFIX_APPShared by every session of the app
temp:KEY_PREFIX_TEMPNot persisted

§Feature flags

No feature is on by default; InMemorySessionService needs none.

FeatureEnables
sqliteSqliteSessionService
databaseAlias for sqlite
postgresPostgresSessionService, with TLS
redisRedisSessionService on a standalone server or Redis Cluster
mongodbMongoSessionService
neo4jNeo4jSessionService
firestoreFirestoreSessionService
vertex-sessionVertexAiSessionService over the Vertex AI Session API
encrypted-sessionEncryptedSession: AES-256-GCM encryption at rest over any backend, with key rotation

Re-exports§

pub use archive::ARCHIVE_AUTHOR;
pub use archive::ARCHIVE_KEY;
pub use archive::ArchiveMark;
pub use archive::SESSION_BUNDLE_FORMAT;
pub use archive::SessionBundle;
pub use archive::ensure_writable;
pub use consent_gate::ConsentGatedSessionService;
pub use event::Events;
pub use history::FORK_ORIGIN_KEY;
pub use history::ForkOrigin;
pub use history::ForkRequest;
pub use history::HistoryChange;
pub use history::HistoryEdit;
pub use history::HistoryOperation;
pub use history::HistoryOutcome;
pub use history::HistoryRewrite;
pub use history::ImportSessionRequest;
pub use history::RewriteHistoryRequest;
pub use history::RewrittenHistory;
pub use history::SessionHistory;
pub use inmemory::InMemorySessionService;
pub use service::AppendEventRequest;
pub use service::CreateRequest;
pub use service::DeleteRequest;
pub use service::GetRequest;
pub use service::ListRequest;
pub use service::SessionService;
pub use session::KEY_PREFIX_APP;
pub use session::KEY_PREFIX_TEMP;
pub use session::KEY_PREFIX_USER;
pub use session::Session;
pub use state::ReadonlyState;
pub use state::State;
pub use state_utils::extract_state_deltas;
pub use state_utils::merge_states;
pub use subject::SessionSubjectData;
pub use subject_firestore::FirestoreConsentStore;
pub use subject_firestore::FirestoreSubjectRegistry;
pub use subject_mongodb::MongoConsentStore;
pub use subject_mongodb::MongoSubjectRegistry;
pub use subject_neo4j::Neo4jConsentStore;
pub use subject_neo4j::Neo4jSubjectRegistry;
pub use subject_redis::RedisConsentStore;
pub use subject_redis::RedisSubjectRegistry;
pub use subject_sql::PostgresConsentStore;
pub use subject_sql::PostgresSubjectRegistry;
pub use subject_sql::SqliteConsentStore;
pub use subject_sql::SqliteSubjectRegistry;
pub use approval::PostgresApprovalStore;
pub use approval::SqliteApprovalStore;
pub use audit_log::PostgresAuditLogStore;
pub use audit_log::SqliteAuditLogStore;
pub use firestore_audit_log::FirestoreAuditLogStore;
pub use firestore_runtime::FirestoreGovernanceStateStore;
pub use firestore_runtime::FirestoreLeaseStore;
pub use firestore_runtime::FirestoreRunStore;
pub use firestore_runtime::FirestoreScheduleStore;
pub use firestore_stores::FirestoreActionLedger;
pub use firestore_stores::FirestoreApprovalStore;
pub use firestore_stores::FirestoreSpendLedger;
pub use governance_state::PostgresGovernanceStateStore;
pub use governance_state::SqliteGovernanceStateStore;
pub use lease::PostgresLeaseStore;
pub use lease::SqliteLeaseStore;
pub use mongodb_audit_log::MongoAuditLogStore;
pub use mongodb_runtime::MongoGovernanceStateStore;
pub use mongodb_runtime::MongoLeaseStore;
pub use mongodb_runtime::MongoRunStore;
pub use mongodb_runtime::MongoScheduleStore;
pub use mongodb_stores::MongoActionLedger;
pub use mongodb_stores::MongoApprovalStore;
pub use mongodb_stores::MongoSpendLedger;
pub use neo4j_audit_log::Neo4jAuditLogStore;
pub use neo4j_runtime::Neo4jGovernanceStateStore;
pub use neo4j_runtime::Neo4jLeaseStore;
pub use neo4j_runtime::Neo4jRunStore;
pub use neo4j_runtime::Neo4jScheduleStore;
pub use neo4j_stores::Neo4jActionLedger;
pub use neo4j_stores::Neo4jApprovalStore;
pub use neo4j_stores::Neo4jSpendLedger;
pub use postgres_action_ledger::PostgresActionLedger;
pub use redis_audit_log::RedisAuditLogStore;
pub use redis_runtime::RedisGovernanceStateStore;
pub use redis_runtime::RedisLeaseStore;
pub use redis_runtime::RedisRunStore;
pub use redis_runtime::RedisScheduleStore;
pub use redis_stores::RedisActionLedger;
pub use redis_stores::RedisApprovalStore;
pub use redis_stores::RedisSpendLedger;
pub use run_store::PostgresRunStore;
pub use run_store::SqliteRunStore;
pub use schedule::PostgresScheduleStore;
pub use schedule::SqliteScheduleStore;
pub use spend::PostgresSpendLedger;
pub use spend::SqliteSpendLedger;
pub use sqlite::SqliteSessionService;
pub use sqlite_action_ledger::SqliteActionLedger;
pub use encrypted::EncryptedSession;
pub use encrypted_approval::EncryptedApprovalStore;
pub use encryption_key::EncryptionKey;
pub use firestore::FirestoreSessionConfig;
pub use firestore::FirestoreSessionService;
pub use firestore::app_state_path as firestore_app_state_path;
pub use firestore::event_path as firestore_event_path;
pub use firestore::session_path as firestore_session_path;
pub use firestore::user_state_path as firestore_user_state_path;
pub use mongodb::MongoSessionService;
pub use neo4j::Neo4jSessionService;
pub use postgres::PostgresSessionService;
pub use redis::RedisSessionConfig;
pub use redis::RedisSessionService;
pub use redis::app_state_key;
pub use redis::events_key;
pub use redis::index_key;
pub use redis::session_key;
pub use redis::updated_index_key;
pub use redis::user_state_key;
pub use vertex::VertexAiSessionConfig;
pub use vertex::VertexAiSessionService;

Modules§

approval
SQL-backed approval stores for calls held for confirmation. SQL-backed ApprovalStore implementations.
archive
Session archive: put a finished conversation away without deleting it.
audit_log
SQL-backed audit log stores for signed, Merkle-hashed audit logs. SQL-backed AuditLogStore implementations.
consent_gate
A session service that writes nothing lasting for a subject without its consent. A session service that writes nothing lasting for a subject without its consent.
encrypted
AES-256-GCM encrypted session wrapper with key rotation. Transparent encryption wrapper for any SessionService implementation.
encrypted_approval
Approval arguments and decisions sealed at rest (spec 3.1 §7.12, §10 S5). EncryptedApprovalStore: an ApprovalStore whose payloads reach the inner store sealed in the envelope (spec 3.1 §7.12, §9.2 I57, §10 S5).
encryption_key
Encryption key management for encrypted sessions. AES-256-GCM encryption key management.
envelope
The adk-enc:v1: envelope other stores wrap their payloads with (spec 3.1 §10 S5). The adk-enc:v1: envelope: AES-256-GCM with associated data, as EncryptedSession stores it (spec 3.1 §7.12, §10 S5).
event
Event types and the Events trait for accessing session event history.
firestore
Google Cloud Firestore session backend. Firestore session service backend.
firestore_audit_log
Firestore-backed audit log store for signed, Merkle-hashed audit logs. Firestore-backed AuditLogStore.
firestore_runtime
Firestore-backed lease, run, schedule, and governance state stores. Firestore-backed LeaseStore, DurableRunStore, ScheduleStore, and GovernanceStateStore.
firestore_stores
Firestore-backed spend ledger, action ledger, and approval store. Firestore-backed SpendLedger, ActionLedger, and ApprovalStore.
governance_state
SQL-backed governance state stores for a kill switch shared by every replica. SQL-backed GovernanceStateStore implementations.
history
Forking a session, rewinding it, and editing its history.
inmemory
In-memory session backend for testing and lightweight use cases.
lease
SQL-backed lease stores with fencing epochs. SQL-backed LeaseStore implementations.
migration
Schema migration utilities for database-backed session stores. Lightweight, embedded migration runner for SQL-backed session services.
mongodb
MongoDB session backend. MongoDB session service backend.
mongodb_audit_log
MongoDB-backed audit log store for signed, Merkle-hashed audit logs. MongoDB-backed AuditLogStore.
mongodb_runtime
MongoDB-backed lease, run, schedule, and governance state stores. MongoDB-backed LeaseStore, DurableRunStore, ScheduleStore, and GovernanceStateStore.
mongodb_stores
MongoDB-backed spend ledger, action ledger, and approval store. MongoDB-backed SpendLedger, ActionLedger, and ApprovalStore.
neo4j
Neo4j graph database session backend. Neo4j session service backend.
neo4j_audit_log
Neo4j-backed audit log store for signed, Merkle-hashed audit logs. Neo4j-backed AuditLogStore.
neo4j_runtime
Neo4j-backed lease, run, schedule, and governance state stores. Neo4j-backed LeaseStore, DurableRunStore, ScheduleStore, and GovernanceStateStore.
neo4j_stores
Neo4j-backed spend ledger, action ledger, and approval store. Neo4j-backed SpendLedger, ActionLedger, and ApprovalStore.
postgres
PostgreSQL session backend.
postgres_action_ledger
PostgreSQL-backed action ledger for non-idempotent tool calls.
redis
Redis session backend with TTL support. Redis-backed session service.
redis_audit_log
Redis-backed audit log store for signed, Merkle-hashed audit logs. Redis-backed AuditLogStore.
redis_runtime
Redis-backed lease, run, schedule, and governance state stores. Redis-backed LeaseStore, DurableRunStore, ScheduleStore, and GovernanceStateStore.
redis_stores
Redis-backed spend ledger, action ledger, and approval store. Redis-backed SpendLedger, ActionLedger, and ApprovalStore.
run_store
SQL-backed durable run queues. SQL-backed DurableRunStore implementations.
schedule
SQL-backed schedule stores. SQL-backed ScheduleStore implementations.
service
Session service trait and request/response types.
session
The Session trait and state key prefix constants.
spend
SQL-backed spend ledgers shared by model calls and payments. SQL-backed SpendLedger implementations.
sqlite
SQLite session backend.
sqlite_action_ledger
SQLite-backed action ledger for non-idempotent tool calls.
state
State access traits (State and ReadonlyState).
state_utils
Shared utilities for extracting and merging state deltas across backends. Shared state utility functions for session backends.
subject
The session family’s SubjectDataStore adapter: a subject’s sessions, events, and user: state, exported and erased through any SessionService.
subject_firestore
Firestore-backed subject registry and consent store. Firestore-backed SubjectRegistry and ConsentStore.
subject_mongodb
MongoDB-backed subject registry and consent store. MongoDB-backed SubjectRegistry and ConsentStore.
subject_neo4j
Neo4j-backed subject registry and consent store. Neo4j-backed SubjectRegistry and ConsentStore.
subject_redis
Redis-backed subject registry and consent store. Redis-backed SubjectRegistry and ConsentStore.
subject_sql
SQL-backed subject registries and consent stores. SQL-backed SubjectRegistry and ConsentStore implementations.
vertex
Vertex AI Session API backend.

Structs§

Event
Event represents a single interaction in a conversation. This struct embeds LlmResponse to match ADK-Go’s design pattern.
EventActions
Actions to apply as side effects of an event.