# `Jido.AI.Reasoning.Adaptive.Strategy`
[🔗](https://github.com/agentjido/jido_ai/blob/v2.4.0/lib/jido_ai/reasoning/adaptive/strategy.ex#L1)

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.

# `complexity`

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

# `config`

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

# `strategy_type`

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

# `analyze_prompt`

Analyzes a prompt and returns the recommended strategy.

# `get_complexity_score`

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

Returns the complexity score for the current task.

# `get_selected_strategy`

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

Returns the currently selected strategy for an agent.

# `llm_partial_action`

```elixir
@spec llm_partial_action() :: :adaptive_llm_partial
```

Returns the action atom for handling streaming LLM partial tokens.

# `llm_result_action`

```elixir
@spec llm_result_action() :: :adaptive_llm_result
```

Returns the action atom for handling LLM results.

# `request_error_action`

```elixir
@spec request_error_action() :: :adaptive_request_error
```

Returns the action atom for handling request rejection events.

# `start_action`

```elixir
@spec start_action() :: :adaptive_start
```

Returns the action atom for starting an adaptive exploration.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
