Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
34 changes: 34 additions & 0 deletions apps/web/src/lib/ai-gateway/auto-model/index.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
24 changes: 22 additions & 2 deletions apps/web/src/lib/ai-gateway/auto-model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Mode, ResolvedAutoModel> = {
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',
Expand Down
8 changes: 6 additions & 2 deletions apps/web/src/lib/ai-gateway/auto-model/resolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down