Package com.tnsai.planning.llm
Class PlanApprovalGate
java.lang.Object
com.tnsai.planning.llm.PlanApprovalGate
Plan-level human-in-the-loop approval gate.
Sits between plan generation and execution, presenting the plan to the user for review. Users can approve, reject, modify, or reorder steps before execution proceeds.
Approval Flow
- Planner generates plan
- Gate presents plan to user via
PlanApprovalGate.PlanReviewCallback - User returns an
PlanApprovalGate.ApprovalDecision - Gate applies modifications and returns the final plan (or empty on reject)
Usage
PlanApprovalGate gate = PlanApprovalGate.builder()
.reviewCallback(plan -> {
System.out.println(plan.toDisplayString());
System.out.print("Approve? (y/n/modify): ");
String input = scanner.nextLine();
if ("y".equals(input)) return ApprovalDecision.approve();
if ("n".equals(input)) return ApprovalDecision.reject("User rejected");
return ApprovalDecision.approve(); // simplified
})
.build();
Optional<LLMPlan> approved = gate.review(generatedPlan);
approved.ifPresent(plan -> engine.executePlan(plan));
Integration with ToolCallFilter
For step-level approval during execution, combine with the agent's
ToolCallFilter. The gate handles
plan-level approval; the filter handles individual tool call approval.
- Since:
- 0.3.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordRepresents the user's decision after reviewing a plan.static enumType of plan approval decision.static final classBuilder forPlanApprovalGate.static interfaceCallback for presenting a plan to the user for review. -
Method Summary
Modifier and TypeMethodDescriptionstatic PlanApprovalGateCreates a gate that auto-approves all plans (useful for testing/automation).static PlanApprovalGate.Builderbuilder()Creates a new builder.generateAndReview(LLMDynamicPlanner planner, String goal) Generates a plan and reviews it in one step.generateAndReview(LLMDynamicPlanner planner, String goal, Map<String, Object> state) Generates a plan with state context and reviews it.Reviews a plan through the approval gate.
-
Method Details
-
builder
Creates a new builder. -
autoApprove
Creates a gate that auto-approves all plans (useful for testing/automation). -
review
Reviews a plan through the approval gate.- Parameters:
plan- the plan to review- Returns:
- the approved (possibly modified) plan, or empty if rejected
-
generateAndReview
Generates a plan and reviews it in one step.- Parameters:
planner- the planner to usegoal- the goal- Returns:
- approved plan, or empty if rejected
-
generateAndReview
public Optional<LLMPlan> generateAndReview(LLMDynamicPlanner planner, String goal, Map<String, Object> state) Generates a plan with state context and reviews it.- Parameters:
planner- the planner to usegoal- the goalstate- current state- Returns:
- approved plan, or empty if rejected
-