Table of Contents

Interface IReasoningStrategy<T>

Namespace
AiDotNet.Interfaces
Assembly
AiDotNet.dll

Defines the contract for reasoning strategies that solve problems through structured thinking.

public interface IReasoningStrategy<T>

Type Parameters

T

The numeric type used for calculations and scoring (e.g., double, float).

Remarks

For Beginners: A reasoning strategy is like a specific approach or method for solving problems. Just like you might use different strategies to solve math problems (working backwards, drawing diagrams, breaking into steps), AI systems can use different reasoning strategies like Chain-of-Thought, Tree-of-Thoughts, or Self-Consistency.

This interface defines what every reasoning strategy must be able to do:

  • Accept a problem or query
  • Apply its specific reasoning approach
  • Return a structured result with the answer and reasoning trace

Think of it like different cooking methods (baking, frying, steaming) - they're all ways to prepare food, but each has its own process. Similarly, different reasoning strategies all aim to solve problems, but each uses a different approach.

Example Usage:

// Use Chain-of-Thought strategy for step-by-step reasoning
IReasoningStrategy<double> cotStrategy = new ChainOfThoughtStrategy<double>(chatModel);
var result = await cotStrategy.ReasonAsync("What is 15% of 240?");
Console.WriteLine(result.FinalAnswer); // "36"
Console.WriteLine(result.ReasoningChain); // Shows step-by-step work

// Use Tree-of-Thoughts for exploring multiple paths
IReasoningStrategy<double> totStrategy = new TreeOfThoughtsStrategy<double>(chatModel);
var result2 = await totStrategy.ReasonAsync("How can we reduce carbon emissions?");

Properties

Description

Gets a description of what this reasoning strategy does and when to use it.

string Description { get; }

Property Value

string

Remarks

For Beginners: This provides information about what makes this strategy unique and what types of problems it's best suited for. For example, Chain-of-Thought might describe itself as "Best for problems requiring step-by-step logical deduction."

StrategyName

Gets the name of this reasoning strategy.

string StrategyName { get; }

Property Value

string

Remarks

For Beginners: This is a human-readable name that identifies the strategy, like "Chain-of-Thought" or "Tree-of-Thoughts". It's useful for logging, debugging, or displaying to users which reasoning approach was used.

Methods

ReasonAsync(string, ReasoningConfig?, CancellationToken)

Applies the reasoning strategy to solve a problem or answer a query.

Task<ReasoningResult<T>> ReasonAsync(string query, ReasoningConfig? config = null, CancellationToken cancellationToken = default)

Parameters

query string

The problem or question to reason about.

config ReasoningConfig

Configuration options for the reasoning process (optional).

cancellationToken CancellationToken

Token to cancel the operation (optional).

Returns

Task<ReasoningResult<T>>

A reasoning result containing the answer, reasoning chain, and metadata.

Remarks

For Beginners: This method is where the actual "thinking" happens. You provide a question or problem, and the strategy applies its specific reasoning approach to solve it.

The config parameter lets you customize how the strategy works (like setting how many steps to take, or how deep to explore). The cancellationToken allows you to stop the reasoning if it's taking too long.

The result includes not just the final answer, but also the complete reasoning process, so you can see how the AI arrived at its conclusion.