Skip to content

Gemini thinkingBudget defaults to 0, which is incompatible with some models like Gemini 2.5 Pro #7735

Description

@warmboi

Plugin Type

VSCode Extension

Cline Version

3.38.0

What happened?

Problem Description

When using Gemini models through the GeminiHandler, the thinkingBudget parameter in the API request defaults to 0. This is because the _thinkingBudget variable in src/core/api/providers/gemini.ts is initialized with this.options.thinkingBudgetTokens ?? 0.

// file: src/core/api/providers/gemini.ts

// ...
// Configure thinking budget if supported
const _thinkingBudget = this.options.thinkingBudgetTokens ?? 0;
// ...

This default value of 0 causes issues because it's not a valid setting for all models. For example, according to the official documentation, Gemini 2.5 Pro does not support disabling thinking and requires a thinkingBudget between 128 and 32768, or -1 for dynamic allocation. Sending 0 to this model is incorrect.

For other models like Gemini 2.5 Flash Lite, the default behavior is no thinking, so 0 is acceptable. However, having a single static default for all models is problematic.

Suggested Solution

The default value for thinkingBudget should be set dynamically based on the selected model to ensure compatibility and leverage the best default behavior for each.

A more robust implementation would be to check the model ID and set the default thinkingBudget accordingly:

// file: src/core/api/providers/gemini.ts (Proposed Change)

let _thinkingBudget: number;
if (options.thinkingBudgetTokens !== undefined) {
    _thinkingBudget = options.thinkingBudgetTokens;
} else {
    // Default behavior based on model, see https://ai.google.dev/gemini-api/docs/thinking#supported-models
    switch (modelId) {
        case GeminiModelId.GEMINI_2_5_PRO:
        case GeminiModelId.GEMINI_2_5_FLASH:
            _thinkingBudget = -1; // Default to dynamic thinking
            break;
        default:
            _thinkingBudget = 0; // Default to off for other models like Flash Lite
            break;
    }
}

This change ensures that:

  • Gemini 2.5 Pro and Flash default to dynamic thinking (-1), which is their recommended behavior.
  • Other models, like Flash Lite, default to 0, preserving their standard behavior.
  • Users can still explicitly override this by setting thinkingBudgetTokens.

References

Steps to reproduce

  1. on extention settings
  2. set API provider and apikey and model (gemini-2.5-pro)
  3. uncheck enable thinking
  4. click done

and chat

Provider/Model

gemini-2.5-pro

System Information

OS: mac m1
ram: 16gb

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bot RespondedIssue has received an automated responseP2Medium priorityVS CodeIssues specific to VS Code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions