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
[]
= "0.4"
Or use the meta-crate:
[]
= { = "0.4", = ["sessions"] }
Quick Start
use ;
use json;
use HashMap;
let service = new;
let mut initial_state = new;
initial_state.insert;
let session = service.create.await?;
let name = session.state.get;
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 |
# SQLite
= { = "0.4", = ["sqlite"] }
# PostgreSQL
= { = "0.4", = ["postgres"] }
# Redis
= { = "0.4", = ["redis"] }
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 SqliteSessionService;
let service = new.await?;
// Run all pending migrations
service.migrate.await?;
// Check current schema version
let version = service.schema_version.await?;
println!;
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 has been renamed to SqliteSessionService to accurately reflect that it is a SQLite-only backend. A deprecated type alias is provided for backward compatibility:
// Old (still compiles with a deprecation warning)
use DatabaseSessionService;
// New
use 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.