16 unstable releases (3 breaking)
Uses new Rust 2024
| new 0.4.0 | Mar 16, 2026 |
|---|---|
| 0.3.2 | Feb 21, 2026 |
| 0.2.1 | Jan 22, 2026 |
| 0.1.9 | Jan 3, 2026 |
| 0.1.1 | Nov 30, 2025 |
#1648 in Asynchronous
523 downloads per month
Used in 8 crates
(7 directly)
410KB
8K
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 = "0.4"
Or use the meta-crate:
[dependencies]
adk-rust = { version = "0.4", 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 |
# SQLite
adk-session = { version = "0.4", features = ["sqlite"] }
# PostgreSQL
adk-session = { version = "0.4", features = ["postgres"] }
# Redis
adk-session = { version = "0.4", features = ["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 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 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 adk_session::DatabaseSessionService;
// New
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
~7–54MB
~826K SLoC