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
+25
View File
@@ -33,6 +33,7 @@ import {
allToolSchemaNames
} from "./unified-ai-runner.shared";
import {executeToolBatchWithAdapter} from "./tool-batch-runner";
import {decideToolLoopContinuation} from "./tool-loop-control";
import {bot} from "../index";
import fs from "node:fs";
import path from "node:path";
@@ -204,6 +205,18 @@ export async function runOpenAi(
}
}
const continuation = decideToolLoopContinuation({
round,
maxRounds: MAX_TOOL_ROUNDS,
toolCalls: calls,
});
if (!continuation.continue && continuation.reason === "max_rounds_reached") {
aiLog("warn", "openai.tool_loop.max_rounds_reached", {
round,
maxRounds: MAX_TOOL_ROUNDS,
});
}
responseInput = [...responseInput, ...(response.output ?? []), ...toolOutputs];
continue;
}
@@ -400,6 +413,18 @@ export async function runOpenAi(
}
}
const continuation = decideToolLoopContinuation({
round,
maxRounds: MAX_TOOL_ROUNDS,
toolCalls: calls,
});
if (!continuation.continue && continuation.reason === "max_rounds_reached") {
aiLog("warn", "openai.tool_loop.max_rounds_reached", {
round,
maxRounds: MAX_TOOL_ROUNDS,
});
}
responseInput = [...responseInput, ...(completedResponse.output ?? []), ...toolOutputs];
}
} finally {