Merge fe8f06db4e608f74445c37ea0642b21def20f542 into 8a05c05596ca9ba0735dafd8e359885de4c2c969

This commit is contained in:
Ali Shahed 2026-03-20 22:59:23 -07:00 committed by GitHub
commit 96af01eeb5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 43 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import type { Model } from "@mariozechner/pi-ai";
import { afterEach, describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../../config/config.js";
import { captureEnv } from "../../test-utils/env.js";
import { runExtraParamsCase } from "./extra-params.test-support.js";
@ -93,3 +94,35 @@ describe("extra-params: OpenAI attribution", () => {
});
});
});
describe("extra-params: tool choice forwarding", () => {
it("forwards tool_choice from agent model params into stream options", () => {
const cfg = {
agents: {
defaults: {
models: {
"openai/gpt-5.4": {
params: {
tool_choice: "required",
},
},
},
},
},
} satisfies OpenClawConfig;
const capture = runExtraParamsCase({
applyModelId: "gpt-5.4",
applyProvider: "openai",
cfg,
model: {
api: "openai-completions",
provider: "openai",
id: "gpt-5.4",
} as Model<"openai-completions">,
payload: {},
});
expect((capture.options as { toolChoice?: string } | undefined)?.toolChoice).toBe("required");
});
});

View File

@ -5,6 +5,7 @@ import { applyExtraParamsToAgent } from "./extra-params.js";
export type ExtraParamsCapture<TPayload extends Record<string, unknown>> = {
headers?: Record<string, string>;
options?: SimpleStreamOptions;
payload: TPayload;
};
@ -32,6 +33,7 @@ export function runExtraParamsCase<
const baseStreamFn: StreamFn = (model, _context, options) => {
captured.headers = options?.headers;
captured.options = options;
options?.onPayload?.(params.payload, model);
return {} as ReturnType<StreamFn>;
};

View File

@ -90,6 +90,14 @@ function createStreamFnWithExtraParams(
if (typeof extraParams.maxTokens === "number") {
streamParams.maxTokens = extraParams.maxTokens;
}
const resolvedToolChoice = resolveAliasedParamValue(
[extraParams],
"tool_choice",
"toolChoice",
);
if (resolvedToolChoice !== undefined) {
streamParams.toolChoice = resolvedToolChoice as CacheRetentionStreamOptions["toolChoice"];
}
const transport = extraParams.transport;
if (transport === "sse" || transport === "websocket" || transport === "auto") {
streamParams.transport = transport;