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
- State Management - Key-value state with typed prefixes
- Event History - Conversation history tracking
- Session Lifecycle - Create, update, and restore sessions
Installation
[]
= "0.2.0"
Or use the meta-crate:
[]
= { = "0.2.0", = ["sessions"] }
Quick Start
use ;
use json;
use HashMap;
// Create session service
let service = new;
// Create a new session with initial state
let mut initial_state = new;
initial_state.insert;
let session = service.create.await?;
// Read state (immutable)
let name = session.state.get;
State Prefixes
ADK uses prefixes to organize state:
| Prefix | Purpose | Persistence |
|---|---|---|
user: |
User preferences | Across sessions |
app: |
Application state | Application-wide |
temp: |
Temporary data | Current turn only |
// State is set at session creation or via CreateRequest
let mut state = new;
state.insert;
state.insert;
// Read state
let theme = session.state.get;
Features
- Thread-safe with async/await
- Automatic event history management
- Pluggable storage backends
- Optional SQLite persistence (
databasefeature)
Feature Flags
[]
= { = "0.2.0", = ["database"] }
database- Enable SQLite-backed sessions
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.