Jido.AgentServer.State
(Jido v2.2.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.
Attaches a parent reference to the runtime and agent state.
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.
Returns recent debug events, newest first.
Increments the error count.
Transitions the runtime into an orphaned state, preserving the former parent.
Checks if the queue is empty.
Returns the current queue length.
Records a debug event if debug mode is enabled.
Removes a child by tag.
Removes a child by PID.
Enables or disables debug mode at runtime.
Sets the status.
Updates the agent in state.
Types
@type status() :: :initializing | :idle | :processing | :stopping
@type t() :: %Jido.AgentServer.State{ agent: any(), agent_module: atom(), children: map(), completion_waiters: map(), cron_jobs: map(), cron_monitor_refs: map(), cron_monitors: map(), cron_restart_attempts: map(), cron_restart_timer_refs: map(), cron_restart_timers: map(), cron_runtime_specs: map(), cron_specs: map(), debug: boolean(), debug_events: [any()], debug_max_events: integer(), default_dispatch: nil | any(), deferred_async_signals: any(), error_count: integer(), error_policy: any(), id: binary(), jido: atom(), lifecycle: any(), max_queue_size: integer(), metrics: map(), on_parent_death: atom(), orphaned_from: nil | any(), parent: nil | any(), partition: nil | any(), processing: boolean(), queue: any(), registry: atom(), restored_from_storage: boolean(), signal_call_inflight: nil | any(), signal_call_queue: any(), signal_router: nil | any(), skip_schedules: boolean(), spawn_fun: nil | any(), status: atom() }
Functions
@spec add_child(t(), term(), Jido.AgentServer.ChildInfo.t()) :: t()
Adds a child to the children map.
@spec attach_parent(t(), Jido.AgentServer.ParentRef.t()) :: t()
Attaches a parent reference to the runtime and agent state.
@spec dequeue(t()) :: {{:value, {Jido.Signal.t(), struct()}}, t()} | {:empty, t()}
Dequeues the next directive for processing.
@spec enqueue(t(), Jido.Signal.t(), struct()) :: {:ok, t()} | {:error, :queue_overflow}
Enqueues a directive with its triggering signal for later execution.
@spec enqueue_all(t(), Jido.Signal.t(), [struct()]) :: {:ok, t()} | {:error, :queue_overflow}
Enqueues multiple directives from a single signal.
@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.
@spec get_child(t(), term()) :: Jido.AgentServer.ChildInfo.t() | nil
Gets a child by tag.
Returns recent debug events, newest first.
Options
:limit- Maximum number of events to return (default: all)
Increments the error count.
Transitions the runtime into an orphaned state, preserving the former parent.
Checks if the queue is empty.
@spec queue_length(t()) :: non_neg_integer()
Returns the current queue length.
Records a debug event if debug mode is enabled.
Events are stored in a ring buffer (max 500 entries). Each event includes a monotonic timestamp for relative timing.
Removes a child by tag.
Removes a child by PID.
Enables or disables debug mode at runtime.
Sets the status.
Updates the agent in state.