pig/supervisor

Supervised agent — wraps agent in OTP static supervisor.

The easy path: start_supervised(config) gives you an agent managed by a OneForOne supervisor. Advanced users can still use pig.start(config) for standalone agents.

Types

Handle to a supervised agent.

Wraps the agent’s Subject and the supervisor’s Pid. Use run/run_with_timeout to send prompts, stop to tear down the supervision tree.

pub type SupervisedAgent {
  SupervisedAgent(
    subject: process.Subject(runtime.RuntimeMsg),
    sup_pid: process.Pid,
  )
}

Constructors

Values

pub fn run(
  sup: SupervisedAgent,
  prompt: String,
) -> Result(message.Message, error.AiError)

Run a prompt against the supervised agent with a 120-second timeout.

pub fn run_with_timeout(
  sup: SupervisedAgent,
  prompt: String,
  timeout_ms: Int,
) -> Result(message.Message, error.AiError)

Run a prompt against the supervised agent with an explicit timeout.

pub fn start_supervised(
  agent_config: state.AgentConfig,
  consumer_specs: List(consumer_spec.ConsumerSpec),
) -> Result(SupervisedAgent, actor.StartError)

Start a supervised agent from an AgentConfig and consumer specs.

Spawns a nested OneForOne static supervisor containing:

  • An event subtree (dispatcher + consumers)
  • The agent actor

The dispatcher and agent are named so Subjects can be recovered after supervisor start. Returns a SupervisedAgent handle.

pub fn stop(sup: SupervisedAgent) -> Nil

Stop the supervised agent.

Sends an exit signal to the supervisor process. OTP cascades shutdown to the agent child process.

Search Document