Package com.tnsai.refinement
Class RefinementLoop
java.lang.Object
com.tnsai.refinement.RefinementLoop
Iterative refinement loop for persistent output improvement.
Inspired by Claude's Ralph plugin, this executor repeatedly processes outputs until they meet predefined standards through iterative refinement.
Usage
RefinementLoop loop = RefinementLoop.builder()
.task("Convert Python to TypeScript")
.completionCriteria(CompletionCriteria.builder()
.compilerCheck("tsc --noEmit")
.testCommand("npm test")
.mustNotContain("def ", "import ")
.build())
.maxIterations(10)
.stopHook(StopHook.onAllTestsPass())
.onIteration(iter -> log.info("Iteration {}", iter.iterationNumber()))
.build();
RefinementResult result = loop.execute(agent, pythonCode);
System.out.println(result.getFinalOutput());
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for RefinementLoop. -
Method Summary
Modifier and TypeMethodDescriptionstatic RefinementLoop.Builderbuilder()Creates a new builder for RefinementLoop.Executes the refinement loop with an agent.Executes the refinement loop with an LLM client.
-
Method Details
-
builder
Creates a new builder for RefinementLoop. -
execute
Executes the refinement loop with an agent.- Parameters:
agent- The agent to use for refinementinput- The initial input to refine- Returns:
- The refinement result
-
execute
Executes the refinement loop with an LLM client.
-