From 9d19eafa977f5e5bc6992d40d2ae3e143c87ca98 Mon Sep 17 00:00:00 2001 From: hogeheer499-commits Date: Sun, 26 Jul 2026 02:16:13 +0200 Subject: [PATCH] fix(core): avoid required tools in DashScope thinking (#7661) Co-authored-by: JS van Dijk <267467744+hogeheer499-commits@users.noreply.github.com> --- .../openaiContentGenerator/pipeline.test.ts | 22 +++++++++++++++++++ .../core/openaiContentGenerator/pipeline.ts | 14 ++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) 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;