Skip to content

Commit cf1f007

Browse files
authored
feat(adk): overhaul ADK backend to align with v1.0.0 store (#400)
## Summary Improved ADK integration based on upstream improvements since initial implementation. - **Full-event JSON storage**: Replace 17-column decomposed `EventRecord` with 5-column model (`session_id`, `invocation_id`, `author`, `timestamp`, `event_json`). Eliminates column drift with upstream ADK — new Event fields are captured automatically without schema changes. - **State persistence fix**: `append_event()` now persists session state atomically with the event via `append_event_and_update_state()`. Previously, state mutations from `event.actions.state_delta` were lost on reload. - **Scoped state**: `temp:` keys stripped before persistence, `app:`/`user:` split/merge helpers for future cross-session state sharing. - **Unified async contract**: All stores (including previously sync-only DuckDB, ADBC, pymysql, Oracle sync, Spanner, psycopg sync, mysqlconnector sync) now extend `BaseAsyncADKStore` and wrap sync operations via `sqlspec.utils.sync_tools.async_()`. - **Artifact service**: New `SQLSpecArtifactService` composing SQL metadata tables with `sqlspec/storage/` content backends (S3, GCS, Azure, local filesystem). - **BigQuery removed**: Correctness bugs (JSON_VALUE flattening, unsafe bytes encoding) and architectural mismatch (high latency, eventual consistency, per-query cost) confirmed removal. - **CockroachDB upgraded**: GIN indexes and native tsvector FTS restored (incorrectly stripped in prior code). - **Memory service expanded**: `add_events_to_memory()` and `add_memory()` implemented (ADK v1.25+ contract). - **Capability config**: `ADKConfig` expanded with `fts_language`, `artifact_storage_uri`, `schema_version`, partitioning, retention, compression, and SQLite optimization sections.
1 parent 466107b commit cf1f007

68 files changed

Lines changed: 7172 additions & 5181 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ jobs:
108108
- name: Test
109109
env:
110110
PYTHONFAULTHANDLER: "1"
111-
PYTEST_ADDOPTS: "--max-worker-restart=0 -s"
111+
PYTEST_ADDOPTS: "--max-worker-restart=0"
112112
run: timeout 900s uv run pytest -n 2 --dist=loadgroup
113113

114114
# test-linux-freethreaded:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,4 @@ uv.toml
6868
.geminiignore
6969
.beads/
7070
tools/scripts/profiles/*.prof
71+
.agents/

docs/_tapes/migration_workflow.tape

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,31 @@ Type "# Initialize the migration environment"
2828
Enter
2929
Sleep 500ms
3030

31-
Type "sqlspec db init"
31+
Type "sqlspec init"
3232
Enter
3333
Sleep 3s
3434

3535
Type "# Create a new migration"
3636
Enter
3737
Sleep 500ms
3838

39-
Type 'sqlspec db create-migration -m "add users table"'
39+
Type 'sqlspec create-migration -m "add users table"'
4040
Enter
4141
Sleep 3s
4242

4343
Type "# Apply the migration"
4444
Enter
4545
Sleep 500ms
4646

47-
Type "sqlspec db upgrade"
47+
Type "sqlspec upgrade"
4848
Enter
4949
Sleep 3s
5050

5151
Type "# Check current revision"
5252
Enter
5353
Sleep 500ms
5454

55-
Type "sqlspec db show-current-revision"
55+
Type "sqlspec show-current-revision"
5656
Enter
5757
Sleep 3s
5858

docs/extensions/adk/adapters.rst

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,36 @@ Choosing an Adapter
1010

1111
Use async adapters for best performance with ADK runners:
1212

13-
- **PostgreSQL**: ``asyncpg`` (recommended), ``psycopg`` (async mode)
14-
- **SQLite**: ``aiosqlite``
15-
- **MySQL**: ``asyncmy``
13+
- **PostgreSQL** (recommended): ``asyncpg``, ``psycopg`` (async mode), ``psqlpy``
14+
- **CockroachDB**: ``cockroach_asyncpg``, ``cockroach_psycopg`` (full FTS support)
15+
- **MySQL/MariaDB**: ``asyncmy``
16+
- **SQLite**: ``aiosqlite`` (development and single-process)
17+
- **Oracle**: ``oracledb``
18+
- **DuckDB**: ``duckdb`` (analytics; reduced-scope for ADK)
19+
- **ADBC**: ``adbc`` (Arrow-native, driver-agnostic)
20+
- **Spanner**: ``spanner`` (Google Cloud, globally distributed)
1621

17-
Sync adapters work but require wrapping with ``anyio`` for async ADK runners.
22+
Sync adapters (``psycopg`` sync mode, ``sqlite``, ``mysqlconnector``, ``pymysql``)
23+
work but require wrapping with ``anyio`` for async ADK runners.
24+
25+
Each Adapter Provides
26+
=====================
27+
28+
Every adapter with ADK support ships three store classes:
29+
30+
- **Session store** (e.g., ``AsyncpgADKStore``) -- sessions and events.
31+
- **Memory store** (e.g., ``AsyncpgADKMemoryStore``) -- long-term memory with FTS.
32+
- **Artifact store** (e.g., ``AsyncpgADKArtifactStore``) -- artifact metadata.
33+
34+
Import from the adapter's ``adk`` subpackage:
35+
36+
.. code-block:: python
37+
38+
from sqlspec.adapters.asyncpg.adk import (
39+
AsyncpgADKStore,
40+
AsyncpgADKMemoryStore,
41+
AsyncpgADKArtifactStore,
42+
)
1843
1944
Example
2045
=======
@@ -30,6 +55,6 @@ Example
3055
See Also
3156
========
3257

33-
- :doc:`backends` for the full adapter support matrix.
58+
- :doc:`backends` for the full support matrix and backend-specific notes.
3459
- :doc:`/usage/drivers_and_querying` for adapter configuration patterns.
3560
- :doc:`/reference/adapters` for the complete adapter API.

docs/extensions/adk/api.rst

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,20 @@ Services
1919
:show-inheritance:
2020
:no-index:
2121

22-
Base Stores
23-
===========
22+
.. autoclass:: sqlspec.extensions.adk.memory.SQLSpecSyncMemoryService
23+
:members:
24+
:undoc-members:
25+
:show-inheritance:
26+
:no-index:
27+
28+
.. autoclass:: SQLSpecArtifactService
29+
:members:
30+
:undoc-members:
31+
:show-inheritance:
32+
:no-index:
33+
34+
Session Stores
35+
==============
2436

2537
.. autoclass:: BaseAsyncADKStore
2638
:members:
@@ -34,6 +46,9 @@ Base Stores
3446
:show-inheritance:
3547
:no-index:
3648

49+
Memory Stores
50+
=============
51+
3752
.. autoclass:: BaseAsyncADKMemoryStore
3853
:members:
3954
:undoc-members:
@@ -45,3 +60,57 @@ Base Stores
4560
:undoc-members:
4661
:show-inheritance:
4762
:no-index:
63+
64+
Artifact Stores
65+
===============
66+
67+
.. autoclass:: BaseAsyncADKArtifactStore
68+
:members:
69+
:undoc-members:
70+
:show-inheritance:
71+
:no-index:
72+
73+
.. autoclass:: BaseSyncADKArtifactStore
74+
:members:
75+
:undoc-members:
76+
:show-inheritance:
77+
:no-index:
78+
79+
Record Types
80+
============
81+
82+
.. autoclass:: SessionRecord
83+
:members:
84+
:show-inheritance:
85+
:no-index:
86+
87+
.. autoclass:: EventRecord
88+
:members:
89+
:show-inheritance:
90+
:no-index:
91+
92+
.. autoclass:: MemoryRecord
93+
:members:
94+
:show-inheritance:
95+
:no-index:
96+
97+
.. autoclass:: ArtifactRecord
98+
:members:
99+
:show-inheritance:
100+
:no-index:
101+
102+
Configuration
103+
=============
104+
105+
.. autoclass:: ADKConfig
106+
:members:
107+
:show-inheritance:
108+
:no-index:
109+
110+
Converters
111+
==========
112+
113+
.. automodule:: sqlspec.extensions.adk.converters
114+
:members:
115+
:undoc-members:
116+
:no-index:

0 commit comments

Comments
 (0)