View Source Jido.Agent.Worker (Jido v1.0.0-rc.1)

A GenServer implementation for managing Jido agents with centralized command handling and pluggable communication.

This module provides a robust worker process for Jido agents, handling:

  • Agent state management
  • Command processing and queueing
  • PubSub-based communication
  • Metrics and signal emission

It supports various commands like replan, pause, resume, reset, and stop, and manages the agent's lifecycle through different states (idle, planning, running, paused).

Summary

Functions

Triggers the agent to act based on its current state.

Returns a child specification for starting the Agent Worker under a supervisor.

Sends a command to the agent.

Updates the agent's attributes.

Starts a new Agent Worker process.

Types

agent()

@type agent() :: Jido.Agent.t()

command()

@type command() :: :replan | :pause | :resume | :reset | :stop

topic()

@type topic() :: String.t()

Functions

act(server, attrs)

@spec act(GenServer.server(), map()) :: :ok

Triggers the agent to act based on its current state.

Parameters

  • server - The GenServer reference
  • attrs - A map of additional attributes for the action

Returns

  • :ok

child_spec(init_arg)

@spec child_spec(keyword()) :: Supervisor.child_spec()

Returns a child specification for starting the Agent Worker under a supervisor.

cmd(server, command, args \\ nil)

@spec cmd(GenServer.server(), command(), term()) ::
  {:ok, Jido.Agent.Worker.State.t()} | {:error, term()}

Sends a command to the agent.

Parameters

  • server - The GenServer reference
  • command - The command to execute
  • args - Additional arguments for the command (optional)

Returns

  • {:ok, State.t()} on success
  • {:error, term()} on failure

set(server, attrs)

@spec set(GenServer.server(), map()) :: :ok

Updates the agent's attributes.

Parameters

  • server - The GenServer reference
  • attrs - A map of attributes to update

Returns

  • :ok

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Starts a new Agent Worker process.

Options

  • :agent - The Jido agent to manage (required)
  • :name - The name to register the process under (optional, defaults to agent ID)
  • :pubsub - The PubSub module to use for communication (required)

Returns

  • {:ok, pid} on success
  • {:error, reason} on failure