fix: improve stuck detection to detect same tool repeated
- Previous fix required EXACT same tool call signature (including arguments) - Bot was stuck reading file in sections with different line numbers - New logic: detect stuck if SAME TOOL is called repeatedly (arguments may vary) - Extract tool name from signature and check if all recent calls use same tool - Still requires 3+ repetitions before triggering intervention This fixes the infinite loop bug when bot tries to read large files in sections. Example: - Before: bash:read:1-100, bash:read:101-200, bash:read:201-300 (different signatures) → not stuck - After: bash:read:1-100, bash:read:101-200, bash:read:201-300 (same tool, different args) → stuck!
This commit is contained in:
@@ -514,11 +514,24 @@ export async function initBot(config, api, tools, skills, agents) {
|
|||||||
// Hash: tool name + first 80 chars of args (enough to detect repeated patterns)
|
// Hash: tool name + first 80 chars of args (enough to detect repeated patterns)
|
||||||
return `${fn.name}:${args.slice(0, 80)}`;
|
return `${fn.name}:${args.slice(0, 80)}`;
|
||||||
};
|
};
|
||||||
const isStuck = () => {
|
const isStuck = () => {
|
||||||
if (callHistory.length < STUCK_THRESHOLD) return false;
|
if (callHistory.length < STUCK_THRESHOLD) return false;
|
||||||
const recent = callHistory.slice(-STUCK_THRESHOLD);
|
const recent = callHistory.slice(-STUCK_THRESHOLD);
|
||||||
return recent.every(s => s === recent[0]);
|
|
||||||
};
|
// Flexible: detect stuck even if arguments vary slightly
|
||||||
|
// Extract tool name from signature (everything before first colon)
|
||||||
|
const toolNames = recent.map(s => s.split(':')[0]);
|
||||||
|
const uniqueToolNames = [...new Set(toolNames)];
|
||||||
|
|
||||||
|
// If all calls use the same tool, check if they differ by arguments
|
||||||
|
if (uniqueToolNames.length === 1) {
|
||||||
|
// Same tool, different arguments → still stuck
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Different tools → not stuck
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
// Context compaction: trim old tool results to keep context manageable
|
// Context compaction: trim old tool results to keep context manageable
|
||||||
const compactContext = () => {
|
const compactContext = () => {
|
||||||
|
|||||||
1593
src/bot/index.js.backup
Normal file
1593
src/bot/index.js.backup
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user