ExAgent.Tool.ResultStore.Postgres (ExAgent v3.0.0)

View Source

PostgreSQL storage for offloaded tool results, using the host's Ecto Repo.

Stability — Candidate.

alias ExAgent.Tool.{OutputLimit, ResultStore.Postgres}
handle = Postgres.new(MyApp.Repo, scope: "tenant-42")
OutputLimit.new(offload: {Postgres, handle})

A stable, host-selected scope corresponds to one ETS store. All writers for a scope should use the same limits. A write evicts the oldest entries across its runs until both quotas fit. Reads require the original scope, run and reference and never extend expiry. The database clock determines TTL.

Create the table with a pinned ExAgent.Migration in the host. Schedule cleanup_expired/2 on the host to reclaim idle scopes. The adapter uses the host's pool at READ COMMITTED isolation and starts no processes. Reading one result materializes its full text for the caller.

Summary

Functions

Remove up to 1–1000 expired rows across the Repo's scopes, including abandoned scopes.

Remove up to 1–1000 results of a host-confirmed orphan run within this handle's scope.

Standalone tool result schema SQL. Rolling down deletes all stored results.

Build a handle for a required nonempty host :scope. Defaults are 8 MiB of content, 256 entries and a five-minute TTL.

Types

t()

@opaque t()

Functions

cleanup_expired(repo, limit \\ 100)

@spec cleanup_expired(module(), pos_integer()) ::
  {:ok, non_neg_integer()} | {:error, :unavailable}

Remove up to 1–1000 expired rows across the Repo's scopes, including abandoned scopes.

delete_run(postgres, run, limit \\ 100)

@spec delete_run(t(), String.t(), pos_integer()) ::
  {:ok, non_neg_integer()} | {:error, :unavailable}

Remove up to 1–1000 results of a host-confirmed orphan run within this handle's scope.

migration_sql(atom, list)

This function is deprecated. Use ExAgent.Migration for new migrations. Removal in 4.0..
@spec migration_sql(:up | :down, keyword()) :: [String.t()]

Standalone tool result schema SQL. Rolling down deletes all stored results.

new(repo, opts)

@spec new(module(), keyword()) :: t()

Build a handle for a required nonempty host :scope. Defaults are 8 MiB of content, 256 entries and a five-minute TTL.