Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions docs/users/configuration/model-providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -583,14 +583,14 @@ The optional `reasoning` field under `generationConfig` controls how aggressivel

### Per-provider behavior

| Protocol / provider | Wire shape | Notes |
| ------------------------------------------------------------- | -------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **OpenAI / DashScope** (`qwen3.8-max`, `qwen3.8-max-preview`) | Flat `reasoning_effort: <effort>` body parameter | The five `/effort` tiers (`low`, `medium`, `high`, `xhigh`, `max`) are passed through verbatim; DashScope applies any model-specific mapping. Do not also configure `thinking_budget`, because DashScope rejects requests containing both fields. Other Qwen models continue to map a selected effort to `enable_thinking: true`. |
| **OpenAI / DeepSeek** (`api.deepseek.com`) | Flat `reasoning_effort: <effort>` body parameter | When `reasoning.effort` is set in the nested config shape, it's rewritten to flat `reasoning_effort` and `'low'`/`'medium'` are normalized to `'high'`, `'xhigh'` to `'max'` — mirroring DeepSeek's [server-side back-compat](https://api-docs.deepseek.com/zh-cn/api/create-chat-completion). Top-level `samplingParams.reasoning_effort` or `extra_body.reasoning_effort` overrides skip this normalization and ship verbatim. |
| **OpenAI** (other compatible servers) | `reasoning: { effort, ... }` passed through verbatim | Set via `samplingParams` (e.g. `samplingParams.reasoning_effort` for GPT-5/o-series) when the provider expects a different shape. |
| **Anthropic** (real `api.anthropic.com`) | `output_config: { effort }` plus the `effort-2025-11-24` beta header | Real Anthropic accepts `'low'`/`'medium'`/`'high'` only. `'max'` is **clamped to `'high'`** with a `debugLogger.warn` line (once per generator); if you want max effort, switch the baseURL to a DeepSeek-compatible endpoint that supports it. |
| **Anthropic** (`api.deepseek.com/anthropic`) | Same `output_config: { effort }` + beta header | `'max'` is passed through unchanged. |
| **Gemini** (`@google/genai`) | `thinkingConfig: { includeThoughts: true, thinkingLevel }` | `'low'` → `LOW`, `'high'`/`'max'` → `HIGH`, others → `THINKING_LEVEL_UNSPECIFIED` (Gemini has no `MAX` tier). |
| Protocol / provider | Wire shape | Notes |
| --------------------------------------------- | -------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **OpenAI / DashScope** (`qwen3.8-max` family) | Flat `reasoning_effort: <effort>` body parameter | The five `/effort` tiers (`low`, `medium`, `high`, `xhigh`, `max`) are passed through verbatim for any model id starting with `qwen3.8-max` (including dated snapshots and `-latest` aliases); DashScope applies any model-specific mapping. A configured `thinking_budget` is dropped whenever an effort tier ships, because DashScope rejects requests containing both fields. Other Qwen models continue to map a selected effort to `enable_thinking: true`. |
| **OpenAI / DeepSeek** (`api.deepseek.com`) | Flat `reasoning_effort: <effort>` body parameter | When `reasoning.effort` is set in the nested config shape, it's rewritten to flat `reasoning_effort` and `'low'`/`'medium'` are normalized to `'high'`, `'xhigh'` to `'max'` — mirroring DeepSeek's [server-side back-compat](https://api-docs.deepseek.com/zh-cn/api/create-chat-completion). Top-level `samplingParams.reasoning_effort` or `extra_body.reasoning_effort` overrides skip this normalization and ship verbatim. |
| **OpenAI** (other compatible servers) | `reasoning: { effort, ... }` passed through verbatim | Set via `samplingParams` (e.g. `samplingParams.reasoning_effort` for GPT-5/o-series) when the provider expects a different shape. |
| **Anthropic** (real `api.anthropic.com`) | `output_config: { effort }` plus the `effort-2025-11-24` beta header | Real Anthropic accepts `'low'`/`'medium'`/`'high'` only. `'max'` is **clamped to `'high'`** with a `debugLogger.warn` line (once per generator); if you want max effort, switch the baseURL to a DeepSeek-compatible endpoint that supports it. |
| **Anthropic** (`api.deepseek.com/anthropic`) | Same `output_config: { effort }` + beta header | `'max'` is passed through unchanged. |
| **Gemini** (`@google/genai`) | `thinkingConfig: { includeThoughts: true, thinkingLevel }` | `'low'` → `LOW`, `'high'`/`'max'` → `HIGH`, others → `THINKING_LEVEL_UNSPECIFIED` (Gemini has no `MAX` tier). |

### `reasoning: false`

Expand Down
34 changes: 34 additions & 0 deletions packages/core/src/core/openaiContentGenerator/pipeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,18 @@ describe('ContentGenerationPipeline', () => {
expectedThinking: undefined,
expectedToolChoice: 'required',
},
{
name: 'preserve required tool selection for a non-qwen model with a user reasoning_effort',
baseUrl:
'https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1',
model: 'glm-5.2',
extraBody: { reasoning_effort: 'high' },
thinkingMandatory: undefined,
reasoning: undefined,
includeThoughts: true,
expectedThinking: undefined,
expectedToolChoice: 'required',
},
{
name: 'preserve required tool selection when thinking is not enabled',
baseUrl: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
Expand All @@ -766,6 +778,28 @@ describe('ContentGenerationPipeline', () => {
expectedThinking: undefined,
expectedToolChoice: 'required',
},
{
name: 'strip the effort tier under the config-level reasoning opt-out',
baseUrl: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
model: 'qwen3.8-max',
extraBody: { reasoning_effort: 'high' },
thinkingMandatory: undefined,
reasoning: false,
includeThoughts: true,
expectedThinking: false,
expectedToolChoice: 'required',
},
{
name: 'strip the effort tier under the per-request thinking opt-out',
baseUrl: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
model: 'qwen3.8-max',
extraBody: { reasoning_effort: 'high' },
thinkingMandatory: undefined,
reasoning: undefined,
includeThoughts: false,
expectedThinking: false,
expectedToolChoice: 'required',
},
{
name: 'never emit the disable even under the reasoning opt-out',
baseUrl:
Expand Down
14 changes: 12 additions & 2 deletions packages/core/src/core/openaiContentGenerator/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,14 +959,24 @@ export class ContentGenerationPipeline {

const typed = providerRequest as unknown as Record<string, unknown>;
const reasoningEffort = typed['reasoning_effort'];
// DashScope rejects forced tool selection while thinking is enabled.
// DashScope rejects forced tool selection while thinking is enabled. The
// `reasoning_effort` clause is family-gated like the disable path above:
// on non-qwen models sharing the DashScope endpoint it is an opaque
// sampling override, not a thinking switch, and dropping `required`
// there would degrade their forced-tool side queries.
if (
isDashScope &&
typed['tool_choice'] === 'required' &&
(thinkingMandatory ||
typed['enable_thinking'] === true ||
(typeof reasoningEffort === 'string' && reasoningEffort !== 'none'))
((model.startsWith('qwen') || model === 'coder-model') &&
typeof reasoningEffort === 'string' &&
reasoningEffort !== 'none'))
) {
debugLogger.debug(
'DashScope: dropping tool_choice=required while thinking is enabled',
{ model, reasoningEffort, thinkingMandatory },
);
delete typed['tool_choice'];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,146 @@ describe('DashScopeOpenAICompatibleProvider', () => {
expect(result['reasoning']).toBeUndefined();
});

it('drops the preset enable_thinking when an effort tier ships on qwen3.8-max-preview', () => {
// The Token Plan preset ships qwen3.8-max-preview with enableThinking,
// which provider-config.ts turns into extra_body.enable_thinking; the
// provider merges that extra_body last. With an effort tier selected
// the wire body must carry reasoning_effort alone — not both competing
// thinking knobs.
const generator = new DashScopeOpenAICompatibleProvider(
{
...mockContentGeneratorConfig,
model: 'qwen3.8-max-preview',
reasoning: { effort: 'high' },
extra_body: { enable_thinking: true },
} as ContentGeneratorConfig,
mockCliConfig,
);
const result = generator.buildRequest(
{
...baseRequest,
model: 'qwen3.8-max-preview',
reasoning: { effort: 'high' },
} as unknown as Parameters<typeof generator.buildRequest>[0],
'test-prompt-id',
) as unknown as Record<string, unknown>;

expect(result['reasoning_effort']).toBe('high');
expect(result['enable_thinking']).toBeUndefined();
expect(result['reasoning']).toBeUndefined();
});

it('drops enable_thinking when a request-level reasoning_effort override ships on a legacy qwen model', () => {
// A request-level reasoning_effort override can reach a legacy qwen
// model that also gets enable_thinking from the effort config; ship
// the explicit tier alone, never both knobs.
const generator = new DashScopeOpenAICompatibleProvider(
{
...mockContentGeneratorConfig,
model: 'qwen3.7-max',
reasoning: { effort: 'high' },
} as ContentGeneratorConfig,
mockCliConfig,
);
const result = generator.buildRequest(
{
...baseRequest,
model: 'qwen3.7-max',
reasoning_effort: 'max',
reasoning: { effort: 'high' },
} as unknown as Parameters<typeof generator.buildRequest>[0],
'test-prompt-id',
) as unknown as Record<string, unknown>;

expect(result['reasoning_effort']).toBe('max');
expect(result['enable_thinking']).toBeUndefined();
});

it.each(['qwen3.8-max-2026-01-15', 'qwen3.8-max-latest'])(
'passes effort through for the %s snapshot/alias id',
Comment thread
wenshao marked this conversation as resolved.
Resolved
(model) => {
const generator = new DashScopeOpenAICompatibleProvider(
{
...mockContentGeneratorConfig,
model,
reasoning: { effort: 'xhigh' },
} as ContentGeneratorConfig,
mockCliConfig,
);
const result = generator.buildRequest(
{ ...baseRequest, model },
'test-prompt-id',
) as unknown as Record<string, unknown>;

expect(result['reasoning_effort']).toBe('xhigh');
expect(result['enable_thinking']).toBeUndefined();
},
);

it('drops an extra_body thinking_budget when an effort tier ships', () => {
// DashScope rejects requests carrying both reasoning_effort and
// thinking_budget; the selected tier wins.
const generator = new DashScopeOpenAICompatibleProvider(
{
...mockContentGeneratorConfig,
model: 'qwen3.8-max',
reasoning: { effort: 'high' },
extra_body: { thinking_budget: 1024 },
} as ContentGeneratorConfig,
mockCliConfig,
);
const result = generator.buildRequest(
{ ...baseRequest, model: 'qwen3.8-max' },
'test-prompt-id',
) as unknown as Record<string, unknown>;

expect(result['reasoning_effort']).toBe('high');
expect(result['thinking_budget']).toBeUndefined();
});

it('keeps thinking_budget alongside enable_thinking on legacy qwen models', () => {
// thinking_budget + enable_thinking is a valid pair on hybrid models;
// only the reasoning_effort combination is rejected.
const generator = new DashScopeOpenAICompatibleProvider(
{
...mockContentGeneratorConfig,
model: 'qwen3.7-max',
reasoning: { effort: 'high' },
extra_body: { thinking_budget: 1024 },
} as ContentGeneratorConfig,
mockCliConfig,
);
const result = generator.buildRequest(
{ ...baseRequest, model: 'qwen3.7-max' },
'test-prompt-id',
) as unknown as Record<string, unknown>;

expect(result['enable_thinking']).toBe(true);
expect(result['thinking_budget']).toBe(1024);
});

it('vision model: drops enable_thinking when extra_body ships a reasoning_effort override', () => {
// The vision branch merges extra_body last like the text path; the
// conflicting-knob drop must apply there too.
const generator = new DashScopeOpenAICompatibleProvider(
{
...mockContentGeneratorConfig,
model: 'qwen-vl-max',
reasoning: { effort: 'high' },
extra_body: { reasoning_effort: 'max' },
} as ContentGeneratorConfig,
mockCliConfig,
);
const result = generator.buildRequest(
{ ...baseRequest, model: 'qwen-vl-max' },
'test-prompt-id',
) as unknown as Record<string, unknown>;

expect(result['reasoning_effort']).toBe('max');
expect(result['enable_thinking']).toBeUndefined();
expect(result['vl_high_resolution_images']).toBe(true);
});

it('strips the pipeline-injected nested reasoning when enable_thinking is added on a qwen model', () => {
// The pipeline injects a nested `reasoning: { effort }` object for
// OpenAI-compatible endpoints. qwen drives thinking via `enable_thinking`,
Expand Down
Loading
Loading