aboutsummaryrefslogtreecommitdiff
path: root/modules/core/module-aiassist.js
diff options
context:
space:
mode:
Diffstat (limited to 'modules/core/module-aiassist.js')
-rw-r--r--modules/core/module-aiassist.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/modules/core/module-aiassist.js b/modules/core/module-aiassist.js
index a5c5022..5f20fbc 100644
--- a/modules/core/module-aiassist.js
+++ b/modules/core/module-aiassist.js
@@ -1365,6 +1365,27 @@ buildSystemPrompt() {
var profile = this._activeLoopProfile || {};
var loopCfg = profile.loop || {};
var maxTurns = loopCfg.maxTurns || this.MAX_TOOL_TURNS;
+ var baseTurns = maxTurns;
+ let _lastTurnSig = null, _progressStreak = 0, _stallStreak = 0;
+ const _logStart = (this._toolCallLog || []).length;
+ // D3: extend the budget only while turns keep producing NEW output.
+ const _noteProgress = (results) => {
+ try {
+ const arr = (results || []).map(r => (r && typeof r === 'object' && 'toolResult' in r) ? r.toolResult : r);
+ if (!arr.length) return;
+ const h = _sigHash(JSON.stringify(arr));
+ if (_lastTurnSig !== null && h !== _lastTurnSig) { _progressStreak++; _stallStreak = 0; }
+ else if (_lastTurnSig !== null) { _stallStreak++; _progressStreak = 0; }
+ _lastTurnSig = h;
+ if (_progressStreak >= 2 && maxTurns < baseTurns + 4) {
+ maxTurns += 2;
+ this.terminal.print(`📈 Progress detected — extending turn budget to ${maxTurns}`, 'info');
+ }
+ if (_stallStreak === 3) {
+ messages.push({ role: 'system', content: 'No new information in the last turns — stop calling tools and give your final answer now.' });
+ }
+ } catch (_e) {}
+ };
var loopDetect = loopCfg.loopDetection || { enabled: true, threshold: 6, windowMs: 30000 };
var confEsc = loopCfg.confidenceEscalation || { enabled: true, threshold: 90 };
var finalPrompt = loopCfg.finalTurnPrompt || 'This is your last tool turn. You MUST provide a final answer after this tool call. Synthesize what you know.';
@@ -1666,6 +1687,7 @@ buildSystemPrompt() {
}
}
}
+ _noteProgress(safeResults);
if (pendingText) {
messages.push({ role: 'assistant', content: pendingText });
}