adk-session 0.2.0

Session management and state persistence for Rust Agent Development Kit (ADK-Rust) agents
Documentation

adk-session

Session management and state persistence for Rust Agent Development Kit (ADK-Rust) agents.

Crates.io Documentation License

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

[dependencies]
adk-session = "0.2.0"

Or use the meta-crate:

[dependencies]
adk-rust = { version = "0.2.0", features = ["sessions"] }

Quick Start

use adk_session::{InMemorySessionService, SessionService, CreateRequest, KEY_PREFIX_USER};
use serde_json::json;
use std::collections::HashMap;

// Create session service
let service = InMemorySessionService::new();

// Create a new session with initial state
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,  // Auto-generate
    state: initial_state,
}).await?;

// Read state (immutable)
let name = session.state().get("user:name");

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 = HashMap::new();
state.insert("user:theme".to_string(), json!("dark"));
state.insert("temp:current_step".to_string(), json!("2"));

// Read state
let theme = session.state().get("user:theme");

Features

  • Thread-safe with async/await
  • Automatic event history management
  • Pluggable storage backends
  • Optional SQLite persistence (database feature)

Feature Flags

[dependencies]
adk-session = { version = "0.2.0", features = ["database"] }
  • database - Enable SQLite-backed sessions

Related Crates

License

Apache-2.0

Part of ADK-Rust

This crate is part of the ADK-Rust framework for building AI agents in Rust.