Skip to main content

adk_session/
lib.rs

1//! # adk-session
2#![allow(clippy::result_large_err)]
3#![deny(missing_docs)]
4//!
5//! Session management and state persistence for ADK agents.
6//!
7//! ## Overview
8//!
9//! This crate provides session and state management:
10//!
11//! - [`InMemorySessionService`] - Simple in-memory session storage
12//! - `VertexAiSessionService` - Vertex AI Session API backend (`vertex-session` feature)
13//! - [`Session`] - Conversation session with state and events
14//! - [`State`] - Key-value state with typed prefixes
15//! - [`SessionService`] - Trait for custom session backends
16//!
17//! ## Quick Start
18//!
19//! ```rust,no_run
20//! use adk_session::InMemorySessionService;
21//!
22//! let service = InMemorySessionService::new();
23//!
24//! // Sessions are created and managed by the Runner
25//! // State is accessed via the session
26//! ```
27//!
28//! ## State Prefixes
29//!
30//! ADK uses prefixes to organize state:
31//!
32//! | Prefix | Constant | Purpose |
33//! |--------|----------|---------|
34//! | `user:` | [`KEY_PREFIX_USER`] | User preferences |
35//! | `app:` | [`KEY_PREFIX_APP`] | Application state |
36//! | `temp:` | [`KEY_PREFIX_TEMP`] | Temporary data |
37
38/// Event types and the [`Events`] trait for accessing session event history.
39pub mod event;
40/// In-memory session backend for testing and lightweight use cases.
41pub mod inmemory;
42/// Schema migration utilities for database-backed session stores.
43pub mod migration;
44/// Session service trait and request/response types.
45pub mod service;
46/// The [`Session`] trait and state key prefix constants.
47pub mod session;
48/// State access traits ([`State`] and [`ReadonlyState`]).
49pub mod state;
50/// Shared utilities for extracting and merging state deltas across backends.
51pub mod state_utils;
52
53#[cfg(feature = "encrypted-session")]
54/// AES-256-GCM encrypted session wrapper with key rotation.
55pub mod encrypted;
56#[cfg(feature = "encrypted-session")]
57/// Encryption key management for encrypted sessions.
58pub mod encryption_key;
59#[cfg(feature = "firestore")]
60/// Google Cloud Firestore session backend.
61pub mod firestore;
62#[cfg(feature = "mongodb")]
63/// MongoDB session backend.
64pub mod mongodb;
65#[cfg(feature = "neo4j")]
66/// Neo4j graph database session backend.
67pub mod neo4j;
68#[cfg(feature = "postgres")]
69/// PostgreSQL session backend.
70pub mod postgres;
71#[cfg(feature = "redis")]
72/// Redis session backend with TTL support.
73pub mod redis;
74#[cfg(feature = "sqlite")]
75/// SQLite session backend.
76pub mod sqlite;
77#[cfg(feature = "vertex-session")]
78/// Vertex AI Session API backend.
79pub mod vertex;
80
81pub use event::{Event, EventActions, Events};
82pub use inmemory::InMemorySessionService;
83pub use service::{
84    AppendEventRequest, CreateRequest, DeleteRequest, GetRequest, ListRequest, SessionService,
85};
86pub use session::{KEY_PREFIX_APP, KEY_PREFIX_TEMP, KEY_PREFIX_USER, Session};
87pub use state::{ReadonlyState, State};
88pub use state_utils::{extract_state_deltas, merge_states};
89
90#[cfg(feature = "sqlite")]
91pub use sqlite::SqliteSessionService;
92
93#[cfg(feature = "encrypted-session")]
94pub use encrypted::EncryptedSession;
95#[cfg(feature = "encrypted-session")]
96pub use encryption_key::EncryptionKey;
97#[cfg(feature = "firestore")]
98pub use firestore::{
99    FirestoreSessionConfig, FirestoreSessionService, app_state_path as firestore_app_state_path,
100    event_path as firestore_event_path, session_path as firestore_session_path,
101    user_state_path as firestore_user_state_path,
102};
103#[cfg(feature = "mongodb")]
104pub use mongodb::MongoSessionService;
105#[cfg(feature = "neo4j")]
106pub use neo4j::Neo4jSessionService;
107#[cfg(feature = "postgres")]
108pub use postgres::PostgresSessionService;
109#[cfg(feature = "redis")]
110pub use redis::{
111    RedisSessionConfig, RedisSessionService, app_state_key, events_key, index_key, session_key,
112    user_state_key,
113};
114#[cfg(feature = "vertex-session")]
115pub use vertex::{VertexAiSessionConfig, VertexAiSessionService};