Add shared tool loop stop policy

This commit is contained in:
2026-05-18 19:24:39 +03:00
parent 13df2a1c23
commit 9a105caf0b
6 changed files with 152 additions and 1 deletions
+40
View File
@@ -0,0 +1,40 @@
import test from "node:test";
import assert from "node:assert/strict";
const {decideToolLoopContinuation} = await import("../dist/ai/tool-loop-control.js");
test("tool loop continuation stops when there are no tool calls", () => {
const decision = decideToolLoopContinuation({
round: 0,
maxRounds: 3,
toolCalls: [],
});
assert.equal(decision.continue, false);
assert.equal(decision.reason, "no_tool_calls");
assert.equal(decision.remainingRounds, 2);
});
test("tool loop continuation stops on the last allowed round", () => {
const decision = decideToolLoopContinuation({
round: 2,
maxRounds: 3,
toolCalls: [{id: "call-1", name: "read_file", argumentsText: "{}"}],
});
assert.equal(decision.continue, false);
assert.equal(decision.reason, "max_rounds_reached");
assert.equal(decision.remainingRounds, 0);
});
test("tool loop continuation allows further rounds when tools remain and rounds are left", () => {
const decision = decideToolLoopContinuation({
round: 1,
maxRounds: 3,
toolCalls: [{id: "call-1", name: "read_file", argumentsText: "{}"}],
});
assert.equal(decision.continue, true);
assert.equal(decision.reason, undefined);
assert.equal(decision.remainingRounds, 1);
});