Package dev.agenor.runtime.reflection
Class DefaultReflectionStrategy
java.lang.Object
dev.agenor.runtime.reflection.DefaultReflectionStrategy
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault critique prompt sent to the LLM when no custom prompt is configured. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultReflectionStrategy(LLMProvider llmProvider) Creates aDefaultReflectionStrategyusing the givenLLMProvider. -
Method Summary
Modifier and TypeMethodDescriptioncritique(String originalOutput, String task, ReflectionConfig config) CritiquesoriginalOutputin the context oftask.
-
Field Details
-
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.Xso it can be reliably parsed.- See Also:
-
-
Constructor Details
-
DefaultReflectionStrategy
Creates aDefaultReflectionStrategyusing the givenLLMProvider.- 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) CritiquesoriginalOutputin the context oftask.Builds a critique prompt, calls the LLM, and parses the score from the response. If the score meets or exceeds
ReflectionConfig.scoreThreshold()the returnedCritiqueResulthasshouldRevise = false; otherwisetrue.- Specified by:
critiquein interfaceReflectionStrategy- 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; nevernull
-