fix: prevent plan completion when replan is requested

Track replan state to ensure plan doesn't complete prematurely when a replan
is requested. Also add CompletePlan to orchestration agent definitions and
update step progress callback on successful completion.
This commit is contained in:
Andrew Beal 2026-01-28 23:03:38 +00:00
parent 1bdab361b4
commit 1b47c64c8b
2 changed files with 8 additions and 2 deletions

View file

@ -50,7 +50,7 @@ export abstract class AIFunctionDefinitions {
}
public static orchestrationAgentDefinitions(): IAIFunctionDefinition[] {
return [CompleteStep, Replan, CancelPlan];
return [CompleteStep, Replan, CancelPlan, CompletePlan];
}
public static planningAgentDefinitions(): IAIFunctionDefinition[] {

View file

@ -48,6 +48,7 @@ export class OrchestrationAgent extends AIController {
callbacks.onPlanUpdate(executionPlan);
let currentStepIndex = 0;
let replanRequested = false;
for (const [index, step] of executionPlan.executionSteps.entries()) {
currentStepIndex = index;
callbacks.onPlanStepUpdate(currentStepIndex);
@ -102,11 +103,16 @@ export class OrchestrationAgent extends AIController {
role: Role.User,
content: `A replan was requested when attempting to execute Step ${index + 1}. Replan context: ${orchestrationResult.replanContext}`
}));
replanRequested = true;
break;
}
}
planCompleted = currentStepIndex >= executionPlan.executionSteps.length - 1;
planCompleted = !replanRequested && currentStepIndex >= executionPlan.executionSteps.length - 1;
if (planCompleted) {
callbacks.onPlanStepUpdate(executionPlan.executionSteps.length);
}
}
this.debugService?.log("OrchestrationAgent", "Planned workflow completed - requesting summary");