Jido.AI.Reasoning.ReAct.State (Jido AI v2.3.0)

Copy Markdown View Source

Runtime state for a single ReAct run.

Summary

Functions

Advances the event sequence counter to seq when it is ahead of the current value, leaving it untouched otherwise.

Increments the event sequence counter and returns {state, next_seq}.

Clears all pending tool calls.

Clears streaming accumulators before a new LLM turn starts.

Returns elapsed runtime in milliseconds.

Restores state from a minimal checkpoint map.

Increments the reasoning iteration counter.

Merges usage counters into existing state usage map.

Returns the minimal serializable map required to resume execution.

Creates initial runtime state for a new query.

Stores terminal error value.

Stores the current LLM call id.

Stores the latest provider response id for multi-turn continuation.

Stores structured output metadata.

Replaces pending tool calls.

Stores terminal result value.

Sets runtime status.

Returns the Zoi schema used to validate ReAct runtime state.

Types

t()

@type t() :: %Jido.AI.Reasoning.ReAct.State{
  active_tools: map(),
  context: any(),
  error: nil | nil | any(),
  iteration: integer(),
  llm_call_id: nil | nil | binary(),
  llm_response_id: nil | nil | binary(),
  output: map(),
  pending_tool_calls: [
    %Jido.AI.Reasoning.ReAct.PendingToolCall{
      arguments: map(),
      attempts: integer(),
      duration_ms: nil | integer(),
      id: binary(),
      name: binary(),
      result: nil | any(),
      status: atom()
    }
  ],
  prev_tool_signature: nil | nil | any(),
  request_id: binary(),
  result: nil | nil | any(),
  run_id: binary(),
  seq: integer(),
  started_at_ms: integer(),
  status: atom(),
  streaming_text: binary(),
  streaming_thinking: binary(),
  updated_at_ms: integer(),
  usage: map(),
  version: integer()
}

Functions

adopt_seq(state, seq)

@spec adopt_seq(t(), integer() | nil) :: t()

Advances the event sequence counter to seq when it is ahead of the current value, leaving it untouched otherwise.

Used to reconcile sequence numbers allocated out-of-band by the tool-execution heartbeat (which runs in a separate process while the runner is blocked inside Task.async_stream). Adopting the heartbeat's final seq guarantees the next normal event the runner emits is strictly greater than every keepalive, preserving the monotonic-and-unique seq invariant.

bump_seq(state)

@spec bump_seq(t()) :: {t(), pos_integer()}

Increments the event sequence counter and returns {state, next_seq}.

clear_pending_tools(state)

@spec clear_pending_tools(t()) :: t()

Clears all pending tool calls.

clear_streaming(state)

@spec clear_streaming(t()) :: t()

Clears streaming accumulators before a new LLM turn starts.

duration_ms(state)

@spec duration_ms(t()) :: non_neg_integer()

Returns elapsed runtime in milliseconds.

from_checkpoint_map(map)

@spec from_checkpoint_map(map()) :: {:ok, t()} | {:error, term()}

Restores state from a minimal checkpoint map.

inc_iteration(state)

@spec inc_iteration(t()) :: t()

Increments the reasoning iteration counter.

merge_usage(state, usage)

@spec merge_usage(t(), map() | nil) :: t()

Merges usage counters into existing state usage map.

minimal_checkpoint_map(state)

@spec minimal_checkpoint_map(t()) :: map()

Returns the minimal serializable map required to resume execution.

new(query, system_prompt, opts \\ [])

@spec new(String.t(), String.t() | nil, keyword()) :: t()

Creates initial runtime state for a new query.

put_error(state, error)

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

Stores terminal error value.

put_llm_call_id(state, call_id)

@spec put_llm_call_id(t(), String.t() | nil) :: t()

Stores the current LLM call id.

put_llm_response_id(state, response_id)

@spec put_llm_response_id(t(), String.t() | nil) :: t()

Stores the latest provider response id for multi-turn continuation.

put_output(state, output)

@spec put_output(t(), map()) :: t()

Stores structured output metadata.

put_pending_tools(state, pending)

@spec put_pending_tools(t(), [Jido.AI.Reasoning.ReAct.PendingToolCall.t()]) :: t()

Replaces pending tool calls.

put_result(state, result)

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

Stores terminal result value.

put_status(state, status)

@spec put_status(t(), atom()) :: t()

Sets runtime status.

schema()

@spec schema() :: term()

Returns the Zoi schema used to validate ReAct runtime state.