Skip to content

Commit 8a37391

Browse files
author
ai-hpc
committed
fix(agents): quiet extra_body tuning-key collisions
1 parent 301213a commit 8a37391

2 files changed

Lines changed: 71 additions & 3 deletions

File tree

src/agents/embedded-agent-runner-extraparams.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,68 @@ describe("applyExtraParamsToAgent", () => {
12841284
expect(payload).not.toHaveProperty("store");
12851285
});
12861286

1287+
it("applies extra_body tuning-key overrides without warning", () => {
1288+
const warnSpy = vi.spyOn(log, "warn").mockImplementation(() => {});
1289+
try {
1290+
const payload = runResponsesPayloadMutationCase({
1291+
applyProvider: "deepseek",
1292+
applyModelId: "deepseek-chat",
1293+
extraParamsOverride: {
1294+
extra_body: {
1295+
thinking: { type: "disabled" },
1296+
},
1297+
},
1298+
model: {
1299+
api: "openai-completions",
1300+
provider: "deepseek",
1301+
id: "deepseek-chat",
1302+
baseUrl: "https://api.deepseek.com/v1",
1303+
} as Model<"openai-completions">,
1304+
payload: {
1305+
messages: [],
1306+
model: "deepseek-chat",
1307+
thinking: { type: "enabled" },
1308+
},
1309+
});
1310+
1311+
expect(payload.thinking).toEqual({ type: "disabled" });
1312+
expect(warnSpy).not.toHaveBeenCalled();
1313+
} finally {
1314+
warnSpy.mockRestore();
1315+
}
1316+
});
1317+
1318+
it("warns when extra_body overrides framework-managed request scaffolding", () => {
1319+
const warnSpy = vi.spyOn(log, "warn").mockImplementation(() => {});
1320+
try {
1321+
runResponsesPayloadMutationCase({
1322+
applyProvider: "deepseek",
1323+
applyModelId: "deepseek-chat",
1324+
extraParamsOverride: {
1325+
extra_body: {
1326+
model: "rogue-model",
1327+
},
1328+
},
1329+
model: {
1330+
api: "openai-completions",
1331+
provider: "deepseek",
1332+
id: "deepseek-chat",
1333+
baseUrl: "https://api.deepseek.com/v1",
1334+
} as Model<"openai-completions">,
1335+
payload: {
1336+
messages: [],
1337+
model: "deepseek-chat",
1338+
},
1339+
});
1340+
1341+
expect(warnSpy).toHaveBeenCalledWith(
1342+
expect.stringContaining("framework-managed request keys: model"),
1343+
);
1344+
} finally {
1345+
warnSpy.mockRestore();
1346+
}
1347+
});
1348+
12871349
it("forwards chat_template_kwargs params as top-level openai-completions payload fields", () => {
12881350
const payload = runResponsesPayloadMutationCase({
12891351
applyProvider: "vllm",

src/agents/embedded-agent-runner/extra-params.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,8 @@ function createOpenAICompletionsChatTemplateKwargsWrapper(params: {
752752
};
753753
}
754754

755+
const FRAMEWORK_MANAGED_EXTRA_BODY_KEYS = new Set(["messages", "model", "stream"]);
756+
755757
function createOpenAICompletionsExtraBodyWrapper(
756758
baseStreamFn: StreamFn | undefined,
757759
extraBody: Record<string, unknown>,
@@ -762,9 +764,13 @@ function createOpenAICompletionsExtraBodyWrapper(
762764
return underlying(model, context, options);
763765
}
764766
return streamWithPayloadPatch(underlying, model, context, options, (payloadObj) => {
765-
const collisions = Object.keys(extraBody).filter((key) => Object.hasOwn(payloadObj, key));
766-
if (collisions.length > 0) {
767-
log.warn(`extra_body overwriting request payload keys: ${collisions.join(", ")}`);
767+
const clobberedManagedKeys = Object.keys(extraBody).filter(
768+
(key) => Object.hasOwn(payloadObj, key) && FRAMEWORK_MANAGED_EXTRA_BODY_KEYS.has(key),
769+
);
770+
if (clobberedManagedKeys.length > 0) {
771+
log.warn(
772+
`extra_body overrides framework-managed request keys: ${clobberedManagedKeys.join(", ")}`,
773+
);
768774
}
769775
Object.assign(payloadObj, extraBody);
770776
});

0 commit comments

Comments
 (0)