fix(core): avoid required tools in DashScope thinking (#7661)

Co-authored-by: JS van Dijk <267467744+hogeheer499-commits@users.noreply.github.com>
This commit is contained in:
hogeheer499-commits 2026-07-26 02:16:13 +02:00 committed by GitHub
parent ecd86421c5
commit 9d19eafa97
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 4 deletions

View file

@ -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:

View file

@ -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<string, unknown>;
// 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;