Google ADK¶
Session, event, and memory storage backends for Google Agent Development Kit.
Session Service¶
- class sqlspec.extensions.adk.SQLSpecSessionService[source]¶
Bases:
BaseSessionServiceSQLSpec-backed implementation of BaseSessionService.
Provides session and event storage using SQLSpec database adapters. Delegates all database operations to a store implementation.
- Parameters:
store¶ (
BaseAsyncADKStore) – Database store implementation (e.g., AsyncpgADKStore).
Example
from sqlspec.adapters.asyncpg import AsyncpgConfig from sqlspec.adapters.asyncpg.adk.store import AsyncpgADKStore from sqlspec.extensions.adk.service import SQLSpecSessionService
config = AsyncpgConfig(connection_config={“dsn”: “postgresql://…”}) store = AsyncpgADKStore(config) await store.ensure_tables()
service = SQLSpecSessionService(store) session = await service.create_session(
app_name=”my_app”, user_id=”user123”, state={“key”: “value”}
)
- __init__(store)[source]¶
Initialize the session service.
- Parameters:
store¶ (
BaseAsyncADKStore) – Database store implementation.
- property store: BaseAsyncADKStore¶
Return the database store.
- async create_session(*, app_name, user_id, state=None, session_id=None)[source]¶
Create a new session.
- async list_sessions(*, app_name, user_id=None)[source]¶
List all sessions for an app, optionally filtered by user.
Memory Services¶
- class sqlspec.extensions.adk.SQLSpecMemoryService[source]¶
Bases:
BaseMemoryServiceSQLSpec-backed implementation of BaseMemoryService.
Provides memory entry storage using SQLSpec database adapters. Delegates all database operations to a store implementation.
ADK BaseMemoryService defines two core methods: - add_session_to_memory(session) - Ingests session into memory (returns void) - search_memory(app_name, user_id, query) - Searches stored memories
- Parameters:
store¶ (
BaseAsyncADKMemoryStore) – Database store implementation (e.g., AsyncpgADKMemoryStore).
Example
from sqlspec.adapters.asyncpg import AsyncpgConfig from sqlspec.adapters.asyncpg.adk.store import AsyncpgADKMemoryStore from sqlspec.extensions.adk.memory.service import SQLSpecMemoryService
- config = AsyncpgConfig(
connection_config={“dsn”: “postgresql://…”}, extension_config={
- “adk”: {
“memory_table”: “adk_memory_entries”, “memory_use_fts”: True,
}
}
) store = AsyncpgADKMemoryStore(config) await store.ensure_tables()
service = SQLSpecMemoryService(store) await service.add_session_to_memory(completed_session)
- response = await service.search_memory(
app_name=”my_app”, user_id=”user123”, query=”previous conversation about Python”
)
- __init__(store)[source]¶
Initialize the memory service.
- Parameters:
store¶ (
BaseAsyncADKMemoryStore) – Database store implementation.
- property store: BaseAsyncADKMemoryStore¶
Return the database store.
- async add_session_to_memory(session)[source]¶
Add a completed session to the memory store.
Extracts all events with content from the session and stores them as searchable memory entries. Uses UPSERT to skip duplicates.
The Session object contains app_name and user_id properties. Events are converted to memory records and bulk inserted via store. Returns void per ADK BaseMemoryService contract.
Notes
Events without content are skipped
Duplicate event_ids are silently ignored (idempotent)
Uses bulk insert for efficiency
- class sqlspec.extensions.adk.SQLSpecSyncMemoryService[source]¶
Bases:
objectSynchronous SQLSpec-backed memory service.
Provides memory entry storage using SQLSpec sync database adapters. This is a sync-compatible version for use with sync drivers like SQLite.
Note: This does NOT inherit from BaseMemoryService since ADK’s base class requires async methods. Use this for sync-only deployments.
- Parameters:
store¶ (
BaseSyncADKMemoryStore) – Sync database store implementation.
Example
from sqlspec.adapters.sqlite import SqliteConfig from sqlspec.adapters.sqlite.adk.store import SqliteADKMemoryStore from sqlspec.extensions.adk.memory.service import SQLSpecSyncMemoryService
- config = SqliteConfig(
connection_config={“database”: “app.db”}, extension_config={
- “adk”: {
“memory_table”: “adk_memory_entries”,
}
}
) store = SqliteADKMemoryStore(config) store.ensure_tables()
service = SQLSpecSyncMemoryService(store) service.add_session_to_memory(completed_session)
- memories = service.search_memory(
app_name=”my_app”, user_id=”user123”, query=”Python discussion”
)
- __init__(store)[source]¶
Initialize the sync memory service.
- Parameters:
store¶ (
BaseSyncADKMemoryStore) – Sync database store implementation.
- property store: BaseSyncADKMemoryStore¶
Return the database store.
Store Base Classes¶
- class sqlspec.extensions.adk.BaseAsyncADKStore[source]¶
-
Base class for async SQLSpec-backed ADK session stores.
Implements storage operations for Google ADK sessions and events using SQLSpec database adapters with async/await.
This abstract base class provides common functionality for all database-specific store implementations including: - Connection management via SQLSpec configs - Table name validation - Session and event CRUD operations
Subclasses must implement dialect-specific SQL queries and will be created in each adapter directory (e.g., sqlspec/adapters/asyncpg/adk/store.py).
- Parameters:
config¶ (
TypeVar(ConfigT, bound= DatabaseConfigProtocol[Any, Any, Any])) – SQLSpec database configuration with extension_config[“adk”] settings.
Notes
Configuration is read from config.extension_config[“adk”]: - session_table: Sessions table name (default: “adk_sessions”) - events_table: Events table name (default: “adk_events”) - owner_id_column: Optional owner FK column DDL (default: None)
- __init__(config)[source]¶
Initialize the ADK store.
- Parameters:
config¶ (
TypeVar(ConfigT, bound= DatabaseConfigProtocol[Any, Any, Any])) – SQLSpec database configuration.
Notes
Reads configuration from config.extension_config[“adk”]: - session_table: Sessions table name (default: “adk_sessions”) - events_table: Events table name (default: “adk_events”) - owner_id_column: Optional owner FK column DDL (default: None)
- property config: ConfigT¶
Return the database configuration.
- property owner_id_column_ddl: str | None¶
Return the full owner ID column DDL (or None if not configured).
- property owner_id_column_name: str | None¶
Return the owner ID column name only (or None if not configured).
- abstractmethod async create_session(session_id, app_name, user_id, state, owner_id=None)[source]¶
Create a new session.
- Parameters:
- Return type:
- Returns:
The created session record.
- abstractmethod async get_session(session_id)[source]¶
Get a session by ID.
- Parameters:
- Return type:
- Returns:
Session record if found, None otherwise.
- abstractmethod async list_sessions(app_name, user_id=None)[source]¶
List all sessions for an app, optionally filtered by user.
- abstractmethod async append_event(event_record)[source]¶
Append an event to a session.
- Parameters:
event_record¶ (
EventRecord) – Event record to store.- Return type:
- abstractmethod async get_events(session_id, after_timestamp=None, limit=None)[source]¶
Get events for a session.
- class sqlspec.extensions.adk.BaseSyncADKStore[source]¶
-
Base class for sync SQLSpec-backed ADK session stores.
Implements storage operations for Google ADK sessions and events using SQLSpec database adapters with synchronous execution.
This abstract base class provides common functionality for sync database-specific store implementations including: - Connection management via SQLSpec configs - Table name validation - Session and event CRUD operations
Subclasses must implement dialect-specific SQL queries and will be created in each adapter directory (e.g., sqlspec/adapters/sqlite/adk/store.py).
- Parameters:
config¶ (
TypeVar(ConfigT, bound= DatabaseConfigProtocol[Any, Any, Any])) – SQLSpec database configuration with extension_config[“adk”] settings.
Notes
Configuration is read from config.extension_config[“adk”]: - session_table: Sessions table name (default: “adk_sessions”) - events_table: Events table name (default: “adk_events”) - owner_id_column: Optional owner FK column DDL (default: None)
- __init__(config)[source]¶
Initialize the sync ADK store.
- Parameters:
config¶ (
TypeVar(ConfigT, bound= DatabaseConfigProtocol[Any, Any, Any])) – SQLSpec database configuration.
Notes
Reads configuration from config.extension_config[“adk”]: - session_table: Sessions table name (default: “adk_sessions”) - events_table: Events table name (default: “adk_events”) - owner_id_column: Optional owner FK column DDL (default: None)
- property config: ConfigT¶
Return the database configuration.
- property owner_id_column_ddl: str | None¶
Return the full owner ID column DDL (or None if not configured).
- property owner_id_column_name: str | None¶
Return the owner ID column name only (or None if not configured).
- abstractmethod create_session(session_id, app_name, user_id, state, owner_id=None)[source]¶
Create a new session.
- Parameters:
- Return type:
- Returns:
The created session record.
- abstractmethod get_session(session_id)[source]¶
Get a session by ID.
- Parameters:
- Return type:
- Returns:
Session record if found, None otherwise.
- abstractmethod list_sessions(app_name, user_id=None)[source]¶
List all sessions for an app, optionally filtered by user.
- abstractmethod create_event(event_id, session_id, app_name, user_id, author=None, actions=None, content=None, **kwargs)[source]¶
Create a new event.
- abstractmethod list_events(session_id)[source]¶
List events for a session ordered by timestamp.
- Parameters:
- Return type:
- Returns:
List of event records ordered by timestamp ASC.
Memory Store Base Classes¶
- class sqlspec.extensions.adk.BaseAsyncADKMemoryStore[source]¶
-
Base class for async SQLSpec-backed ADK memory stores.
Implements storage operations for Google ADK memory entries using SQLSpec database adapters with async/await.
This abstract base class provides common functionality for all database-specific memory store implementations including: - Connection management via SQLSpec configs - Table name validation - Memory entry CRUD operations - Text search with optional full-text search support
Subclasses must implement dialect-specific SQL queries and will be created in each adapter directory (e.g., sqlspec/adapters/asyncpg/adk/store.py).
- Parameters:
config¶ (
TypeVar(ConfigT, bound= DatabaseConfigProtocol[Any, Any, Any])) – SQLSpec database configuration with extension_config[“adk”] settings.
Notes
Configuration is read from config.extension_config[“adk”]: - memory_table: Memory table name (default: “adk_memory_entries”) - memory_use_fts: Enable full-text search when supported (default: False) - memory_max_results: Max search results (default: 20) - owner_id_column: Optional owner FK column DDL (default: None) - enable_memory: Whether memory is enabled (default: True)
- __init__(config)[source]¶
Initialize the ADK memory store.
- Parameters:
config¶ (
TypeVar(ConfigT, bound= DatabaseConfigProtocol[Any, Any, Any])) – SQLSpec database configuration.
Notes
Reads configuration from config.extension_config[“adk”]: - memory_table: Memory table name (default: “adk_memory_entries”) - memory_use_fts: Enable full-text search when supported (default: False) - memory_max_results: Max search results (default: 20) - owner_id_column: Optional owner FK column DDL (default: None) - enable_memory: Whether memory is enabled (default: True)
- property config: ConfigT¶
Return the database configuration.
- property owner_id_column_ddl: str | None¶
Return the full owner ID column DDL (or None if not configured).
- property owner_id_column_name: str | None¶
Return the owner ID column name only (or None if not configured).
- abstractmethod async create_tables()[source]¶
Create the memory table and indexes if they don’t exist.
Should check self._enabled and skip table creation if False.
- Return type:
- async ensure_tables()[source]¶
Create tables when enabled and emit a standardized log entry.
- Return type:
- abstractmethod async insert_memory_entries(entries, owner_id=None)[source]¶
Bulk insert memory entries with deduplication.
Uses UPSERT pattern to skip duplicates based on event_id.
- Parameters:
- Return type:
- Returns:
Number of entries actually inserted (excludes duplicates).
- Raises:
RuntimeError – If memory store is disabled.
- abstractmethod async search_entries(query, app_name, user_id, limit=None)[source]¶
Search memory entries by text query.
Uses the configured search strategy (simple ILIKE or FTS).
- Parameters:
- Return type:
- Returns:
List of matching memory records ordered by relevance/timestamp.
- Raises:
RuntimeError – If memory store is disabled.
- class sqlspec.extensions.adk.BaseSyncADKMemoryStore[source]¶
-
Base class for sync SQLSpec-backed ADK memory stores.
Implements storage operations for Google ADK memory entries using SQLSpec database adapters with synchronous execution.
This abstract base class provides common functionality for sync database-specific memory store implementations including: - Connection management via SQLSpec configs - Table name validation - Memory entry CRUD operations - Text search with optional full-text search support
Subclasses must implement dialect-specific SQL queries and will be created in each adapter directory (e.g., sqlspec/adapters/sqlite/adk/store.py).
- Parameters:
config¶ (
TypeVar(ConfigT, bound= DatabaseConfigProtocol[Any, Any, Any])) – SQLSpec database configuration with extension_config[“adk”] settings.
Notes
Configuration is read from config.extension_config[“adk”]: - memory_table: Memory table name (default: “adk_memory_entries”) - memory_use_fts: Enable full-text search when supported (default: False) - memory_max_results: Max search results (default: 20) - owner_id_column: Optional owner FK column DDL (default: None) - enable_memory: Whether memory is enabled (default: True)
- __init__(config)[source]¶
Initialize the sync ADK memory store.
- Parameters:
config¶ (
TypeVar(ConfigT, bound= DatabaseConfigProtocol[Any, Any, Any])) – SQLSpec database configuration.
Notes
Reads configuration from config.extension_config[“adk”]: - memory_table: Memory table name (default: “adk_memory_entries”) - memory_use_fts: Enable full-text search when supported (default: False) - memory_max_results: Max search results (default: 20) - owner_id_column: Optional owner FK column DDL (default: None) - enable_memory: Whether memory is enabled (default: True)
- property config: ConfigT¶
Return the database configuration.
- property owner_id_column_ddl: str | None¶
Return the full owner ID column DDL (or None if not configured).
- property owner_id_column_name: str | None¶
Return the owner ID column name only (or None if not configured).
- abstractmethod create_tables()[source]¶
Create the memory table and indexes if they don’t exist.
Should check self._enabled and skip table creation if False.
- Return type:
- abstractmethod insert_memory_entries(entries, owner_id=None)[source]¶
Bulk insert memory entries with deduplication.
Uses UPSERT pattern to skip duplicates based on event_id.
- Parameters:
- Return type:
- Returns:
Number of entries actually inserted (excludes duplicates).
- Raises:
RuntimeError – If memory store is disabled.
- abstractmethod search_entries(query, app_name, user_id, limit=None)[source]¶
Search memory entries by text query.
Uses the configured search strategy (simple ILIKE or FTS).
- Parameters:
- Return type:
- Returns:
List of matching memory records ordered by relevance/timestamp.
- Raises:
RuntimeError – If memory store is disabled.
Record Types¶
- class sqlspec.extensions.adk.SessionRecord[source]¶
Bases:
TypedDictDatabase record for a session.
Represents the schema for sessions stored in the database.