Skip to main content

adk_session/
lib.rs

1//! # adk-session
2#![allow(clippy::result_large_err)]
3//!
4//! Session management and state persistence for ADK agents.
5//!
6//! ## Overview
7//!
8//! This crate provides session and state management:
9//!
10//! - [`InMemorySessionService`] - Simple in-memory session storage
11//! - `VertexAiSessionService` - Vertex AI Session API backend (`vertex-session` feature)
12//! - [`Session`] - Conversation session with state and events
13//! - [`State`] - Key-value state with typed prefixes
14//! - [`SessionService`] - Trait for custom session backends
15//!
16//! ## Quick Start
17//!
18//! ```rust,no_run
19//! use adk_session::InMemorySessionService;
20//!
21//! let service = InMemorySessionService::new();
22//!
23//! // Sessions are created and managed by the Runner
24//! // State is accessed via the session
25//! ```
26//!
27//! ## State Prefixes
28//!
29//! ADK uses prefixes to organize state:
30//!
31//! | Prefix | Constant | Purpose |
32//! |--------|----------|---------|
33//! | `user:` | [`KEY_PREFIX_USER`] | User preferences |
34//! | `app:` | [`KEY_PREFIX_APP`] | Application state |
35//! | `temp:` | [`KEY_PREFIX_TEMP`] | Temporary data |
36
37pub mod event;
38pub mod inmemory;
39pub mod migration;
40pub mod service;
41pub mod session;
42pub mod state;
43pub mod state_utils;
44
45#[cfg(feature = "encrypted-session")]
46pub mod encrypted;
47#[cfg(feature = "encrypted-session")]
48pub mod encryption_key;
49#[cfg(feature = "firestore")]
50pub mod firestore;
51#[cfg(feature = "mongodb")]
52pub mod mongodb;
53#[cfg(feature = "neo4j")]
54pub mod neo4j;
55#[cfg(feature = "postgres")]
56pub mod postgres;
57#[cfg(feature = "redis")]
58pub mod redis;
59#[cfg(feature = "sqlite")]
60pub mod sqlite;
61#[cfg(feature = "vertex-session")]
62pub mod vertex;
63
64pub use event::{Event, EventActions, Events};
65pub use inmemory::InMemorySessionService;
66pub use service::{
67    AppendEventRequest, CreateRequest, DeleteRequest, GetRequest, ListRequest, SessionService,
68};
69pub use session::{KEY_PREFIX_APP, KEY_PREFIX_TEMP, KEY_PREFIX_USER, Session};
70pub use state::{ReadonlyState, State};
71pub use state_utils::{extract_state_deltas, merge_states};
72
73#[cfg(feature = "sqlite")]
74pub use sqlite::SqliteSessionService;
75
76/// Deprecated alias — use [`SqliteSessionService`] instead.
77#[cfg(feature = "sqlite")]
78#[deprecated(since = "0.4.0", note = "renamed to SqliteSessionService")]
79pub type DatabaseSessionService = SqliteSessionService;
80#[cfg(feature = "encrypted-session")]
81pub use encrypted::EncryptedSession;
82#[cfg(feature = "encrypted-session")]
83pub use encryption_key::EncryptionKey;
84#[cfg(feature = "firestore")]
85pub use firestore::{
86    FirestoreSessionConfig, FirestoreSessionService, app_state_path as firestore_app_state_path,
87    event_path as firestore_event_path, session_path as firestore_session_path,
88    user_state_path as firestore_user_state_path,
89};
90#[cfg(feature = "mongodb")]
91pub use mongodb::MongoSessionService;
92#[cfg(feature = "neo4j")]
93pub use neo4j::Neo4jSessionService;
94#[cfg(feature = "postgres")]
95pub use postgres::PostgresSessionService;
96#[cfg(feature = "redis")]
97pub use redis::{
98    RedisSessionConfig, RedisSessionService, app_state_key, events_key, index_key, session_key,
99    user_state_key,
100};
101#[cfg(feature = "vertex-session")]
102pub use vertex::{VertexAiSessionConfig, VertexAiSessionService};