Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/engine/conversationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ function safeStringify(value: unknown): string {
}
return val;
});
} catch (err) {
} catch {
return String(value);
}
}
48 changes: 29 additions & 19 deletions src/engine/copilotEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ export class CopilotEngine {
let iteration = 0;
let isFirstIteration = true;
let hadPlannedCalls = false;
let shouldStopForSatisfiedPlanner = false;

// Step 4: Reasoning Loop
while (iteration < this.maxIterations) {
Expand Down Expand Up @@ -391,28 +392,37 @@ export class CopilotEngine {
);
plannedCalls = plan.toolCalls ?? [];

if (iteration >= 3 && plannedCalls.length === 0) {
console.log(
`[Copilot][${chatId}] Follow-up planner returned no tool calls on iteration ${iteration}. Treating this as satisfied and stopping for synthesis.`,
);
shouldStopForSatisfiedPlanner = true;
}

// Record iteration start with planned tools
this.executionTracer.startIteration(trace, plannedCalls);

// Apply follow-up heuristics
const beforeHeuristics = plannedCalls.length;
const followUpSuggestions = await this.followUpEngine.applyFollowUps(
formattedResults,
chatId,
conversationTurns,
questionForPlanning,
plannedCalls,
);
plannedCalls.push(...followUpSuggestions);

// Record heuristic modifications
if (plannedCalls.length !== beforeHeuristics) {
this.executionTracer.recordHeuristic(trace, {
heuristicName: "followUpHeuristics",
action: "modify",
reason: "Applied context-aware follow-up heuristics",
affectedTools: plannedCalls.map((c) => c.name),
});
if (!shouldStopForSatisfiedPlanner) {
// Apply follow-up heuristics
const beforeHeuristics = plannedCalls.length;
const followUpSuggestions = await this.followUpEngine.applyFollowUps(
formattedResults,
chatId,
conversationTurns,
questionForPlanning,
plannedCalls,
);
plannedCalls.push(...followUpSuggestions);

// Record heuristic modifications
if (plannedCalls.length !== beforeHeuristics) {
this.executionTracer.recordHeuristic(trace, {
heuristicName: "followUpHeuristics",
action: "modify",
reason: "Applied context-aware follow-up heuristics",
affectedTools: plannedCalls.map((c) => c.name),
});
}
}
}

Expand Down
Loading
Loading