diff --git a/packages/core/src/core/openaiContentGenerator/pipeline.test.ts b/packages/core/src/core/openaiContentGenerator/pipeline.test.ts index d3e8b03276..5c699a45e2 100644 --- a/packages/core/src/core/openaiContentGenerator/pipeline.test.ts +++ b/packages/core/src/core/openaiContentGenerator/pipeline.test.ts @@ -722,6 +722,28 @@ describe('ContentGenerationPipeline', () => { expectedThinking: true, expectedToolChoice: undefined, }, + { + name: 'remove required tool selection when thinking is enabled on the wire', + baseUrl: 'https://dashscope.aliyuncs.com/compatible-mode/v1', + model: 'qwen3.7-max', + extraBody: { enable_thinking: true }, + thinkingMandatory: undefined, + reasoning: undefined, + includeThoughts: true, + expectedThinking: true, + expectedToolChoice: undefined, + }, + { + name: 'preserve required tool selection when thinking is not enabled', + baseUrl: 'https://dashscope.aliyuncs.com/compatible-mode/v1', + model: 'qwen3.7-max', + extraBody: undefined, + thinkingMandatory: undefined, + reasoning: undefined, + includeThoughts: true, + expectedThinking: undefined, + expectedToolChoice: 'required', + }, { name: 'never emit the disable even under the reasoning opt-out', baseUrl: diff --git a/packages/core/src/core/openaiContentGenerator/pipeline.ts b/packages/core/src/core/openaiContentGenerator/pipeline.ts index 04b9837a43..1614f5fcbf 100644 --- a/packages/core/src/core/openaiContentGenerator/pipeline.ts +++ b/packages/core/src/core/openaiContentGenerator/pipeline.ts @@ -955,10 +955,16 @@ export class ContentGenerationPipeline { delete typed['chat_template_kwargs']; } } - // DashScope rejects forced tool selection while thinking is enabled. - if (isDashScope && typed['tool_choice'] === 'required') { - delete typed['tool_choice']; - } + } + + const typed = providerRequest as unknown as Record; + // DashScope rejects forced tool selection while thinking is enabled. + if ( + isDashScope && + typed['tool_choice'] === 'required' && + (thinkingMandatory || typed['enable_thinking'] === true) + ) { + delete typed['tool_choice']; } return providerRequest;