jeopi-ai 16.7.2 → 16.7.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.
|
@@ -26,7 +26,10 @@ export interface CyclicalToolCallDetection {
|
|
|
26
26
|
readonly toolNames: readonly string[];
|
|
27
27
|
readonly windowSize: number;
|
|
28
28
|
}
|
|
29
|
-
export type ToolCallLoopDetection = RepeatedToolCallDetection | CyclicalToolCallDetection
|
|
29
|
+
export type ToolCallLoopDetection = RepeatedToolCallDetection | CyclicalToolCallDetection | {
|
|
30
|
+
readonly kind: "stalled_tool_call";
|
|
31
|
+
readonly toolName: string;
|
|
32
|
+
};
|
|
30
33
|
/** Detects consecutive identical or semantically repeated assistant tool calls across model turns. */
|
|
31
34
|
export declare class ToolCallLoopGuard {
|
|
32
35
|
#private;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "jeopi-ai",
|
|
4
|
-
"version": "16.7.
|
|
4
|
+
"version": "16.7.3",
|
|
5
5
|
"description": "Unified LLM API with automatic model discovery and provider configuration",
|
|
6
6
|
"homepage": "https://github.com/akillness/jeopi",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@bufbuild/protobuf": "^2.12.0",
|
|
41
|
-
"jeopi-catalog": "16.7.
|
|
42
|
-
"jeopi-utils": "16.7.
|
|
43
|
-
"jeopi-wire": "16.7.
|
|
41
|
+
"jeopi-catalog": "16.7.3",
|
|
42
|
+
"jeopi-utils": "16.7.3",
|
|
43
|
+
"jeopi-wire": "16.7.3",
|
|
44
44
|
"arktype": "2.2.3",
|
|
45
45
|
"zod": "^4"
|
|
46
46
|
},
|
|
@@ -36,7 +36,10 @@ export interface CyclicalToolCallDetection {
|
|
|
36
36
|
readonly windowSize: number;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export type ToolCallLoopDetection =
|
|
39
|
+
export type ToolCallLoopDetection =
|
|
40
|
+
| RepeatedToolCallDetection
|
|
41
|
+
| CyclicalToolCallDetection
|
|
42
|
+
| { readonly kind: "stalled_tool_call"; readonly toolName: string };
|
|
40
43
|
|
|
41
44
|
function canonicalizeToolCallValue(value: unknown): unknown {
|
|
42
45
|
if (Array.isArray(value)) {
|
|
@@ -166,6 +169,7 @@ export class ToolCallLoopGuard {
|
|
|
166
169
|
#threshold: number;
|
|
167
170
|
#exemptTools: ReadonlySet<string>;
|
|
168
171
|
#callStreaks = new Map<string, number>();
|
|
172
|
+
#unchanged: { fingerprint: bigint; count: number } | undefined;
|
|
169
173
|
#cycleWindowSize: number;
|
|
170
174
|
#recentCalls: Array<{ hash: string; toolNames: string[] }> = [];
|
|
171
175
|
#lastCycleSignature: string | undefined;
|
|
@@ -190,6 +194,7 @@ export class ToolCallLoopGuard {
|
|
|
190
194
|
}
|
|
191
195
|
|
|
192
196
|
#reset(): void {
|
|
197
|
+
this.#unchanged = undefined;
|
|
193
198
|
this.#callStreaks.clear();
|
|
194
199
|
this.#recentCalls = [];
|
|
195
200
|
this.#lastCycleSignature = undefined;
|
|
@@ -240,6 +245,7 @@ export class ToolCallLoopGuard {
|
|
|
240
245
|
|
|
241
246
|
const trackedCalls = allToolCalls.filter(call => !this.#isExemptToolCall(call));
|
|
242
247
|
if (trackedCalls.length === 0) {
|
|
248
|
+
this.#unchanged = undefined;
|
|
243
249
|
return null;
|
|
244
250
|
}
|
|
245
251
|
|
|
@@ -264,13 +270,39 @@ export class ToolCallLoopGuard {
|
|
|
264
270
|
for (const entry of turnEntries) {
|
|
265
271
|
const count = (this.#callStreaks.get(entry.lookupKey) ?? 0) + 1;
|
|
266
272
|
nextStreaks.set(entry.lookupKey, count);
|
|
267
|
-
if (count
|
|
273
|
+
if (count === this.#threshold && !hitEntry) {
|
|
268
274
|
hitEntry = { toolCall: entry.toolCall, canonicalArgs: entry.canonicalArgs, count };
|
|
269
275
|
}
|
|
270
276
|
}
|
|
271
277
|
|
|
272
278
|
this.#callStreaks = nextStreaks;
|
|
273
279
|
|
|
280
|
+
// The redirect uses a broad semantic match. Pausing needs stronger evidence:
|
|
281
|
+
// one exact call and the same full text result, after a redirect was sent.
|
|
282
|
+
const entry = turnEntries[0];
|
|
283
|
+
const result = turn.toolResults[0];
|
|
284
|
+
if (
|
|
285
|
+
allToolCalls.length === 1 &&
|
|
286
|
+
entry &&
|
|
287
|
+
(nextStreaks.get(entry.lookupKey) ?? 0) > this.#threshold &&
|
|
288
|
+
turn.toolResults.length === 1 &&
|
|
289
|
+
result?.toolCallId === entry.toolCall.id &&
|
|
290
|
+
result.content.length &&
|
|
291
|
+
result.content.every(part => part.type === "text")
|
|
292
|
+
) {
|
|
293
|
+
const fingerprint = Bun.hash(
|
|
294
|
+
JSON.stringify([entry.toolCall.name, entry.canonicalArgs, result.isError, result.content]),
|
|
295
|
+
);
|
|
296
|
+
const count = this.#unchanged?.fingerprint === fingerprint ? this.#unchanged.count + 1 : 1;
|
|
297
|
+
this.#unchanged = { fingerprint, count };
|
|
298
|
+
if (count >= Math.max(2, this.#threshold)) {
|
|
299
|
+
this.#reset();
|
|
300
|
+
return { kind: "stalled_tool_call", toolName: entry.toolCall.name };
|
|
301
|
+
}
|
|
302
|
+
} else {
|
|
303
|
+
this.#unchanged = undefined;
|
|
304
|
+
}
|
|
305
|
+
|
|
274
306
|
if (hitEntry) {
|
|
275
307
|
return {
|
|
276
308
|
kind: "repeated_tool_call",
|