Jido.AgentServer.State (Jido v2.0.0-rc.0)

View Source

Internal state for AgentServer GenServer.

Internal Module

This module is internal to the AgentServer implementation. Its API may change without notice. Use Jido.AgentServer.state/1 to retrieve state.

This struct holds all runtime state for an agent instance including the agent itself, directive queue, hierarchy tracking, and configuration.

Summary

Functions

Adds a child to the children map.

Dequeues the next directive for processing.

Enqueues a directive with its triggering signal for later execution.

Enqueues multiple directives from a single signal.

Creates a new State from validated Options, agent module, and agent struct.

Gets a child by tag.

Increments the error count.

Checks if the queue is empty.

Returns the current queue length.

Removes a child by tag.

Removes a child by PID.

Sets the status.

Updates the agent in state.

Types

status()

@type status() :: :initializing | :idle | :processing | :stopping

t()

@type t() :: %Jido.AgentServer.State{
  agent: any(),
  agent_module: atom(),
  children: map(),
  completion_waiters: map(),
  cron_jobs: map(),
  default_dispatch: any(),
  error_count: integer(),
  error_policy: any(),
  id: binary(),
  jido: atom(),
  lifecycle: any(),
  max_queue_size: integer(),
  metrics: map(),
  on_parent_death: atom(),
  parent: any(),
  processing: boolean(),
  queue: any(),
  registry: atom(),
  signal_router: any(),
  skip_schedules: boolean(),
  spawn_fun: any(),
  status: atom()
}

Functions

add_child(state, tag, child)

@spec add_child(t(), term(), Jido.AgentServer.ChildInfo.t()) :: t()

Adds a child to the children map.

dequeue(state)

@spec dequeue(t()) :: {{:value, {Jido.Signal.t(), struct()}}, t()} | {:empty, t()}

Dequeues the next directive for processing.

enqueue(state, signal, directive)

@spec enqueue(t(), Jido.Signal.t(), struct()) ::
  {:ok, t()} | {:error, :queue_overflow}

Enqueues a directive with its triggering signal for later execution.

enqueue_all(state, signal, list)

@spec enqueue_all(t(), Jido.Signal.t(), [struct()]) ::
  {:ok, t()} | {:error, :queue_overflow}

Enqueues multiple directives from a single signal.

from_options(opts, agent_module, agent)

@spec from_options(Jido.AgentServer.Options.t(), module(), struct()) ::
  {:ok, t()} | {:error, term()}

Creates a new State from validated Options, agent module, and agent struct.

If a parent reference is provided, it's injected into the agent's state as agent.state.__parent__ so agents can use Directive.emit_to_parent/3.

get_child(state, tag)

@spec get_child(t(), term()) :: Jido.AgentServer.ChildInfo.t() | nil

Gets a child by tag.

increment_error_count(state)

@spec increment_error_count(t()) :: t()

Increments the error count.

queue_empty?(state)

@spec queue_empty?(t()) :: boolean()

Checks if the queue is empty.

queue_length(state)

@spec queue_length(t()) :: non_neg_integer()

Returns the current queue length.

remove_child(state, tag)

@spec remove_child(t(), term()) :: t()

Removes a child by tag.

remove_child_by_pid(state, pid)

@spec remove_child_by_pid(t(), pid()) :: {term() | nil, t()}

Removes a child by PID.

set_status(state, status)

@spec set_status(t(), status()) :: t()

Sets the status.

update_agent(state, agent)

@spec update_agent(
  t(),
  struct()
) :: t()

Updates the agent in state.