27 releases (1 stable)
Uses new Rust 2024
| 1.0.0 | Jun 7, 2026 |
|---|---|
| 0.9.1 | May 24, 2026 |
| 0.8.4 | May 18, 2026 |
| 0.5.0 | Mar 29, 2026 |
| 0.1.1 | Nov 30, 2025 |
#2034 in Asynchronous
8,122 downloads per month
Used in 21 crates
(13 directly)
660KB
12K
SLoC
adk-session
Session management and state persistence for Rust Agent Development Kit (ADK-Rust) agents.
Overview
adk-session provides session and state management for the Rust Agent Development Kit (ADK-Rust):
- InMemorySessionService - Simple in-memory session storage
- SqliteSessionService - SQLite-backed persistence (
sqlitefeature) - PostgresSessionService - PostgreSQL-backed persistence (
postgresfeature) - RedisSessionService - Redis-backed persistence (
redisfeature) - MongoSessionService - MongoDB-backed persistence (
mongodbfeature) - Neo4jSessionService - Neo4j-backed persistence (
neo4jfeature) - FirestoreSessionService - Firestore-backed persistence (
firestorefeature) - VertexAiSessionService - Vertex AI Session API backend (
vertex-sessionfeature) - Schema Migrations - Versioned, forward-only migrations for all database backends
Installation
[dependencies]
adk-session = "1.0.0"
Or use the meta-crate:
[dependencies]
adk-rust = { version = "1.0.0", features = ["sessions"] }
Quick Start
use adk_session::{InMemorySessionService, SessionService, CreateRequest, KEY_PREFIX_USER};
use serde_json::json;
use std::collections::HashMap;
let service = InMemorySessionService::new();
let mut initial_state = HashMap::new();
initial_state.insert(format!("{}name", KEY_PREFIX_USER), json!("Alice"));
let session = service.create(CreateRequest {
app_name: "my_app".to_string(),
user_id: "user_123".to_string(),
session_id: None,
state: initial_state,
}).await?;
let name = session.state().get("user:name");
State Prefixes
| Prefix | Purpose | Persistence |
|---|---|---|
user: |
User preferences | Across sessions |
app: |
Application state | Application-wide |
temp: |
Temporary data | Current turn only |
Feature Flags
| Feature | Backend | Description |
|---|---|---|
sqlite |
SQLite | Single-node persistence via sqlx |
database |
SQLite | Alias for sqlite (backward compat) |
postgres |
PostgreSQL | Production-grade relational persistence |
redis |
Redis | Low-latency in-memory persistence via fred |
mongodb |
MongoDB | Document-oriented persistence |
neo4j |
Neo4j | Graph database persistence |
firestore |
Firestore | Google Cloud Firestore persistence |
vertex-session |
Vertex AI | Vertex AI Session API backend |
encrypted-session |
AES-256-GCM | Transparent encryption at rest with key rotation |
# SQLite
adk-session = { version = "1.0.0", features = ["sqlite"] }
# PostgreSQL
adk-session = { version = "1.0.0", features = ["postgres"] }
# Redis
adk-session = { version = "1.0.0", features = ["redis"] }
# Encrypted sessions
adk-session = { version = "1.0.0", features = ["encrypted-session"] }
Encrypted Sessions
Wrap any SessionService with EncryptedSession to encrypt session state at rest using AES-256-GCM:
use adk_session::{EncryptedSession, EncryptionKey, InMemorySessionService};
let key = EncryptionKey::generate();
let inner = InMemorySessionService::new();
let service = EncryptedSession::new(inner, key, vec![]);
// Use like any SessionService — encryption is transparent
Key rotation is supported by passing previous keys:
let new_key = EncryptionKey::generate();
let old_key = EncryptionKey::from_env("OLD_KEY")?;
let service = EncryptedSession::new(inner, new_key, vec![old_key]);
Schema Migrations
All database backends (SQLite, PostgreSQL, MongoDB, Neo4j) include a versioned migration system. Migrations are forward-only, idempotent, and tracked in a _schema_migrations registry table.
use adk_session::SqliteSessionService;
let service = SqliteSessionService::new("sqlite:sessions.db").await?;
// Run all pending migrations
service.migrate().await?;
// Check current schema version
let version = service.schema_version().await?;
println!("Schema version: {version}");
Each backend detects pre-existing tables (baseline detection) and registers them as already applied, so migrate() is safe to call on both fresh and existing databases.
Rename: DatabaseSessionService → SqliteSessionService
As of v0.4.0, DatabaseSessionService was renamed to SqliteSessionService to accurately reflect that it is a SQLite-only backend. The deprecated type alias was removed in v0.7.0. Update your imports:
use adk_session::SqliteSessionService;
Related Crates
- adk-rust - Meta-crate with all components
- adk-core - Core
Sessiontrait - adk-runner - Uses sessions for execution
License
Apache-2.0
Part of ADK-Rust
This crate is part of the ADK-Rust framework for building AI agents in Rust.
Dependencies
~8–55MB
~861K SLoC