Jido.AI.Actions.Reasoning.Infer (Jido AI v2.1.0)

View Source

A Jido.Action for drawing logical inferences from given premises.

This action uses ReqLLM with a specialized system prompt for logical reasoning, helping to draw valid conclusions from given information.

Parameters

  • model (optional) - Model alias (e.g., :reasoning) or direct spec
  • premises (required) - The given facts/information as premises
  • question (required) - What to infer from the premises
  • context (optional) - Additional background information
  • max_tokens (optional) - Maximum tokens to generate (default: 2048)
  • temperature (optional) - Sampling temperature (default: 0.3)
  • timeout (optional) - Request timeout in milliseconds

Examples

# Basic inference
{:ok, result} = Jido.Exec.run(Jido.AI.Actions.Reasoning.Infer, %{
  premises: "All cats are mammals. Fluffy is a cat.",
  question: "Is Fluffy a mammal?"
})

# With context
{:ok, result} = Jido.Exec.run(Jido.AI.Actions.Reasoning.Infer, %{
  premises: "If it rains, the ground gets wet. The ground is wet.",
  question: "Can we conclude that it rained?",
  context: "Consider that sprinklers can also make the ground wet."
})

Summary

Functions

Returns the Action metadata. Alias for to_json/0.

Returns the category of the Action.

Returns the description of the Action.

Returns the name of the Action.

Lifecycle hook called after Action execution.

Lifecycle hook called after output validation.

Lifecycle hook called after parameter validation.

Lifecycle hook called before output validation.

Lifecycle hook called before parameter validation.

Lifecycle hook called when an error occurs.

Returns the output schema of the Action.

Executes the infer action.

Returns the input schema of the Action.

Returns the tags associated with the Action.

Returns the Action metadata as a JSON-serializable map.

Converts the Action to an LLM-compatible tool format.

Validates the output result for the Action.

Validates the input parameters for the Action.

Returns the version of the Action.

Functions

__action_metadata__()

Returns the Action metadata. Alias for to_json/0.

category()

Returns the category of the Action.

description()

Returns the description of the Action.

name()

Returns the name of the Action.

on_after_run(result)

@spec on_after_run({:ok, map()} | {:error, any()}) :: {:ok, map()} | {:error, any()}

Lifecycle hook called after Action execution.

on_after_validate_output(output)

@spec on_after_validate_output(map()) :: {:ok, map()} | {:error, any()}

Lifecycle hook called after output validation.

on_after_validate_params(params)

@spec on_after_validate_params(map()) :: {:ok, map()} | {:error, any()}

Lifecycle hook called after parameter validation.

on_before_validate_output(output)

@spec on_before_validate_output(map()) :: {:ok, map()} | {:error, any()}

Lifecycle hook called before output validation.

on_before_validate_params(params)

@spec on_before_validate_params(map()) :: {:ok, map()} | {:error, any()}

Lifecycle hook called before parameter validation.

on_error(failed_params, error, context, opts)

@spec on_error(map(), any(), map(), keyword()) :: {:ok, map()} | {:error, any()}

Lifecycle hook called when an error occurs.

output_schema()

Returns the output schema of the Action.

run(params, context)

@spec run(map(), map()) :: {:ok, map()} | {:ok, map(), any()} | {:error, any()}

Executes the infer action.

Returns

  • {:ok, result} - Successful response with result, reasoning, confidence, model, and usage keys
  • {:error, reason} - Error from ReqLLM or validation

Result Format

%{
  result: "The inferred conclusion",
  reasoning: "Step-by-step reasoning chain",
  confidence: 0.9,
  model: "anthropic:claude-sonnet-4-20250514",
  usage: %{...}
}

schema()

Returns the input schema of the Action.

tags()

Returns the tags associated with the Action.

to_json()

Returns the Action metadata as a JSON-serializable map.

to_tool()

Converts the Action to an LLM-compatible tool format.

validate_output(output)

@spec validate_output(map()) :: {:ok, map()} | {:error, String.t()}

Validates the output result for the Action.

Examples

iex> defmodule ExampleAction do
...>   use Jido.Action,
...>     name: "example_action",
...>     output_schema: [
...>       result: [type: :string, required: true]
...>     ]
...> end
...> ExampleAction.validate_output(%{result: "test", extra: "ignored"})
{:ok, %{result: "test", extra: "ignored"}}

iex> ExampleAction.validate_output(%{extra: "ignored"})
{:error, "Invalid output for Action: Required key :result not found"}

validate_params(params)

@spec validate_params(map()) :: {:ok, map()} | {:error, String.t()}

Validates the input parameters for the Action.

Examples

iex> defmodule ExampleAction do
...>   use Jido.Action,
...>     name: "example_action",
...>     schema: [
...>       input: [type: :string, required: true]
...>     ]
...> end
...> ExampleAction.validate_params(%{input: "test"})
{:ok, %{input: "test"}}

iex> ExampleAction.validate_params(%{})
{:error, "Invalid parameters for Action: Required key :input not found"}

vsn()

Returns the version of the Action.