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
@type agent() :: Jido.Agent.t()
@type command() :: :replan | :pause | :resume | :reset | :stop
@type topic() :: String.t()
Functions
@spec act(GenServer.server(), map()) :: :ok
Triggers the agent to act based on its current state.
Parameters
server
- The GenServer referenceattrs
- A map of additional attributes for the action
Returns
:ok
@spec child_spec(keyword()) :: Supervisor.child_spec()
Returns a child specification for starting the Agent Worker under a supervisor.
@spec cmd(GenServer.server(), command(), term()) :: {:ok, Jido.Agent.Worker.State.t()} | {:error, term()}
Sends a command to the agent.
Parameters
server
- The GenServer referencecommand
- The command to executeargs
- Additional arguments for the command (optional)
Returns
{:ok, State.t()}
on success{:error, term()}
on failure
@spec set(GenServer.server(), map()) :: :ok
Updates the agent's attributes.
Parameters
server
- The GenServer referenceattrs
- A map of attributes to update
Returns
:ok
@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