Skip to main content

adk_session/
lib.rs

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