Behaviour for persisting ExAgent.Server.Snapshots (and, in Phase 3, session
snapshots).
ExAgent never owns a database: the store is a pluggable behaviour. The default
ExAgent.Store.ETS keeps snapshots in an in-process ETS table (dev/test); a
future ExAgent.Store.Postgres will implement the same contract for durable,
multi-node persistence.
The contract (what a store must do)
save_agent_snapshot/2— persist a snapshot, keyed by itsagent_id.load_agent_snapshot/2— fetch a snapshot byagent_id.list_agent_snapshots/1— list all persisted agent snapshots.delete_agent_snapshot/2— remove a snapshot byagent_id.save_session_snapshot/2/load_session_snapshot/2— the session counterparts (used byExAgent.Sessionfrom Phase 3).
Portability rule
Implementations MUST round-trip snapshots through a portable encoding (JSON
for the ETS impl), never term_to_binary of arbitrary terms. This guarantees
the same data can land in Postgres later without redesign, and refuses to
persist non-serializable state (pids, secrets, closures).
A store is referenced as {module, config} where config is opaque to
ExAgent (e.g. an ETS table name). normalize/1 turns friendly forms into that
tuple; nil means "no store" (the default — one-shot friendly).
Summary
Callbacks
Delete an agent snapshot by agent_id.
Delete a session snapshot by session_id (Phase 3).
List every persisted agent snapshot.
Load an agent snapshot by agent_id, or {:error, :not_found}.
Load a session snapshot by session_id (Phase 3).
Persist an agent snapshot, keyed by its agent_id.
Persist a session snapshot, keyed by session_id (Phase 3).
Functions
Delete an agent snapshot via the resolved tuple.
List agent snapshots via the resolved tuple.
Load an agent snapshot via the resolved tuple.
Resolve a store option into a {module, config} tuple, or nil for "no store".
Persist an agent snapshot via the resolved {module, config} tuple.
Types
@type agent_snapshot() :: ExAgent.Server.Snapshot.t()
@type session_snapshot() :: term()
Callbacks
Delete an agent snapshot by agent_id.
Delete a session snapshot by session_id (Phase 3).
@callback list_agent_snapshots(config :: term()) :: [agent_snapshot()]
List every persisted agent snapshot.
@callback load_agent_snapshot(config :: term(), agent_id :: String.t()) :: {:ok, agent_snapshot()} | {:error, :not_found | term()}
Load an agent snapshot by agent_id, or {:error, :not_found}.
@callback load_session_snapshot(config :: term(), session_id :: String.t()) :: {:ok, session_snapshot()} | {:error, :not_found | term()}
Load a session snapshot by session_id (Phase 3).
@callback save_agent_snapshot(config :: term(), snapshot :: agent_snapshot()) :: :ok | {:error, term()}
Persist an agent snapshot, keyed by its agent_id.
@callback save_session_snapshot(config :: term(), snapshot :: session_snapshot()) :: :ok | {:error, term()}
Persist a session snapshot, keyed by session_id (Phase 3).
Functions
Delete an agent snapshot via the resolved tuple.
@spec list_agent_snapshots({module(), term()}) :: [ExAgent.Server.Snapshot.t()]
List agent snapshots via the resolved tuple.
@spec load_agent_snapshot( {module(), term()}, String.t() ) :: {:ok, ExAgent.Server.Snapshot.t()} | {:error, term()}
Load an agent snapshot via the resolved tuple.
Resolve a store option into a {module, config} tuple, or nil for "no store".
nil→nil(no persistence — default).:ets→{ExAgent.Store.ETS, ExAgent.Store.ETS}(default table).{mod, cfg}→ as-is.mod→{mod, []}.
@spec save_agent_snapshot( {module(), term()}, ExAgent.Server.Snapshot.t() ) :: :ok | {:error, term()}
Persist an agent snapshot via the resolved {module, config} tuple.