LegionWeb. AgentTracker. Postgres
(LegionWeb v0.5.0)
View Source
Tracks Legion agents from a PostgreSQL-backed Legion.Store.
This tracker rebuilds the dashboard from persisted conversations, so agents remain visible after their processes or the application stop. It also listens for PostgreSQL notifications and publishes live dashboard updates without polling.
Usage
Define a Legion.Store.Postgres store and configure it for Legion:
defmodule MyApp.AgentStore do
use Legion.Store.Postgres, repo: MyApp.Repo
end
config :legion, :store, MyApp.AgentStoreConfigure LegionWeb to use it:
config :legion_web, :agent_tracker,
{LegionWeb.AgentTracker.Postgres, store: MyApp.AgentStore}Requirements
The configured store must implement Legion.Store and expose the
__repo__/0 and __table__/0 functions generated by
Legion.Store.Postgres. The host application must provide an Ecto repo
backed by Ecto.Adapters.Postgres and include Postgrex.
Tracking behavior
The tracker loads up to 100 persisted conversations. It resolves each
agent_id through Legion.lookup/1 to distinguish live agents from stopped
ones, and reconstructs durable user, assistant, eval-result, and error events
from the stored conversation.
PostgreSQL notifications reload the affected conversation and broadcast its current status and usage. Historical events are loaded when an agent is opened; later notifications broadcast only newly appended events.
Usage comes from the store's usage column, which Legion appends to at the
end of each turn, so usage updates arrive per turn rather than per request.
Summary
Functions
Returns a specification to start this module under a supervisor.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.