Class ReActExecutor

java.lang.Object
com.tnsai.reasoning.react.ReActExecutor

public final class ReActExecutor extends Object
ReAct (Reason + Act + Observe) executor for agentic reasoning.

Implements the ReAct pattern where an LLM explicitly reasons about what to do, takes an action, observes the result, and repeats until the goal is achieved.

This differs from a simple tool-calling loop (AgentToolExecutor) because ReAct produces explicit reasoning traces with structured Thought/Action/Observation steps, enabling better interpretability and decision auditing.

Usage


 ReActExecutor react = ReActExecutor.builder()
     .llm(client)
     .actionHandler((name, input) -> {
         if ("search".equals(name)) return Optional.of(searchService.search(input));
         if ("calculate".equals(name)) return Optional.of(calculator.eval(input));
         return Optional.empty();
     })
     .maxSteps(10)
     .thoughtFormat(ThoughtFormat.STRUCTURED)
     .stopCondition(StopCondition.finalAnswerDetected())
     .build();

 ReActResult result = react.execute("Find the population of Tokyo and compare it to NYC");
 System.out.println(result.getFinalAnswer());
 System.out.println(result.getReasoningTrace());
 

Research Reference

"ReAct: Synergizing Reasoning and Acting in Language Models" (Yao et al., 2022)

See Also:
  • Method Details

    • execute

      public ReActResult execute(String question)
      Executes the ReAct loop for the given question/task.
      Parameters:
      question - the question or task to solve
      Returns:
      the result containing the final answer and all reasoning steps
    • builder

      public static ReActExecutor.Builder builder()