From 1b47c64c8ba07950227994782bd68a5ac55634ca Mon Sep 17 00:00:00 2001 From: Andrew Beal Date: Wed, 28 Jan 2026 23:03:38 +0000 Subject: [PATCH] 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. --- AIClasses/FunctionDefinitions/AIFunctionDefinitions.ts | 2 +- Services/AIServices/OrchestrationAgent.ts | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/AIClasses/FunctionDefinitions/AIFunctionDefinitions.ts b/AIClasses/FunctionDefinitions/AIFunctionDefinitions.ts index 3679269..5f04c8f 100644 --- a/AIClasses/FunctionDefinitions/AIFunctionDefinitions.ts +++ b/AIClasses/FunctionDefinitions/AIFunctionDefinitions.ts @@ -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[] { diff --git a/Services/AIServices/OrchestrationAgent.ts b/Services/AIServices/OrchestrationAgent.ts index 16f7489..3bc8a9b 100644 --- a/Services/AIServices/OrchestrationAgent.ts +++ b/Services/AIServices/OrchestrationAgent.ts @@ -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");