Class RefinementLoop

java.lang.Object
com.tnsai.refinement.RefinementLoop

public final class RefinementLoop extends Object
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());
 
  • Method Details

    • builder

      public static RefinementLoop.Builder builder()
      Creates a new builder for RefinementLoop.
    • execute

      public RefinementResult execute(com.tnsai.agents.Agent agent, String input)
      Executes the refinement loop with an agent.
      Parameters:
      agent - The agent to use for refinement
      input - The initial input to refine
      Returns:
      The refinement result
    • execute

      public RefinementResult execute(com.tnsai.llm.LLMClient llm, String input)
      Executes the refinement loop with an LLM client.