From 3ec8936e953e2bd347ea3258dfa229beab3fc096 Mon Sep 17 00:00:00 2001 From: Josh Lambert Date: Thu, 28 May 2026 11:43:39 -0400 Subject: [PATCH] feat(auto-model): route Balanced Opus modes to Qwen3.7 Max --- .../lib/ai-gateway/auto-model/index.test.ts | 34 +++++++++++++++++++ .../src/lib/ai-gateway/auto-model/index.ts | 24 +++++++++++-- .../lib/ai-gateway/auto-model/resolution.ts | 8 +++-- 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 apps/web/src/lib/ai-gateway/auto-model/index.test.ts diff --git a/apps/web/src/lib/ai-gateway/auto-model/index.test.ts b/apps/web/src/lib/ai-gateway/auto-model/index.test.ts new file mode 100644 index 0000000000..73bff08adc --- /dev/null +++ b/apps/web/src/lib/ai-gateway/auto-model/index.test.ts @@ -0,0 +1,34 @@ +import { describe, expect, test } from '@jest/globals'; +import { + CLAUDE_OPUS_CURRENT_MODEL_ID, + CLAUDE_SONNET_CURRENT_MODEL_ID, +} from '@/lib/ai-gateway/providers/anthropic.constants'; +import { qwen36_plus_model, qwen37_max_model } from '@/lib/ai-gateway/providers/qwen'; +import { + BALANCED_CODE_MODEL, + BALANCED_MODE_TO_MODEL, + FRONTIER_CODE_MODEL, + FRONTIER_MODE_TO_MODEL, + modeSchema, +} from '@/lib/ai-gateway/auto-model'; + +describe('Auto Balanced model routing', () => { + test('uses Qwen3.7 Max in modes where Auto Frontier uses Claude Opus', () => { + for (const mode of modeSchema.options) { + const frontierModel = FRONTIER_MODE_TO_MODEL[mode].model; + const balancedModel = BALANCED_MODE_TO_MODEL[mode].model; + + if (frontierModel === CLAUDE_OPUS_CURRENT_MODEL_ID) { + expect(balancedModel).toBe(qwen37_max_model.public_id); + } else { + expect(frontierModel).toBe(CLAUDE_SONNET_CURRENT_MODEL_ID); + expect(balancedModel).toBe(qwen36_plus_model.public_id); + } + } + }); + + test('keeps Qwen3.6 Plus for the Sonnet-aligned default route', () => { + expect(FRONTIER_CODE_MODEL.model).toBe(CLAUDE_SONNET_CURRENT_MODEL_ID); + expect(BALANCED_CODE_MODEL.model).toBe(qwen36_plus_model.public_id); + }); +}); diff --git a/apps/web/src/lib/ai-gateway/auto-model/index.ts b/apps/web/src/lib/ai-gateway/auto-model/index.ts index 2d23f386a0..795f675bc5 100644 --- a/apps/web/src/lib/ai-gateway/auto-model/index.ts +++ b/apps/web/src/lib/ai-gateway/auto-model/index.ts @@ -6,7 +6,7 @@ import { } from '@/lib/ai-gateway/providers/anthropic.constants'; import type { OpenRouterReasoningConfig } from '@/lib/ai-gateway/providers/openrouter/types'; import type { OpenCodeSettings, Verbosity } from '@kilocode/db/schema-types'; -import { qwen36_plus_model } from '@/lib/ai-gateway/providers/qwen'; +import { qwen36_plus_model, qwen37_max_model } from '@/lib/ai-gateway/providers/qwen'; type AutoModel = { id: string; @@ -92,11 +92,31 @@ export const BALANCED_CLAW_SETUP_MODEL: ResolvedAutoModel = { verbosity: 'high', }; -export const BALANCED_QWEN_MODEL: ResolvedAutoModel = { +const QWEN_MAX_BALANCED: ResolvedAutoModel = { + model: qwen37_max_model.public_id, + reasoning: { enabled: true }, +}; + +const QWEN_PLUS_BALANCED: ResolvedAutoModel = { model: qwen36_plus_model.public_id, reasoning: { enabled: true }, }; +export const BALANCED_CODE_MODEL: ResolvedAutoModel = QWEN_PLUS_BALANCED; + +export const BALANCED_MODE_TO_MODEL: Record = { + claw: QWEN_MAX_BALANCED, + plan: QWEN_MAX_BALANCED, + general: QWEN_MAX_BALANCED, + architect: QWEN_MAX_BALANCED, + orchestrator: QWEN_MAX_BALANCED, + ask: QWEN_MAX_BALANCED, + debug: QWEN_MAX_BALANCED, + build: QWEN_PLUS_BALANCED, + explore: QWEN_PLUS_BALANCED, + code: QWEN_PLUS_BALANCED, +}; + export const KILO_AUTO_FRONTIER_MODEL: AutoModel = { id: 'kilo-auto/frontier', name: 'Auto Frontier', diff --git a/apps/web/src/lib/ai-gateway/auto-model/resolution.ts b/apps/web/src/lib/ai-gateway/auto-model/resolution.ts index 87a4a408b1..9c55db2f07 100644 --- a/apps/web/src/lib/ai-gateway/auto-model/resolution.ts +++ b/apps/web/src/lib/ai-gateway/auto-model/resolution.ts @@ -15,7 +15,8 @@ import { KILO_AUTO_BALANCED_MODEL, modeSchema, BALANCED_CLAW_SETUP_MODEL, - BALANCED_QWEN_MODEL, + BALANCED_MODE_TO_MODEL, + BALANCED_CODE_MODEL, BALANCED_RESPONSES_FALLBACK_MODEL, FRONTIER_MODE_TO_MODEL, FRONTIER_CODE_MODEL, @@ -136,7 +137,10 @@ export async function resolveAutoModel( } else if (apiKind === 'messages') { return { kind: 'ok', resolved: BALANCED_MESSAGES_FALLBACK_MODEL }; } else { - return { kind: 'ok', resolved: BALANCED_QWEN_MODEL }; + return { + kind: 'ok', + resolved: (mode !== null ? BALANCED_MODE_TO_MODEL[mode] : null) ?? BALANCED_CODE_MODEL, + }; } } return {