ExAgent.Memory.Postgres (ExAgent v3.0.0)

View Source

A durable ExAgent.Memory backend on PostgreSQL, through the host's Ecto.Repo (add ecto_sql and postgrex to your app, as for ExAgent.Store.Postgres).

Stability — Stable.

ExAgent.Memory.tool({ExAgent.Memory.Postgres, MyApp.Repo}, scope: "user:42")

Install the table with a pinned ExAgent.Migration in the host.

Each scope is one row: scope (primary key), version, data (the files as JSON text) and updated_at. Versions come from a sequence, so they are never reused, and every write is a single conditional statement. The table is exagent_memory by default; choose another with {ExAgent.Memory.Postgres, {MyApp.Repo, table: "agent_memory"}} (at most 48 characters, letters, digits and underscores) and pass memory_table: "agent_memory" to the unified migration.

Reads and writes disable Ecto query logging and query telemetry because parameters and results can contain the scope and its files. Count tool operations with [:exagent, :memory, :command].

Summary

Functions

Create the memory table and its version sequence for existing host migrations. Kept through 3.x so existing 2.x host migrations can be replayed.

Functions

migrate(repo, table \\ "exagent_memory")

This function is deprecated. Use ExAgent.Migration for new migrations. Removal in 4.0..
@spec migrate(module(), String.t()) :: :ok | {:error, term()}

Create the memory table and its version sequence for existing host migrations. Kept through 3.x so existing 2.x host migrations can be replayed.

Call this from a versioned Ecto migration with migration locking enabled, or from a single release task before starting the replicas. If several nodes first create the same objects concurrently, PostgreSQL can return unique_violation. Once creation has committed, repeating the call is safe.