Jido.AI.Reasoning.AlgorithmOfThoughts.Machine (Jido AI v2.2.0)

Copy Markdown View Source

Pure state machine for Algorithm-of-Thoughts (AoT) reasoning.

AoT in this implementation is intentionally single-query: one LLM generation pass that demonstrates algorithmic search behavior in-context and extracts a final answer.

Summary

Types

External status used by strategy snapshots

Internal machine status (string) - required by Fsmx

t()

Functions

Returns the default AoT system prompt for a profile/search-style pair.

Extracts an explicit final answer line from model output text.

Rebuilds a machine struct from strategy state map data.

Generates a unique call id for AoT LLM stream requests.

Builds a new AoT machine with configurable strategy options.

Parses free-form AoT response text into the structured AoT result shape.

Converts machine state into strategy-storable map form.

Applies a machine event and returns {updated_machine, directives}.

Types

directive()

@type directive() ::
  {:call_llm_stream, String.t(), list()}
  | {:request_error, String.t(), atom(), String.t()}

external_status()

@type external_status() :: :idle | :exploring | :completed | :error

External status used by strategy snapshots

internal_status()

@type internal_status() :: String.t()

Internal machine status (string) - required by Fsmx

msg()

@type msg() ::
  {:start, String.t(), String.t()}
  | {:llm_result, String.t(), term()}
  | {:llm_partial, String.t(), String.t(), atom()}

profile()

@type profile() :: :short | :standard | :long

search_style()

@type search_style() :: :dfs | :bfs

t()

@type t() :: %Jido.AI.Reasoning.AlgorithmOfThoughts.Machine{
  current_call_id: String.t() | nil,
  examples: [String.t()],
  max_tokens: pos_integer(),
  profile: profile(),
  prompt: String.t() | nil,
  require_explicit_answer: boolean(),
  result: map() | nil,
  search_style: search_style(),
  started_at: integer() | nil,
  status: internal_status(),
  streaming_text: String.t(),
  temperature: float(),
  termination_reason: termination_reason(),
  usage: usage()
}

termination_reason()

@type termination_reason() ::
  :success | :missing_explicit_answer | :no_solution | :error | nil

usage()

@type usage() :: %{
  optional(:input_tokens) => non_neg_integer(),
  optional(:output_tokens) => non_neg_integer(),
  optional(:total_tokens) => non_neg_integer()
}

Functions

before_transition(struct, from, to, state_field)

default_system_prompt(profile, search_style, examples \\ [])

@spec default_system_prompt(profile(), search_style(), [String.t()]) :: String.t()

Returns the default AoT system prompt for a profile/search-style pair.

extract_answer(text)

@spec extract_answer(String.t()) :: String.t() | nil

Extracts an explicit final answer line from model output text.

from_map(map)

@spec from_map(map()) :: t()

Rebuilds a machine struct from strategy state map data.

generate_call_id()

@spec generate_call_id() :: String.t()

Generates a unique call id for AoT LLM stream requests.

new(opts \\ [])

@spec new(keyword()) :: t()

Builds a new AoT machine with configurable strategy options.

parse_response(text, require_explicit_answer \\ true)

@spec parse_response(String.t(), boolean()) :: map()

Parses free-form AoT response text into the structured AoT result shape.

to_map(machine)

@spec to_map(t()) :: map()

Converts machine state into strategy-storable map form.

update(machine, msg, env \\ %{})

@spec update(t(), msg(), map()) :: {t(), [directive()]}

Applies a machine event and returns {updated_machine, directives}.