Pārlūkot izejas kodu

fix incorrect position of the first plan message in message history

alexchenzl 3 mēneši atpakaļ
vecāks
revīzija
2bcbe5517b
1 mainītis faili ar 6 papildinājumiem un 4 dzēšanām
  1. 6 4
      chrome-extension/src/background/agent/executor.ts

+ 6 - 4
chrome-extension/src/background/agent/executor.ts

@@ -137,17 +137,19 @@ export class Executor {
         if (this.planner && (context.nSteps % context.options.planningInterval === 0 || validatorFailed)) {
           validatorFailed = false;
           // The first planning step is special, we don't want to add the browser state message to memory
+          let positionForPlan = 0;
           if (this.tasks.length > 1 || step > 0) {
             await this.navigator.addStateMessageToMemory();
+            positionForPlan = this.context.messageManager.length() - 1;
+          } else {
+            positionForPlan = this.context.messageManager.length();
           }
 
           const planOutput = await this.planner.execute();
           if (planOutput.result) {
             logger.info(`🔄 Planner output: ${JSON.stringify(planOutput.result, null, 2)}`);
-            this.context.messageManager.addPlan(
-              JSON.stringify(planOutput.result),
-              this.context.messageManager.length() - 1,
-            );
+            this.context.messageManager.addPlan(JSON.stringify(planOutput.result), positionForPlan);
+
             if (planOutput.result.done) {
               // task is complete, skip navigation
               done = true;