Package com.tnsai.reasoning
Interface ReasoningStrategyHandle
public interface ReasoningStrategyHandle
SPI handle for reasoning strategy integration.
This interface defines the reasoning contract that
Agent uses. Concrete implementations
live in tnsai-intelligence and are discovered via SpiLoader.
Supported strategies include:
- ReAct: Reason → Act → Observe loop
- Tree of Thoughts: Multi-path exploration with pruning
- Graph of Thoughts: Graph-based reasoning with merging
- Self-Consistency: Multiple paths with consensus voting
Usage Example
Agent agent = AgentBuilder.create()
.role(new MyRole())
.reasoningStrategy("react")
.build();
// Agent uses ReAct loop instead of simple LLM call
String answer = agent.chat("Solve this problem step by step");
// Access reasoning details
agent.getLastReasoningResult().ifPresent(result -> {
System.out.println("Steps: " + result.metadata().get("steps"));
System.out.println("LLM calls: " + result.metadata().get("llmCalls"));
});
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceFactory for creating ReasoningStrategyHandle instances by name.static final recordContext provided to the reasoning strategy by the Agent.static final recordResult of a reasoning operation. -
Method Summary
Modifier and TypeMethodDescriptionname()Returns the strategy name (e.g., "react", "tot", "got", "self-consistency").reason(String message, ReasoningStrategyHandle.ReasoningContext context) Performs reasoning on a message using the strategy's algorithm.
-
Method Details
-
reason
ReasoningStrategyHandle.ReasoningResult reason(String message, ReasoningStrategyHandle.ReasoningContext context) Performs reasoning on a message using the strategy's algorithm.- Parameters:
message- user message to reason aboutcontext- reasoning context providing LLM, tools, and history- Returns:
- result containing the answer and strategy-specific metadata
-
name
String name()Returns the strategy name (e.g., "react", "tot", "got", "self-consistency").- Returns:
- strategy identifier
-