Jido.Agent.Server (Jido v1.1.0-rc)

View Source

GenServer implementation for managing agent processes.

This server handles the lifecycle and runtime execution of agents, including:

  • Agent initialization and startup
  • Signal processing and routing
  • State management and transitions
  • Child process supervision
  • Graceful shutdown

The server can be started in different modes (:auto or :manual) and supports both synchronous (call) and asynchronous (cast) signal handling.

Summary

Functions

Sends a synchronous signal to an agent and waits for the response.

Sends an asynchronous signal to an agent.

Returns a child specification for starting the server under a supervisor.

Starts a new agent server process.

Gets the current state of an agent.

Returns a via tuple for process registration.

Types

start_option()

@type start_option() ::
  {:id, String.t()}
  | {:agent, module() | struct()}
  | {:initial_state, map()}
  | {:registry, module()}
  | {:mode, :auto | :manual}
  | {:dispatch, pid() | {module(), term()}}
  | {:log_level, Logger.level()}
  | {:max_queue_size, non_neg_integer()}

Functions

call(agent, signal, timeout \\ 5000)

Sends a synchronous signal to an agent and waits for the response.

cast(agent, signal)

@spec cast(pid() | atom() | {atom(), node()}, Jido.Signal.t()) ::
  {:ok, String.t()} | {:error, term()}

Sends an asynchronous signal to an agent.

child_spec(init_arg)

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

Returns a child specification for starting the server under a supervisor.

dbug(_, _ \\ [])

(macro)

error(_, _ \\ [])

(macro)

start_link(opts)

@spec start_link([start_option()]) :: GenServer.on_start()

Starts a new agent server process.

Options

  • :id - Unique identifier for the agent (auto-generated if not provided)
  • :agent - Agent module or struct to be managed
  • :initial_state - Initial state map for the agent
  • :registry - Registry for process registration
  • :mode - Operation mode (:auto or :manual)
  • :output - Output destination for agent signals
  • :log_level - Logging level
  • :max_queue_size - Maximum size of pending signals queue

Returns

  • {:ok, pid} - Successfully started server process
  • {:error, reason} - Failed to start server

state(agent)

@spec state(pid() | atom() | {atom(), node()}) ::
  {:ok, Jido.Agent.Server.State.t()} | {:error, term()}

Gets the current state of an agent.

via_tuple(name, registry)

@spec via_tuple(String.t(), module()) :: {:via, Registry, {module(), String.t()}}

Returns a via tuple for process registration.