Interface StopCondition

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface StopCondition
Determines when a ReAct loop should stop.

Stop conditions are evaluated after each step. If any condition returns true, the loop terminates and returns the current best answer.

  • Method Details

    • shouldStop

      boolean shouldStop(ReActStep step, StopCondition.StopContext context)
      Evaluates whether the loop should stop.
      Parameters:
      step - the most recently completed step
      context - the stop condition context with accumulated state
      Returns:
      true if the loop should stop
    • answerContains

      static StopCondition answerContains(String text)
      Stops when the final answer contains the specified text (case-insensitive).
    • finalAnswerDetected

      static StopCondition finalAnswerDetected()
      Stops when the LLM indicates it has a final answer (detects "Final Answer:" pattern).
    • noActionFor

      static StopCondition noActionFor(int consecutiveSteps)
      Stops when a specific number of consecutive steps have no action.
    • anyOf

      static StopCondition anyOf(StopCondition... conditions)
      Combines multiple stop conditions with OR logic.