Jido.AI.Reasoning.Adaptive.Strategy (Jido AI v2.2.0)

Copy Markdown View Source

Adaptive execution strategy that automatically selects the best reasoning approach.

This strategy analyzes task characteristics and selects the most appropriate strategy (CoD, CoT, ReAct, AoT, ToT, GoT) for the given task. The strategy is re-evaluated when the previous reasoning completes and a new prompt arrives.

Overview

The Adaptive strategy:

  • Analyzes prompt complexity and task type
  • Selects the appropriate strategy based on heuristics
  • Delegates all operations to the selected strategy
  • Re-evaluates strategy when previous task completes
  • Supports manual override via configuration

Strategy Selection

Strategies are selected based on task type keywords and complexity:

Task Type Detection (highest priority)

  • Iterative Reasoning → TRM (Tiny-Recursive-Model)
    • Keywords: puzzle, solve, step-by-step, iterate, improve, refine, recursive
  • Synthesis → Graph-of-Thoughts (GoT)
    • Keywords: synthesize, combine, merge, integrate, relationships, perspectives
  • Tool use → ReAct
    • Keywords: search, find, calculate, execute, fetch
  • Exploration → Tree-of-Thoughts (ToT)
    • Keywords: analyze, explore, compare, evaluate, alternatives

Complexity-based Selection (fallback)

  • Simple tasks (score < 0.3) → Chain-of-Draft (CoD)
    • Direct questions, simple calculations, factual queries
  • Moderate tasks (0.3-0.7) → ReAct
    • Tasks requiring tool use, multi-step operations
  • Complex tasks (> 0.7) → Tree-of-Thoughts (ToT)
    • Puzzles, planning, creative writing, complex reasoning

Configuration

Configure via strategy options when defining your agent:

use Jido.Agent,
  name: "my_adaptive_agent",
  strategy: {
    Jido.AI.Reasoning.Adaptive.Strategy,
    model: "anthropic:claude-sonnet-4-20250514",
    default_strategy: :react,
    available_strategies: [:cod, :cot, :react, :tot, :got, :trm]
  }

Options

  • :model (optional) - Model identifier passed to selected strategy
  • :default_strategy (optional) - Default strategy if analysis is inconclusive, defaults to :react
  • :strategy (optional) - Manual override to force a specific strategy
  • :available_strategies (optional) - List of available strategies, defaults to [:cod, :cot, :react, :tot, :got, :trm]
  • :complexity_thresholds (optional) - Map of thresholds for strategy selection

Signal Routing

Signal routes are delegated to the selected strategy. Before a strategy is selected, the adaptive strategy handles the initial routing.

State

State includes the selected strategy module and its state.

Summary

Functions

Analyzes a prompt and returns the recommended strategy.

Returns the complexity score for the current task.

Returns the currently selected strategy for an agent.

Returns the action atom for handling streaming LLM partial tokens.

Returns the action atom for handling LLM results.

Returns the action atom for handling request rejection events.

Returns the action atom for starting an adaptive exploration.

Types

complexity()

@type complexity() :: :simple | :moderate | :complex

config()

@type config() :: %{
  optional(:model) => String.t(),
  optional(:default_strategy) => strategy_type(),
  optional(:available_strategies) => [strategy_type()],
  optional(:complexity_thresholds) => map(),
  optional(:strategy_opts) => keyword()
}

strategy_type()

@type strategy_type() :: :cod | :cot | :react | :aot | :tot | :got | :trm

Functions

analyze_prompt(prompt, config \\ %{})

Analyzes a prompt and returns the recommended strategy.

get_complexity_score(agent)

@spec get_complexity_score(Jido.Agent.t()) :: float() | nil

Returns the complexity score for the current task.

get_selected_strategy(agent)

@spec get_selected_strategy(Jido.Agent.t()) :: strategy_type() | nil

Returns the currently selected strategy for an agent.

llm_partial_action()

@spec llm_partial_action() :: :adaptive_llm_partial

Returns the action atom for handling streaming LLM partial tokens.

llm_result_action()

@spec llm_result_action() :: :adaptive_llm_result

Returns the action atom for handling LLM results.

request_error_action()

@spec request_error_action() :: :adaptive_request_error

Returns the action atom for handling request rejection events.

start_action()

@spec start_action() :: :adaptive_start

Returns the action atom for starting an adaptive exploration.