Class DefaultReflectionStrategy

java.lang.Object
dev.agenor.runtime.reflection.DefaultReflectionStrategy
All Implemented Interfaces:
ReflectionStrategy

public class DefaultReflectionStrategy extends Object implements ReflectionStrategy
Default ReflectionStrategy implementation backed by an LLMProvider.

Builds a critique prompt (custom or DEFAULT_CRITIQUE_PROMPT), calls LLMProvider.chat(dev.agenor.core.llm.LLMRequest) to obtain structured feedback, then parses the quality score from the response text using the pattern score: X.X.

Score parsing rules:

  • Pattern score:\s*([0-9]*\.?[0-9]+) is matched case-insensitively.
  • Parsed value is clamped to [0.0, 1.0].
  • If no score is found the response is treated as requiring revision with a conservative score of 0.5.

Example:


 DefaultReflectionStrategy strategy = new DefaultReflectionStrategy(llmProvider);
 CritiqueResult result = strategy.critique(output, task, ReflectionConfig.defaults()).join();
 
Since:
0.12.0
  • Field Details

    • DEFAULT_CRITIQUE_PROMPT

      public static final String DEFAULT_CRITIQUE_PROMPT
      Default critique prompt sent to the LLM when no custom prompt is configured.

      The prompt instructs the model to reply with a score on the last line using the format score: X.X so it can be reliably parsed.

      See Also:
  • Constructor Details

    • DefaultReflectionStrategy

      public DefaultReflectionStrategy(LLMProvider llmProvider)
      Creates a DefaultReflectionStrategy using the given LLMProvider.
      Parameters:
      llmProvider - the provider used to call the critique LLM (non-null)
  • Method Details

    • critique

      public CompletableFuture<CritiqueResult> critique(String originalOutput, String task, ReflectionConfig config)
      Critiques originalOutput in the context of task.

      Builds a critique prompt, calls the LLM, and parses the score from the response. If the score meets or exceeds ReflectionConfig.scoreThreshold() the returned CritiqueResult has shouldRevise = false; otherwise true.

      Specified by:
      critique in interface ReflectionStrategy
      Parameters:
      originalOutput - the text produced by the agent that should be evaluated (non-null)
      task - the original task or prompt that produced the output (non-null)
      config - reflection parameters controlling thresholds and iteration limits (non-null)
      Returns:
      a future that resolves to a CritiqueResult; never null