Skip to content

Commit bf278ef

Browse files
authored
feat(plan): support automatic model switching for Plan Mode (google-gemini#20240)
1 parent 1f9da67 commit bf278ef

19 files changed

Lines changed: 422 additions & 31 deletions

File tree

docs/cli/plan-mode.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ implementation. It allows you to:
2727
- [Example: Allow git commands in Plan Mode](#example-allow-git-commands-in-plan-mode)
2828
- [Example: Enable research subagents in Plan Mode](#example-enable-research-subagents-in-plan-mode)
2929
- [Custom Plan Directory and Policies](#custom-plan-directory-and-policies)
30+
- [Automatic Model Routing](#automatic-model-routing)
3031

3132
## Enabling Plan Mode
3233

@@ -242,6 +243,32 @@ modes = ["plan"]
242243
argsPattern = "\"file_path\":\"[^\"]+[\\\\/]+\\.gemini[\\\\/]+plans[\\\\/]+[\\w-]+\\.md\""
243244
```
244245

246+
## Automatic Model Routing
247+
248+
When using an [**auto model**], Gemini CLI automatically optimizes [**model
249+
routing**] based on the current phase of your task:
250+
251+
1. **Planning Phase:** While in Plan Mode, the CLI routes requests to a
252+
high-reasoning **Pro** model to ensure robust architectural decisions and
253+
high-quality plans.
254+
2. **Implementation Phase:** Once a plan is approved and you exit Plan Mode,
255+
the CLI detects the existence of the approved plan and automatically
256+
switches to a high-speed **Flash** model. This provides a faster, more
257+
responsive experience during the implementation of the plan.
258+
259+
This behavior is enabled by default to provide the best balance of quality and
260+
performance. You can disable this automatic switching in your settings:
261+
262+
```json
263+
{
264+
"general": {
265+
"plan": {
266+
"modelRouting": false
267+
}
268+
}
269+
}
270+
```
271+
245272
[`list_directory`]: /docs/tools/file-system.md#1-list_directory-readfolder
246273
[`read_file`]: /docs/tools/file-system.md#2-read_file-readfile
247274
[`grep_search`]: /docs/tools/file-system.md#5-grep_search-searchtext
@@ -259,3 +286,5 @@ argsPattern = "\"file_path\":\"[^\"]+[\\\\/]+\\.gemini[\\\\/]+plans[\\\\/]+[\\w-
259286
[YOLO mode]: /docs/reference/configuration.md#command-line-arguments
260287
[`plan.toml`]:
261288
https://github.com/google-gemini/gemini-cli/blob/main/packages/core/src/policy/policies/plan.toml
289+
[auto model]: /docs/reference/configuration.md#model-settings
290+
[model routing]: /docs/cli/telemetry.md#model-routing

docs/cli/settings.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ they appear in the UI.
2929
| Enable Auto Update | `general.enableAutoUpdate` | Enable automatic updates. | `true` |
3030
| Enable Notifications | `general.enableNotifications` | Enable run-event notifications for action-required prompts and session completion. Currently macOS only. | `false` |
3131
| Plan Directory | `general.plan.directory` | The directory where planning artifacts are stored. If not specified, defaults to the system temporary directory. | `undefined` |
32+
| Plan Model Routing | `general.plan.modelRouting` | Automatically switch between Pro and Flash models based on Plan Mode status. Uses Pro for the planning phase and Flash for the implementation phase. | `true` |
3233
| Max Chat Model Attempts | `general.maxAttempts` | Maximum number of attempts for requests to the main chat model. Cannot exceed 10. | `10` |
3334
| Debug Keystroke Logging | `general.debugKeystrokeLogging` | Enable debug logging of keystrokes to the console. | `false` |
3435
| Enable Session Cleanup | `general.sessionRetention.enabled` | Enable automatic session cleanup | `false` |

docs/cli/telemetry.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ Captures Gemini API requests, responses, and errors.
487487
- `reasoning` (string, optional)
488488
- `failed` (boolean)
489489
- `error_message` (string, optional)
490+
- `approval_mode` (string)
490491
491492
#### Chat and streaming
492493
@@ -711,12 +712,14 @@ Routing latency/failures and slash-command selections.
711712
- **Attributes**:
712713
- `routing.decision_model` (string)
713714
- `routing.decision_source` (string)
715+
- `routing.approval_mode` (string)
714716
715717
- `gemini_cli.model_routing.failure.count` (Counter, Int): Counts model routing
716718
failures.
717719
- **Attributes**:
718720
- `routing.decision_source` (string)
719721
- `routing.error_message` (string)
722+
- `routing.approval_mode` (string)
720723
721724
##### Agent runs
722725

docs/reference/configuration.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ their corresponding top-level category object in your `settings.json` file.
137137
- **Default:** `undefined`
138138
- **Requires restart:** Yes
139139

140+
- **`general.plan.modelRouting`** (boolean):
141+
- **Description:** Automatically switch between Pro and Flash models based on
142+
Plan Mode status. Uses Pro for the planning phase and Flash for the
143+
implementation phase.
144+
- **Default:** `true`
145+
140146
- **`general.retryFetchErrors`** (boolean):
141147
- **Description:** Retry on "exception TypeError: fetch failed sending
142148
request" errors.

packages/cli/src/config/settingsSchema.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,16 @@ const SETTINGS_SCHEMA = {
285285
'The directory where planning artifacts are stored. If not specified, defaults to the system temporary directory.',
286286
showInDialog: true,
287287
},
288+
modelRouting: {
289+
type: 'boolean',
290+
label: 'Plan Model Routing',
291+
category: 'General',
292+
requiresRestart: false,
293+
default: true,
294+
description:
295+
'Automatically switch between Pro and Flash models based on Plan Mode status. Uses Pro for the planning phase and Flash for the implementation phase.',
296+
showInDialog: true,
297+
},
288298
},
289299
},
290300
retryFetchErrors: {

packages/cli/src/test-utils/mockConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export const createMockConfig = (overrides: Partial<Config> = {}): Config =>
4747
setRemoteAdminSettings: vi.fn(),
4848
isYoloModeDisabled: vi.fn(() => false),
4949
isPlanEnabled: vi.fn(() => false),
50+
getPlanModeRoutingEnabled: vi.fn().mockResolvedValue(true),
51+
getApprovedPlanPath: vi.fn(() => undefined),
5052
getCoreTools: vi.fn(() => []),
5153
getAllowedTools: vi.fn(() => []),
5254
getApprovalMode: vi.fn(() => 'default'),

0 commit comments

Comments
 (0)