API¶
Services¶
- 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|BaseSyncADKStore) -- Database store implementation.
- __init__(store)[source]
Initialize the session service.
- Parameters:
store¶ (
BaseAsyncADKStore|BaseSyncADKStore) -- Database store implementation.
- property store: BaseAsyncADKStore | BaseSyncADKStore
Return the database store.
- async create_session(*, app_name, user_id, state=None, session_id=None)[source]
Create a new session.
- Parameters:
- Return type:
Session- Returns:
The newly created session.
- async get_session(*, app_name, user_id, session_id, config=None)[source]
Get a session by ID.
- async get_user_state(*, app_name, user_id)[source]
Get user-scoped state for an app and user.
ADK's service API returns unprefixed user state keys, while SQLSpec stores the durable state using ADK's documented
user:prefix.
- async list_sessions(*, app_name, user_id=None)[source]
List all sessions for an app, optionally filtered by user.
- async delete_session(*, app_name, user_id, session_id)[source]
Delete a session and all its events.
- async append_event(session, event)[source]
Append an event to a session.
Persists the event record and the post-append durable state atomically via
store.append_event_and_update_state(), then updates the in-memory session only after persistence succeeds.Implements stale-session detection: if the session has been modified in storage since it was last loaded, a
ValueErroris raised instead of silently overwriting.temp:keys are stripped from the persisted state snapshot so they never survive a reload.- Parameters:
- Return type:
Event- Returns:
The appended event.
- Raises:
ValueError -- If the session has been modified in storage since it was loaded (stale session).
- class sqlspec.extensions.adk.memory.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.
- __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.
- async add_events_to_memory(*, app_name, user_id, events, session_id=None, custom_metadata=None)[source]
Add an explicit list of events to the memory service.
Same Event-to-MemoryRecord extraction logic as
add_session_to_memory, but operates on a sequence of Events directly (no Session wrapper needed).
- async add_memory(*, app_name, user_id, memories, custom_metadata=None)[source]
Add explicit memory items directly to the memory service.
Each entry's
contentis serialized tocontent_json, text is extracted fromcontent.partsforcontent_text, andcustom_metadatamerges the entry-levelentry.custom_metadatawith the call-levelcustom_metadataparameter.
- async search_memory(*, app_name, user_id, query)[source]
Search memory entries by text query.
Uses the store's configured search strategy (simple ILIKE or FTS).
- class sqlspec.extensions.adk.memory.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.
- __init__(store)[source]
Initialize the sync memory service.
- Parameters:
store¶ (
BaseSyncADKMemoryStore) -- Sync database store implementation.
- property store: BaseSyncADKMemoryStore
Return the database store.
- 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.
- class sqlspec.extensions.adk.SQLSpecArtifactService[source]
Bases:
BaseArtifactServiceSQLSpec-backed implementation of BaseArtifactService.
Composes SQL metadata storage with
sqlspec/storage/content backends to provide versioned artifact management for Google ADK.Metadata (version number, filename, MIME type, custom metadata, canonical URI) is stored in a SQL table managed by the artifact store. Content bytes are stored in object storage (S3, GCS, Azure, local filesystem) via the storage registry.
- Parameters:
store¶ (
BaseAsyncADKArtifactStore) -- Artifact metadata store implementation.artifact_storage_uri¶ (
str) -- Base URI for content storage. Can also be a registered alias in the storage registry.registry¶ (
StorageRegistry|None) -- Storage registry to use. Defaults to the global singleton.
- __init__(store, artifact_storage_uri, registry=None)[source]
- property store: BaseAsyncADKArtifactStore
Return the artifact metadata store.
- property artifact_storage_uri: str
Return the base URI for content storage.
- async save_artifact(*, app_name, user_id, filename, artifact, session_id=None, custom_metadata=None)[source]
Save an artifact, returning the new version number.
Writes content to object storage first, then inserts the metadata row. If content write succeeds but metadata insert fails, the orphaned content blob is logged but not automatically cleaned up (eventual consistency is acceptable; orphan sweep can be added later).
- Parameters:
- Return type:
- Returns:
The version number (0-based, incrementing).
- async load_artifact(*, app_name, user_id, filename, session_id=None, version=None)[source]
Load an artifact by reading metadata then fetching content.
- Parameters:
- Return type:
Part|None- Returns:
Deserialized Part, or None if not found.
- async list_artifact_keys(*, app_name, user_id, session_id=None)[source]
List distinct artifact filenames.
When
session_idis provided, returns both session-scoped and user-scoped filenames. When None, returns only user-scoped filenames.
- async delete_artifact(*, app_name, user_id, filename, session_id=None)[source]
Delete an artifact and all its versions.
Deletes metadata rows first (fail-fast), then removes content objects from storage (best-effort).
- async list_versions(*, app_name, user_id, filename, session_id=None)[source]
List all version numbers for an artifact.
- async list_artifact_versions(*, app_name, user_id, filename, session_id=None)[source]
List all versions with full metadata for an artifact.
Session Stores¶
- 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_session") - events_table: Events table name (default: "adk_event") - app_state_table: App-scoped state table name (default: "adk_app_state") - user_state_table: User-scoped state table name (default: "adk_user_state") - metadata_table: Internal metadata table name (default: "adk_internal_metadata") - 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_session") - events_table: Events table name (default: "adk_event") - app_state_table: App-scoped state table name (default: "adk_app_state") - user_state_table: User-scoped state table name (default: "adk_user_state") - metadata_table: Internal metadata table name (default: "adk_internal_metadata") - owner_id_column: Optional owner FK column DDL (default: None)
- async create_tables()[source]
Create the sessions and events tables if they don't exist.
- Return type:
- 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(app_name, user_id, session_id, *, renew_for=None)[source]
Get a session.
- Parameters:
- Return type:
- Returns:
Session record if found, None otherwise.
- abstractmethod async update_session_state(app_name, user_id, session_id, state)[source]
Update session state.
- abstractmethod async list_sessions(app_name, user_id=None)[source]
List all sessions for an app, optionally filtered by user.
- abstractmethod async delete_session(app_name, user_id, session_id)[source]
Delete a session and its events.
- 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 append_event_and_update_state(event_record, app_name, user_id, session_id, state, *, app_state=None, user_state=None)[source]
Atomically append an event and update the session's durable state.
This is the authoritative durable write boundary for post-creation session mutations. The event insert, session state update, and the optional scoped-state upserts must succeed together or fail together, and the updated session record is returned in the same round-trip so callers don't need a follow-up read.
When
app_stateis provided (non-None), it is a full merged app-scoped snapshot to replace/upsert forapp_name. Whenuser_stateis provided, it is a full merged user-scoped snapshot to replace/upsert for(app_name, user_id).Nonemeans that scope was untouched by the event and must not be written.- Parameters:
event_record¶ (
EventRecord) -- Event record to store.app_name¶ (
str) -- Application name for routing scoped-state upserts.user_id¶ (
str) -- User identifier for routing user-scoped upserts.session_id¶ (
str) -- Session identifier whose state should be updated.state¶ (
dict[str, typing.Any]) -- Post-append durable session-scoped state snapshot (temp:keys already stripped by the service layer).app_state¶ (
dict[str, typing.Any] |None) -- Full app-scoped state snapshot (app:*keys) to upsert atomically, orNonewhen untouched.user_state¶ (
dict[str, typing.Any] |None) -- Full user-scoped state snapshot (user:*keys) to upsert atomically, orNonewhen untouched.
- Return type:
- Returns:
The updated SessionRecord reflecting the new state and update_time.
- Raises:
ValueError -- If the session row no longer exists at update time (raced with delete_session).
- abstractmethod async get_events(app_name, user_id, session_id, after_timestamp=None, limit=None)[source]
Get events for a session.
- Parameters:
- Return type:
- Returns:
List of event records ordered by timestamp ascending.
- abstractmethod async delete_expired_events(before)[source]
Delete events older than the given timestamp.
- abstractmethod async delete_idle_sessions(updated_before)[source]
Delete sessions whose update_time predates the given threshold.
- abstractmethod async get_app_state(app_name)[source]
Return app-scoped state for an application.
- abstractmethod async get_user_state(app_name, user_id)[source]
Return user-scoped state for an application user.
- abstractmethod async upsert_app_state(app_name, state)[source]
Insert or replace app-scoped state for an application.
- abstractmethod async upsert_user_state(app_name, user_id, state)[source]
Insert or replace user-scoped state for an application user.
- abstractmethod async get_metadata(key)[source]
Return a value from the ADK internal metadata table.
- abstractmethod async set_metadata(key, value)[source]
Set a value in the ADK internal metadata table.
- property config: ConfigT
Return the database configuration.
- property session_table: str
Return the sessions table name.
- property events_table: str
Return the events table name.
- property app_state_table: str
Return the app-scoped state table name.
- property user_state_table: str
Return the user-scoped state table name.
- property metadata_table: str
Return the ADK metadata table name.
- 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).
- async drop_tables()[source]
Drop all ADK tables managed by this store in FK-safe order.
- Return type:
- class sqlspec.extensions.adk.BaseSyncADKStore[source]
-
Base class for sync SQLSpec-backed ADK session stores.
Sync-backed adapters expose a real synchronous API for direct use in synchronous applications. Async bridging belongs in
SQLSpecSessionServicewhen Google ADK calls into a sync store from its async service surface.- Parameters:
config¶ (
TypeVar(ConfigT, bound= DatabaseConfigProtocol[Any, Any, Any])) -- SQLSpec database configuration with extension_config["adk"] settings.
- __init__(config)[source]
Initialize the sync ADK store.
- abstractmethod create_tables()[source]
Create the sessions and events tables if they don't exist.
- Return type:
- abstractmethod create_session(session_id, app_name, user_id, state, owner_id=None)[source]
Create a new session.
- Return type:
- abstractmethod get_session(app_name, user_id, session_id, *, renew_for=None)[source]
Get a session.
- Return type:
- abstractmethod update_session_state(app_name, user_id, session_id, state)[source]
Update session state.
- Return type:
- abstractmethod list_sessions(app_name, user_id=None)[source]
List all sessions for an app, optionally filtered by user.
- Return type:
- abstractmethod delete_session(app_name, user_id, session_id)[source]
Delete a session and its events.
- Return type:
- abstractmethod append_event_and_update_state(event_record, app_name, user_id, session_id, state, *, app_state=None, user_state=None)[source]
Atomically append an event and update the session's durable state.
- Return type:
- abstractmethod get_events(app_name, user_id, session_id, after_timestamp=None, limit=None)[source]
Get events for a session.
- Return type:
- abstractmethod delete_expired_events(before)[source]
Delete events older than the given timestamp.
- Return type:
- abstractmethod delete_idle_sessions(updated_before)[source]
Delete sessions whose update_time predates the given threshold.
- Return type:
- abstractmethod get_app_state(app_name)[source]
Return app-scoped state for an application.
- abstractmethod get_user_state(app_name, user_id)[source]
Return user-scoped state for an application user.
- abstractmethod upsert_app_state(app_name, state)[source]
Insert or replace app-scoped state for an application.
- Return type:
- abstractmethod upsert_user_state(app_name, user_id, state)[source]
Insert or replace user-scoped state for an application user.
- Return type:
- abstractmethod get_metadata(key)[source]
Return a value from the ADK internal metadata table.
- abstractmethod set_metadata(key, value)[source]
Set a value in the ADK internal metadata table.
- Return type:
- property config: ConfigT
Return the database configuration.
- property session_table: str
Return the sessions table name.
- property events_table: str
Return the events table name.
- property app_state_table: str
Return the app-scoped state table name.
- property user_state_table: str
Return the user-scoped state table name.
- property metadata_table: str
Return the ADK metadata table name.
- property owner_id_column_ddl: str | None
Return the full owner ID column DDL (or None if not configured).
Memory Stores¶
- 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.
- Parameters:
config¶ (
TypeVar(ConfigT, bound= DatabaseConfigProtocol[Any, Any, Any])) -- SQLSpec database configuration with extension_config["adk"] settings.
- __init__(config)[source]
Initialize the ADK memory store.
- property config: ConfigT
Return the database configuration.
- property memory_table: str
Return the memory table name.
- property enabled: bool
Return whether memory store is enabled.
- property use_fts: bool
Return whether full-text search is enabled.
- property max_results: int
Return the max search results limit.
- 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.
- abstractmethod async delete_entries_by_session(session_id)[source]
Delete all memory entries for a specific session.
- 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.
- Parameters:
config¶ (
TypeVar(ConfigT, bound= DatabaseConfigProtocol[Any, Any, Any])) -- SQLSpec database configuration with extension_config["adk"] settings.
- __init__(config)[source]
Initialize the sync ADK memory store.
- property config: ConfigT
Return the database configuration.
- property memory_table: str
Return the memory table name.
- property enabled: bool
Return whether memory store is enabled.
- property use_fts: bool
Return whether full-text search is enabled.
- property max_results: int
Return the max search results limit.
- 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:
- ensure_tables()[source]
Create tables when enabled and emit a standardized log entry.
- 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.
- abstractmethod delete_entries_by_session(session_id)[source]
Delete all memory entries for a specific session.
Artifact Stores¶
- class sqlspec.extensions.adk.BaseAsyncADKArtifactStore[source]
-
Base class for async SQLSpec-backed ADK artifact metadata stores.
Manages artifact version metadata in a SQL table. Content bytes are stored externally via
sqlspec/storage/backends and referenced by canonical URI in each metadata row.Subclasses must implement dialect-specific SQL queries.
- Parameters:
config¶ (
TypeVar(ConfigT, bound= DatabaseConfigProtocol[Any, Any, Any])) -- SQLSpec database configuration with extension_config["adk"] settings.
- __init__(config)[source]
Initialize the async ADK artifact store.
- property config: ConfigT
Return the database configuration.
- property artifact_table: str
Return the artifact versions table name.
- abstractmethod async insert_artifact(record)[source]
Insert an artifact version metadata row.
- Parameters:
record¶ (
ArtifactRecord) -- Artifact metadata record to insert.- Return type:
- abstractmethod async get_artifact(app_name, user_id, filename, session_id=None, version=None)[source]
Get a specific artifact version's metadata.
When
versionis None, returns the latest version.- Parameters:
- Return type:
- Returns:
Artifact record if found, None otherwise.
- abstractmethod async list_artifact_keys(app_name, user_id, session_id=None)[source]
List distinct artifact filenames.
When
session_idis provided, returns filenames from both session-scoped and user-scoped artifacts. When None, returns only user-scoped artifact filenames.
- abstractmethod async list_artifact_versions(app_name, user_id, filename, session_id=None)[source]
List all version records for an artifact, ordered by version ascending.
- abstractmethod async delete_artifact(app_name, user_id, filename, session_id=None)[source]
Delete all version records for an artifact and return them.
The caller uses the returned records to clean up content from object storage. Metadata is deleted first (fail-fast); content cleanup is best-effort.
- abstractmethod async get_next_version(app_name, user_id, filename, session_id=None)[source]
Get the next version number for an artifact.
Returns 0 if no versions exist (first version), otherwise
max(version) + 1.
- abstractmethod async create_table()[source]
Create the artifact versions table if it does not exist.
- Return type:
- class sqlspec.extensions.adk.BaseSyncADKArtifactStore[source]
-
Base class for sync SQLSpec-backed ADK artifact metadata stores.
Synchronous counterpart of
BaseAsyncADKArtifactStore.- Parameters:
config¶ (
TypeVar(ConfigT, bound= DatabaseConfigProtocol[Any, Any, Any])) -- SQLSpec database configuration with extension_config["adk"] settings.
- __init__(config)[source]
Initialize the sync ADK artifact store.
- property config: ConfigT
Return the database configuration.
- property artifact_table: str
Return the artifact versions table name.
- abstractmethod insert_artifact(record)[source]
Insert an artifact version metadata row.
- Parameters:
record¶ (
ArtifactRecord) -- Artifact metadata record to insert.- Return type:
- abstractmethod get_artifact(app_name, user_id, filename, session_id=None, version=None)[source]
Get a specific artifact version's metadata.
When
versionis None, returns the latest version.- Parameters:
- Return type:
- Returns:
Artifact record if found, None otherwise.
- abstractmethod list_artifact_keys(app_name, user_id, session_id=None)[source]
List distinct artifact filenames.
- abstractmethod list_artifact_versions(app_name, user_id, filename, session_id=None)[source]
List all version records for an artifact, ordered by version ascending.
- abstractmethod delete_artifact(app_name, user_id, filename, session_id=None)[source]
Delete all version records for an artifact and return them.
- abstractmethod get_next_version(app_name, user_id, filename, session_id=None)[source]
Get the next version number for an artifact.
- abstractmethod create_table()[source]
Create the artifact versions table if it does not exist.
- Return type:
Record Types¶
- class sqlspec.extensions.adk.SessionRecord[source]
Bases:
TypedDictDatabase record for a session.
Represents the schema for sessions stored in the database.
- class sqlspec.extensions.adk.EventRecord[source]
Bases:
TypedDictDatabase record for an event.
Stores the full ADK Event as a single JSON blob (
event_data) alongside indexed scalar columns used for scoped query filtering.This design eliminates column drift with upstream ADK: new Event fields are automatically captured in
event_datawithout schema changes.
- class sqlspec.extensions.adk.MemoryRecord[source]
Bases:
TypedDictDatabase record for a memory entry.
Represents the schema for memory entries stored in the database. Contains extracted content from ADK events for searchable long-term memory.
- class sqlspec.extensions.adk.ArtifactRecord[source]
Bases:
TypedDictDatabase record for an artifact version.
Represents the schema for artifact metadata stored in the database. Content is stored separately in object storage; this record tracks versioning, ownership, and the canonical URI pointing to the content.
The composite key is (app_name, user_id, session_id, filename, version), where session_id may be NULL for user-scoped artifacts.
Configuration¶
- class sqlspec.extensions.adk.ADKConfig[source]
Bases:
TypedDictConfiguration options for ADK session and memory store extension.
All fields are optional with sensible defaults. Use in extension_config["adk"]:
- Configuration supports three deployment scenarios:
SQLSpec manages everything (runtime + migrations)
SQLSpec runtime only (external migration tools like Alembic/Flyway)
Selective features (sessions OR memory, not both)
- enable_sessions: NotRequired[bool]
True.
When False: session service unavailable, session store operations disabled. Independent of migration control - can use externally-managed tables.
- Type:
Enable session store at runtime. Default
- enable_memory: NotRequired[bool]
True.
When False: memory service unavailable, memory store operations disabled. Independent of migration control - can use externally-managed tables.
- Type:
Enable memory store at runtime. Default
- include_sessions_migration: NotRequired[bool]
True.
When False: session migration DDL skipped (use external migration tools). Decoupled from enable_sessions - allows external table management with SQLSpec runtime.
- Type:
Include session tables in SQLSpec migrations. Default
- include_memory_migration: NotRequired[bool]
True.
When False: memory migration DDL skipped (use external migration tools). Decoupled from enable_memory - allows external table management with SQLSpec runtime.
- Type:
Include memory tables in SQLSpec migrations. Default
- session_table: NotRequired[str]
'adk_session'
- Type:
Name of the sessions table. Default
- events_table: NotRequired[str]
'adk_event'
- Type:
Name of the events table. Default
- app_state_table: NotRequired[str]
'adk_app_state'
- Type:
Name of the app-scoped state table. Default
- user_state_table: NotRequired[str]
'adk_user_state'
- Type:
Name of the user-scoped state table. Default
- metadata_table: NotRequired[str]
'adk_internal_metadata'
- Type:
Name of the internal metadata table. Default
- memory_table: NotRequired[str]
'adk_memory'
- Type:
Name of the memory entries table. Default
- artifact_table: NotRequired[str]
'adk_artifact'
- Type:
Name of the artifact metadata table. Default
- artifact_storage_uri: NotRequired[str]
Base URI for artifact content storage.
Points to a
sqlspec/storage/backend where artifact binary content is stored. Can be a direct URI (s3://bucket/path,file:///path) or a registered alias in the storage registry.
- memory_use_fts: NotRequired[bool]
False.
When True, adapters will use their native FTS capabilities where available: - PostgreSQL: to_tsvector/to_tsquery with GIN index - SQLite: FTS5 virtual table - DuckDB: FTS extension with match_bm25 - Oracle: CONTAINS() with CTXSYS.CONTEXT index - Spanner: TOKENIZE_FULLTEXT with search index - MySQL: MATCH...AGAINST with FULLTEXT index
When False, adapters use simple LIKE/ILIKE queries (works without indexes).
- Type:
Enable full-text search when supported. Default
- memory_max_results: NotRequired[int]
Limits the number of memory entries returned by search_memory(). Can be overridden per-query via the limit parameter.
- Type:
Maximum number of results for memory search queries. Default
- owner_id_column: NotRequired[str]
Optional owner ID column definition to link sessions/memories to a user, tenant, team, or other entity.
Format: "column_name TYPE [NOT NULL] REFERENCES table(column) [options...]"
The entire definition is passed through to DDL verbatim. We only parse the column name (first word) for use in INSERT/SELECT statements.
This column is added to both session and memory tables for consistent multi-tenant isolation.
- Supports:
Foreign key constraints: REFERENCES table(column)
Nullable or NOT NULL
CASCADE options: ON DELETE CASCADE, ON UPDATE CASCADE
Dialect-specific options (DEFERRABLE, ENABLE VALIDATE, etc.)
Plain columns without FK (just extra column storage)
Converters¶
Conversion functions between ADK models and database records.
Implements full-event JSON storage: the entire Event is serialized via
Event.model_dump(exclude_none=True, mode="json") into a single event_data
column, with a small set of indexed scalar columns extracted alongside for
query performance. Reconstruction uses Event.model_validate().
Also provides scoped-state helpers that normalise ADK state prefixes
(app:, user:, temp:) so the shared service layer can split,
filter, and merge state before handing it to backend stores.
- sqlspec.extensions.adk.converters.compute_update_marker(update_time)[source]
Compute a stable revision marker from an update timestamp.
Uses the same format as ADK's
StorageSession.get_update_marker(): ISO 8601 with microsecond precision, normalized to UTC.
- sqlspec.extensions.adk.converters.event_to_record(event, app_name, user_id, session_id)[source]
Convert ADK Event to database record using full-event JSON storage.
The entire Event is serialized into
event_datavia Pydantic'smodel_dump(exclude_none=True, mode="json"). Indexed scalar columns are extracted alongside for scoped filtering.
- sqlspec.extensions.adk.converters.filter_temp_state(state)[source]
Return a copy of state with all
temp:keys removed.temp:keys are process-local/session-runtime state and must never be written to persistent storage.
- sqlspec.extensions.adk.converters.merge_scoped_state(session_state, app_state=None, user_state=None)[source]
Merge scoped state buckets into a single state dict.
Priority: session_state is base, app_state and user_state overlay. This matches ADK's documented merge semantics on session load.
- Parameters:
- Return type:
- Returns:
Merged state dict.
- sqlspec.extensions.adk.converters.record_to_event(record)[source]
Convert database record to ADK Event.
Reconstruction is lossless for valid ADK payloads: the full Event is restored from
event_dataviaEvent.model_validate().- Parameters:
record¶ (
EventRecord) -- Event database record.- Return type:
Event- Returns:
ADK Event object.
- sqlspec.extensions.adk.converters.record_to_session(record, events)[source]
Convert database record to ADK Session.
Sets
_storage_update_markerso the service layer can detect concurrent modifications on subsequentappend_eventcalls.- Parameters:
record¶ (
SessionRecord) -- Session database record.events¶ (
list[EventRecord]) -- List of event records for this session.
- Return type:
Session- Returns:
ADK Session object with storage marker set.
- sqlspec.extensions.adk.converters.session_to_record(session)[source]
Convert ADK Session to database record.
- Parameters:
session¶ (
Session) -- ADK Session object.- Return type:
- Returns:
SessionRecord for database storage.
- sqlspec.extensions.adk.converters.split_scoped_state(state)[source]
Split state into app-scoped, user-scoped, and session-scoped buckets.
- Parameters:
state¶ (
dict[str, typing.Any]) -- Full session state dict (temp: already stripped).- Return type:
tuple[dict[str, typing.Any],dict[str, typing.Any],dict[str, typing.Any]]- Returns:
Tuple of (app_state, user_state, session_state). app_state: keys starting with "app:" user_state: keys starting with "user:" session_state: all other keys