Skip to content

Commit 0e7b395

Browse files
Per-Auth Method Feature Flag for Model Routing (#11333)
Co-authored-by: Abhi <[email protected]>
1 parent 81772c4 commit 0e7b395

File tree

3 files changed

+57
-13
lines changed

3 files changed

+57
-13
lines changed

packages/cli/src/config/config.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ vi.mock('@google/gemini-cli-core', async () => {
8585
const actualServer = await vi.importActual<typeof ServerConfig>(
8686
'@google/gemini-cli-core',
8787
);
88+
8889
return {
8990
...actualServer,
9091
IdeClient: {

packages/core/src/config/config.test.ts

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -574,27 +574,52 @@ describe('Server Config (config.ts)', () => {
574574
});
575575
});
576576

577-
describe('UseModelRouter Configuration', () => {
578-
it('should default useModelRouter to false when not provided', () => {
579-
const config = new Config(baseParams);
577+
describe('Model Router with Auth', () => {
578+
it('should disable model router by default for oauth-personal', async () => {
579+
const config = new Config({
580+
...baseParams,
581+
useModelRouter: true,
582+
});
583+
await config.refreshAuth(AuthType.LOGIN_WITH_GOOGLE);
580584
expect(config.getUseModelRouter()).toBe(false);
581585
});
582586

583-
it('should set useModelRouter to true when provided as true', () => {
584-
const paramsWithModelRouter: ConfigParameters = {
587+
it('should enable model router by default for other auth types', async () => {
588+
const config = new Config({
585589
...baseParams,
586590
useModelRouter: true,
587-
};
588-
const config = new Config(paramsWithModelRouter);
591+
});
592+
await config.refreshAuth(AuthType.USE_GEMINI);
593+
expect(config.getUseModelRouter()).toBe(true);
594+
});
595+
596+
it('should disable model router for specified auth type', async () => {
597+
const config = new Config({
598+
...baseParams,
599+
useModelRouter: true,
600+
disableModelRouterForAuth: [AuthType.USE_GEMINI],
601+
});
602+
await config.refreshAuth(AuthType.USE_GEMINI);
603+
expect(config.getUseModelRouter()).toBe(false);
604+
});
605+
606+
it('should enable model router for other auth type', async () => {
607+
const config = new Config({
608+
...baseParams,
609+
useModelRouter: true,
610+
disableModelRouterForAuth: [],
611+
});
612+
await config.refreshAuth(AuthType.LOGIN_WITH_GOOGLE);
589613
expect(config.getUseModelRouter()).toBe(true);
590614
});
591615

592-
it('should set useModelRouter to false when explicitly provided as false', () => {
593-
const paramsWithModelRouter: ConfigParameters = {
616+
it('should keep model router disabled when useModelRouter is false', async () => {
617+
const config = new Config({
594618
...baseParams,
595619
useModelRouter: false,
596-
};
597-
const config = new Config(paramsWithModelRouter);
620+
disableModelRouterForAuth: [AuthType.USE_GEMINI],
621+
});
622+
await config.refreshAuth(AuthType.LOGIN_WITH_GOOGLE);
598623
expect(config.getUseModelRouter()).toBe(false);
599624
});
600625
});

packages/core/src/config/config.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
DEFAULT_GEMINI_EMBEDDING_MODEL,
4848
DEFAULT_GEMINI_FLASH_MODEL,
4949
DEFAULT_GEMINI_MODEL,
50+
DEFAULT_GEMINI_MODEL_AUTO,
5051
DEFAULT_THINKING_MODE,
5152
} from './models.js';
5253
import { shouldAttemptBrowserLaunch } from '../utils/browser.js';
@@ -278,6 +279,7 @@ export interface ConfigParameters {
278279
policyEngineConfig?: PolicyEngineConfig;
279280
output?: OutputSettings;
280281
useModelRouter?: boolean;
282+
disableModelRouterForAuth?: AuthType[];
281283
enableMessageBusIntegration?: boolean;
282284
codebaseInvestigatorSettings?: CodebaseInvestigatorSettings;
283285
continueOnFailedApiCall?: boolean;
@@ -374,7 +376,9 @@ export class Config {
374376
private readonly messageBus: MessageBus;
375377
private readonly policyEngine: PolicyEngine;
376378
private readonly outputSettings: OutputSettings;
377-
private readonly useModelRouter: boolean;
379+
private useModelRouter: boolean;
380+
private readonly initialUseModelRouter: boolean;
381+
private readonly disableModelRouterForAuth?: AuthType[];
378382
private readonly enableMessageBusIntegration: boolean;
379383
private readonly codebaseInvestigatorSettings: CodebaseInvestigatorSettings;
380384
private readonly continueOnFailedApiCall: boolean;
@@ -470,7 +474,11 @@ export class Config {
470474
this.enableToolOutputTruncation = params.enableToolOutputTruncation ?? true;
471475
this.useSmartEdit = params.useSmartEdit ?? true;
472476
this.useWriteTodos = params.useWriteTodos ?? false;
473-
this.useModelRouter = params.useModelRouter ?? false;
477+
this.initialUseModelRouter = params.useModelRouter ?? false;
478+
this.useModelRouter = this.initialUseModelRouter;
479+
this.disableModelRouterForAuth = params.disableModelRouterForAuth ?? [
480+
AuthType.LOGIN_WITH_GOOGLE,
481+
];
474482
this.enableMessageBusIntegration =
475483
params.enableMessageBusIntegration ?? false;
476484
this.codebaseInvestigatorSettings = {
@@ -541,6 +549,16 @@ export class Config {
541549
}
542550

543551
async refreshAuth(authMethod: AuthType) {
552+
this.useModelRouter = this.initialUseModelRouter;
553+
if (this.disableModelRouterForAuth?.includes(authMethod)) {
554+
this.useModelRouter = false;
555+
if (this.model === DEFAULT_GEMINI_MODEL_AUTO) {
556+
this.model = DEFAULT_GEMINI_MODEL;
557+
}
558+
} else {
559+
this.model = DEFAULT_GEMINI_MODEL_AUTO;
560+
}
561+
544562
// Vertex and Genai have incompatible encryption and sending history with
545563
// thoughtSignature from Genai to Vertex will fail, we need to strip them
546564
if (

0 commit comments

Comments
 (0)