Ecto-backed session persistence for the Elixir ADK (adk_ex).
Implements ADK.Session.Service using Ecto, providing database-backed session storage with support for SQLite3 (dev/test) and PostgreSQL (production).
Add adk_ex_ecto to your dependencies:
def deps do
[
{:adk_ex, "~> 0.1"},
{:adk_ex_ecto, "~> 1.0"},
{:ecto_sqlite3, "~> 0.17"}, # or {:postgrex, "~> 0.19"} for PostgreSQL
]
endAdd a migration to your project that creates the 4 ADK tables:
defmodule MyApp.Repo.Migrations.CreateADKTables do
use Ecto.Migration
def change do
ADKExEcto.Migration.up()
end
endmix ecto.migratePass session_module: ADKExEcto.SessionService and your Repo as session_service to the Runner:
{:ok, runner} = ADK.Runner.new(
app_name: "my_app",
root_agent: agent,
session_service: MyApp.Repo,
session_module: ADKExEcto.SessionService
)The migration creates 4 tables matching the Go ADK's database session schema:
| Table | Primary Key | Purpose |
|---|---|---|
adk_sessions |
(app_name, user_id, id) |
Session records with state |
adk_events |
(id, app_name, user_id, session_id) |
Event history with content and actions |
adk_app_states |
(app_name) |
Cross-session app-level state |
adk_user_states |
(app_name, user_id) |
Cross-session user-level state |
State keys are routed by prefix (matching ADK.Session.InMemory behaviour):
| Prefix | Storage | Shared? |
|---|---|---|
| (none) | adk_sessions.state |
Session-local |
app: |
adk_app_states.state |
All users/sessions for app |
user: |
adk_user_states.state |
All sessions for user |
temp: |
Not persisted | Current invocation only |
| Module | Purpose |
|---|---|
ADKExEcto.SessionService |
Implements ADK.Session.Service via Ecto |
ADKExEcto.Migration |
Migration helper (up/0, down/0) |
ADKExEcto.Schemas.Session |
Ecto schema for adk_sessions |
ADKExEcto.Schemas.Event |
Ecto schema for adk_events |
ADKExEcto.Schemas.AppState |
Ecto schema for adk_app_states |
ADKExEcto.Schemas.UserState |
Ecto schema for adk_user_states |
mix deps.get
mix test # 21 tests
mix credo # Static analysis
mix dialyzer # Type checkingMIT