Package com.tnsai.planning.llm
Class AdaptiveReplanEngine
java.lang.Object
com.tnsai.planning.llm.AdaptiveReplanEngine
Executes LLM-generated plans with adaptive replanning on failure.
When a step fails during execution, the engine sends the failure context (error, completed steps, remaining steps) back to the LLM to generate an updated plan for the remaining work.
Replanning Process
- Execute steps sequentially using the provided
StepExecutor - On failure: collect context (completed steps, error, remaining goal)
- Call LLM with failure context to generate a revised plan
- Continue execution with the revised plan
- Repeat up to
maxReplanAttemptstimes
Usage
AdaptiveReplanEngine engine = AdaptiveReplanEngine.builder()
.llm(client)
.planner(planner)
.stepExecutor(step -> {
// execute the step
return StepExecutionResult.success("done");
})
.maxReplanAttempts(3)
.build();
PlanExecutionResult result = engine.execute("Deploy the application");
- Since:
- 0.3.0
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic AdaptiveReplanEngine.Builderbuilder()Creates a new builder.Generates and executes a plan for the given goal, replanning on failure.Generates and executes a plan for the given goal with state context.executePlan(LLMPlan plan) Executes an already-generated plan, replanning on failure.executePlan(LLMPlan plan, Map<String, Object> state) Executes an already-generated plan with state context, replanning on failure.
-
Method Details
-
builder
Creates a new builder. -
execute
Generates and executes a plan for the given goal, replanning on failure.- Parameters:
goal- the natural-language goal- Returns:
- execution result
-
execute
Generates and executes a plan for the given goal with state context.- Parameters:
goal- the natural-language goalstate- current state context- Returns:
- execution result
-
executePlan
Executes an already-generated plan, replanning on failure.- Parameters:
plan- the plan to execute- Returns:
- execution result
-
executePlan
Executes an already-generated plan with state context, replanning on failure.- Parameters:
plan- the plan to executestate- current state context- Returns:
- execution result
-