ExAgent.AgentSupervisor (ExAgent v0.5.0)

Copy Markdown View Source

A DynamicSupervisor that owns ExAgent.Server processes.

Each long-lived agent is a supervised GenServer started under this supervisor, so a crash (or an explicit stop) is isolated from the rest of the application and the agent can be restarted by its host app. Agents are looked up by name via the same :name/:agent_id passed to ExAgent.Server.start_link/1.

Example

{:ok, pid} = ExAgent.AgentSupervisor.start_agent(agent: my_agent, name: :dm)
ExAgent.Server.chat(:dm, "Roll for initiative")

Summary

Functions

Returns a specification to start this module under a supervisor.

Start an ExAgent.Server under this supervisor. opts are forwarded to ExAgent.Server.start_link/1. Returns {:ok, pid} or {:error, _}.

Stop a supervised agent by pid. Returns :ok or {:error, _}.

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_agent(opts)

@spec start_agent(keyword()) :: DynamicSupervisor.on_start_child()

Start an ExAgent.Server under this supervisor. opts are forwarded to ExAgent.Server.start_link/1. Returns {:ok, pid} or {:error, _}.

stop_agent(pid)

@spec stop_agent(pid()) :: :ok | {:error, :not_found}

Stop a supervised agent by pid. Returns :ok or {:error, _}.