fix(agents): normalize SiliconFlow Pro thinking=off payload (#25435)

Land PR #25435 from @Zjianru.
Changelog: add 2026.2.24 fix entry with contributor credit.

Co-authored-by: codez <codezhujr@gmail.com>
This commit is contained in:
Peter Steinberger
2026-02-25 01:11:20 +00:00
parent 8470dff619
commit bd213cf2ad
3 changed files with 106 additions and 0 deletions

View File

@@ -408,6 +408,42 @@ function mapThinkingLevelToOpenRouterReasoningEffort(
return thinkingLevel;
}
function shouldApplySiliconFlowThinkingOffCompat(params: {
provider: string;
modelId: string;
thinkingLevel?: ThinkLevel;
}): boolean {
return (
params.provider === "siliconflow" &&
params.thinkingLevel === "off" &&
params.modelId.startsWith("Pro/")
);
}
/**
* SiliconFlow's Pro/* models reject string thinking modes (including "off")
* with HTTP 400 invalid-parameter errors. Normalize to `thinking: null` to
* preserve "thinking disabled" intent without sending an invalid enum value.
*/
function createSiliconFlowThinkingWrapper(baseStreamFn: StreamFn | undefined): StreamFn {
const underlying = baseStreamFn ?? streamSimple;
return (model, context, options) => {
const originalOnPayload = options?.onPayload;
return underlying(model, context, {
...options,
onPayload: (payload) => {
if (payload && typeof payload === "object") {
const payloadObj = payload as Record<string, unknown>;
if (payloadObj.thinking === "off") {
payloadObj.thinking = null;
}
}
originalOnPayload?.(payload);
},
});
};
}
/**
* Create a streamFn wrapper that adds OpenRouter app attribution headers
* and injects reasoning.effort based on the configured thinking level.
@@ -544,6 +580,13 @@ export function applyExtraParamsToAgent(
agent.streamFn = createAnthropicBetaHeadersWrapper(agent.streamFn, anthropicBetas);
}
if (shouldApplySiliconFlowThinkingOffCompat({ provider, modelId, thinkingLevel })) {
log.debug(
`normalizing thinking=off to thinking=null for SiliconFlow compatibility (${provider}/${modelId})`,
);
agent.streamFn = createSiliconFlowThinkingWrapper(agent.streamFn);
}
if (provider === "openrouter") {
log.debug(`applying OpenRouter app attribution headers for ${provider}/${modelId}`);
// "auto" is a dynamic routing model — we don't know which underlying model