mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:20:43 +00:00
fix(agents): default proxy completions tool choice
This commit is contained in:
committed by
Peter Steinberger
parent
6a71c19839
commit
9a6b769e6e
@@ -2318,7 +2318,7 @@ describe("openai transport stream", () => {
|
||||
expect(functionCall?.arguments).toBe("not valid json");
|
||||
});
|
||||
|
||||
it("does not send tool_choice when tools are provided but toolChoice option is not set", () => {
|
||||
it("defaults tool_choice to auto for proxy-like openai-completions endpoints", () => {
|
||||
const params = buildOpenAICompletionsParams(
|
||||
{
|
||||
id: "test-model",
|
||||
@@ -2346,6 +2346,38 @@ describe("openai transport stream", () => {
|
||||
undefined,
|
||||
);
|
||||
|
||||
expect(params).toHaveProperty("tools");
|
||||
expect(params).toHaveProperty("tool_choice", "auto");
|
||||
});
|
||||
|
||||
it("does not send tool_choice by default for native openai-completions endpoints", () => {
|
||||
const params = buildOpenAICompletionsParams(
|
||||
{
|
||||
id: "gpt-5.4",
|
||||
name: "GPT-5.4",
|
||||
api: "openai-completions",
|
||||
provider: "openai",
|
||||
baseUrl: "https://api.openai.com/v1",
|
||||
reasoning: false,
|
||||
input: ["text"],
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
||||
contextWindow: 4096,
|
||||
maxTokens: 2048,
|
||||
} satisfies Model<"openai-completions">,
|
||||
{
|
||||
systemPrompt: "You are a helpful assistant",
|
||||
messages: [],
|
||||
tools: [
|
||||
{
|
||||
name: "get_weather",
|
||||
description: "Get weather information",
|
||||
parameters: { type: "object", properties: {} },
|
||||
},
|
||||
],
|
||||
} as never,
|
||||
undefined,
|
||||
);
|
||||
|
||||
expect(params).toHaveProperty("tools");
|
||||
expect(params).not.toHaveProperty("tool_choice");
|
||||
});
|
||||
|
||||
@@ -1728,6 +1728,7 @@ export function buildOpenAICompletionsParams(
|
||||
options: OpenAICompletionsOptions | undefined,
|
||||
) {
|
||||
const compat = getCompat(model);
|
||||
const compatDetection = detectOpenAICompletionsCompat(model);
|
||||
const completionsContext = context.systemPrompt
|
||||
? {
|
||||
...context,
|
||||
@@ -1765,6 +1766,12 @@ export function buildOpenAICompletionsParams(
|
||||
params.tools = convertTools(context.tools, compat, model);
|
||||
if (options?.toolChoice) {
|
||||
params.tool_choice = options.toolChoice;
|
||||
} else if (
|
||||
compatDetection.capabilities.usesExplicitProxyLikeEndpoint &&
|
||||
Array.isArray(params.tools) &&
|
||||
params.tools.length > 0
|
||||
) {
|
||||
params.tool_choice = "auto";
|
||||
}
|
||||
} else if (hasToolHistory(context.messages)) {
|
||||
params.tools = [];
|
||||
|
||||
Reference in New Issue
Block a user