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 storageSqliteSessionService,PostgresSessionService,RedisSessionService,MongoSessionService,Neo4jSessionService,FirestoreSessionService, andVertexAiSessionService- database backends, each behind its featureEncryptedSession- AES-256-GCM encryption over any backend (encrypted-sessionfeature)- 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 backendarchive- Archive, unarchive and export sessions on every backendSession- Conversation session with state and eventsState- Key-value state with typed prefixesSessionService- 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:
| Prefix | Constant | Purpose |
|---|---|---|
user: | KEY_PREFIX_USER | Shared by every session of the user |
app: | KEY_PREFIX_APP | Shared by every session of the app |
temp: | KEY_PREFIX_TEMP | Not persisted |
§Feature flags
No feature is on by default; InMemorySessionService needs none.
| Feature | Enables |
|---|---|
sqlite | SqliteSessionService |
database | Alias for sqlite |
postgres | PostgresSessionService, with TLS |
redis | RedisSessionService on a standalone server or Redis Cluster |
mongodb | MongoSessionService |
neo4j | Neo4jSessionService |
firestore | FirestoreSessionService |
vertex-session | VertexAiSessionService over the Vertex AI Session API |
encrypted-session | EncryptedSession: 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
ApprovalStoreimplementations. - 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
AuditLogStoreimplementations. - 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
SessionServiceimplementation. - encrypted_
approval - Approval arguments and decisions sealed at rest (spec 3.1 §7.12, §10 S5).
EncryptedApprovalStore: anApprovalStorewhose payloads reach the inner store sealed in theenvelope(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). Theadk-enc:v1:envelope: AES-256-GCM with associated data, asEncryptedSessionstores it (spec 3.1 §7.12, §10 S5). - event
- Event types and the
Eventstrait 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, andGovernanceStateStore. - firestore_
stores - Firestore-backed spend ledger, action ledger, and approval store.
Firestore-backed
SpendLedger,ActionLedger, andApprovalStore. - governance_
state - SQL-backed governance state stores for a kill switch shared by every replica.
SQL-backed
GovernanceStateStoreimplementations. - 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
LeaseStoreimplementations. - 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, andGovernanceStateStore. - mongodb_
stores - MongoDB-backed spend ledger, action ledger, and approval store.
MongoDB-backed
SpendLedger,ActionLedger, andApprovalStore. - 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, andGovernanceStateStore. - neo4j_
stores - Neo4j-backed spend ledger, action ledger, and approval store.
Neo4j-backed
SpendLedger,ActionLedger, andApprovalStore. - 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, andGovernanceStateStore. - redis_
stores - Redis-backed spend ledger, action ledger, and approval store.
Redis-backed
SpendLedger,ActionLedger, andApprovalStore. - run_
store - SQL-backed durable run queues.
SQL-backed
DurableRunStoreimplementations. - schedule
- SQL-backed schedule stores.
SQL-backed
ScheduleStoreimplementations. - service
- Session service trait and request/response types.
- session
- The
Sessiontrait and state key prefix constants. - spend
- SQL-backed spend ledgers shared by model calls and payments.
SQL-backed
SpendLedgerimplementations. - sqlite
- SQLite session backend.
- sqlite_
action_ ledger - SQLite-backed action ledger for non-idempotent tool calls.
- state
- State access traits (
StateandReadonlyState). - state_
utils - Shared utilities for extracting and merging state deltas across backends. Shared state utility functions for session backends.
- subject
- The session family’s
SubjectDataStoreadapter: a subject’s sessions, events, anduser:state, exported and erased through anySessionService. - subject_
firestore - Firestore-backed subject registry and consent store.
Firestore-backed
SubjectRegistryandConsentStore. - subject_
mongodb - MongoDB-backed subject registry and consent store.
MongoDB-backed
SubjectRegistryandConsentStore. - subject_
neo4j - Neo4j-backed subject registry and consent store.
Neo4j-backed
SubjectRegistryandConsentStore. - subject_
redis - Redis-backed subject registry and consent store.
Redis-backed
SubjectRegistryandConsentStore. - subject_
sql - SQL-backed subject registries and consent stores.
SQL-backed
SubjectRegistryandConsentStoreimplementations. - 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.
- Event
Actions - Actions to apply as side effects of an event.