A durable ExAgent.Store backed by PostgreSQL, for resume across crashes and
multiple nodes.
Snapshots are stored as JSON (the same strict serialization ExAgent.Store.ETS
uses), never raw Erlang terms — so nothing non-serializable (pids, secrets,
closures) can land in the database. The store is DB-free by default in the
rest of exAgent: this module needs ecto_sql + postgrex, declared as optional
dependencies that a host app adds when it wants a durable store.
Wiring
The store takes the host app's Ecto.Repo as its config (the host owns the
database connection — exAgent never does):
# 1) add deps in your app:
# {:ecto_sql, "~> 3.0"}, {:postgrex, "~> 0.19"}
# 2) create the table once (migration or at boot):
ExAgent.Store.Postgres.migrate(MyApp.Repo)
# 3) use it:
ExAgent.AgentSupervisor.start_agent(
agent: agent_template,
agent_id: "dm",
store: {ExAgent.Store.Postgres, MyApp.Repo}
)The snapshots table is exagent_snapshots by default; override it with
{ExAgent.Store.Postgres, {MyApp.Repo, table: "my_snapshots"}}.
Why not own the database?
A library shouldn't own your connection pool, credentials or migrations. The repo comes from your app; exAgent only issues parameterized SQL against one table.
Summary
Functions
Create the snapshots table (idempotent). Run this once from a migration or at
boot, against your app's repo. Columns: key (PK), data (the JSON text),
updated_at.