Skip to content

Google ADK sessions

Google ADK keeps conversation history and state in a session service. google-adk-persql stores those sessions in a PerSQL database, so agent threads survive restarts and live in an isolated SQLite database you can query like any other.

pip install google-adk-persql
import os
from google.adk.runners import Runner
from persql import PerSQL
from google_adk_persql import PerSQLSessionService
client = PerSQL(token=os.environ["PERSQL_TOKEN"])
service = PerSQLSessionService(client.database("acme/agent-state"))
runner = Runner(agent=agent, app_name="my-app", session_service=service)

The service mirrors ADK’s built-in SqliteSessionService: the same four-table layout, app: / user: / temp: state-scope semantics, and events stored as opaque JSON so ADK’s event fields can evolve without migrations. Async PerSQL databases are awaited natively; sync databases run via asyncio.to_thread.

Sessions from every app and user can share one database — rows are keyed by (app_name, user_id, session_id). For hard isolation, give each tenant its own database instead:

service = PerSQLSessionService(client.database(f"acme/tenant-{tenant_id}"))

PerSQL databases are provisioned on first write and billed by usage, so per-tenant session stores cost what they’re actually used for.

SELECT json_extract(event_data, '$.author') AS author, timestamp
FROM adk_events
WHERE session_id = 'user-42'
ORDER BY timestamp;