@kenkaiiii/gg-agent 5.22.2 → 5.22.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +27 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +27 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -227,6 +227,7 @@ async function* agentLoop(messages, options) {
|
|
|
227
227
|
let overloadRetries = 0;
|
|
228
228
|
let emptyResponseRetries = 0;
|
|
229
229
|
let stallRetries = 0;
|
|
230
|
+
let runawayToolcallRetries = 0;
|
|
230
231
|
let overflowCompactionAttempts = 0;
|
|
231
232
|
let toolResultTruncationAttempted = false;
|
|
232
233
|
const invalidToolArgumentCounts = /* @__PURE__ */ new Map();
|
|
@@ -235,6 +236,8 @@ async function* agentLoop(messages, options) {
|
|
|
235
236
|
const MAX_OVERLOAD_RETRIES = 10;
|
|
236
237
|
const MAX_EMPTY_RESPONSE_RETRIES = 2;
|
|
237
238
|
const MAX_STALL_RETRIES = 5;
|
|
239
|
+
const MAX_RUNAWAY_TOOLCALL_RETRIES = 2;
|
|
240
|
+
const RUNAWAY_TOOLCALL_RETRY_DELAY_MS = 1e3;
|
|
238
241
|
const MAX_OVERFLOW_COMPACTIONS = 2;
|
|
239
242
|
const STALL_RETRIES_BEFORE_NON_STREAMING = 2;
|
|
240
243
|
const STALL_DELAY_MS = 1e3;
|
|
@@ -639,11 +642,33 @@ async function* agentLoop(messages, options) {
|
|
|
639
642
|
provider: options.provider,
|
|
640
643
|
model: options.model
|
|
641
644
|
});
|
|
645
|
+
if (runawayToolcallRetries < MAX_RUNAWAY_TOOLCALL_RETRIES) {
|
|
646
|
+
runawayToolcallRetries++;
|
|
647
|
+
const delayMs = RUNAWAY_TOOLCALL_RETRY_DELAY_MS * runawayToolcallRetries;
|
|
648
|
+
diag("retry", {
|
|
649
|
+
reason: "runaway_toolcall",
|
|
650
|
+
attempt: runawayToolcallRetries,
|
|
651
|
+
maxAttempts: MAX_RUNAWAY_TOOLCALL_RETRIES,
|
|
652
|
+
delayMs,
|
|
653
|
+
...runawayDetected
|
|
654
|
+
});
|
|
655
|
+
yield {
|
|
656
|
+
type: "retry",
|
|
657
|
+
reason: "runaway_toolcall",
|
|
658
|
+
attempt: runawayToolcallRetries,
|
|
659
|
+
maxAttempts: MAX_RUNAWAY_TOOLCALL_RETRIES,
|
|
660
|
+
delayMs,
|
|
661
|
+
silent: true
|
|
662
|
+
};
|
|
663
|
+
await abortableSleep(delayMs, options.signal);
|
|
664
|
+
turn--;
|
|
665
|
+
continue;
|
|
666
|
+
}
|
|
642
667
|
const detail = runawayDetected.kind === "chars" ? `${(runawayDetected.chars / 1024).toFixed(0)} KB of tool-call arguments` : `${runawayDetected.events} tool-call delta events`;
|
|
643
668
|
yield {
|
|
644
669
|
type: "error",
|
|
645
670
|
error: new Error(
|
|
646
|
-
`The model
|
|
671
|
+
`The model repeatedly failed to close a tool call after ${MAX_RUNAWAY_TOOLCALL_RETRIES} automatic retries (${detail}). Switch models and retry; your conversation is preserved.`
|
|
647
672
|
)
|
|
648
673
|
};
|
|
649
674
|
break;
|
|
@@ -744,6 +769,7 @@ async function* agentLoop(messages, options) {
|
|
|
744
769
|
}
|
|
745
770
|
overloadRetries = 0;
|
|
746
771
|
stallRetries = 0;
|
|
772
|
+
runawayToolcallRetries = 0;
|
|
747
773
|
const contentArr = Array.isArray(response.message.content) ? response.message.content : null;
|
|
748
774
|
const hasActionableContent = response.message.content !== "" && contentArr !== null && contentArr.some(
|
|
749
775
|
(p) => p.type === "text" || p.type === "tool_call" || p.type === "server_tool_call"
|