claude/agent/actor

Values

pub fn run_with_events(
  config: config.AgentConfig,
  prompt: String,
  on_event: fn(agent.AgentEvent) -> Nil,
) -> Result(agent.AgentResult, agent.AgentError)

Run the agent loop, calling the provided callback with events at each step.

This is a synchronous function that blocks until the agent completes. The on_event callback is invoked at each notable step, giving the caller visibility into the agent’s progress.

Example

actor.run_with_events(config, "Hello", fn(event) {
  case event {
    agent.Started(id) -> io.println("Started: " <> id)
    agent.Done(result) -> io.println("Done!")
    _ -> Nil
  }
})
pub fn start(
  config: config.AgentConfig,
  prompt: String,
  caller: process.Subject(agent.AgentEvent),
) -> process.Pid

Start an agent in a new BEAM process, sending events to the given subject.

The agent runs asynchronously in a spawned process. Events are sent to the caller’s subject as they occur, so the caller can receive them from their mailbox.

Returns the Pid of the spawned agent process.

Example

let events = process.new_subject()
let pid = actor.start(config, "Hello", events)

// Receive events from the agent
case process.receive(events, 30_000) {
  Ok(agent.Started(id)) -> io.println("Agent started: " <> id)
  Ok(agent.Done(result)) -> io.println("Agent done!")
  _ -> io.println("Timeout or other event")
}
Search Document