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
12 changes: 12 additions & 0 deletions .changeset/fix-gemini-3-thinking-level.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"roo-cline": patch
---

fix(gemini): upgrade @google/genai to support thinkingLevel for Gemini 3 models

The previous SDK version (1.29.1) did not include the `thinkingLevel` property in
`ThinkingConfig`, causing INVALID_ARGUMENT errors when using Gemini 3 Pro and Flash
models which require effort-based reasoning configuration via `thinkingLevel`.

Updated to @google/genai ^1.30.0 which adds support for `thinkingLevel` with values:
MINIMAL, LOW, MEDIUM, HIGH.
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions src/api/transform/__tests__/reasoning.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// npx vitest run src/api/transform/__tests__/reasoning.spec.ts

import type { ModelInfo, ProviderSettings, ReasoningEffortWithMinimal } from "@roo-code/types"
import { ThinkingLevel } from "@google/genai"

import {
getOpenRouterReasoning,
Expand Down Expand Up @@ -615,7 +616,7 @@ describe("reasoning.ts", () => {
const result = getGeminiReasoning(options) as GeminiReasoningParams | undefined

// Budget should not be used for effort-only models
expect(result).toEqual({ thinkingLevel: "high", includeThoughts: true })
expect(result).toEqual({ thinkingLevel: ThinkingLevel.HIGH, includeThoughts: true })
})

it("should still return thinkingLevel when enableReasoningEffort is false but effort is explicitly set", () => {
Expand All @@ -641,7 +642,7 @@ describe("reasoning.ts", () => {
}

const result = getGeminiReasoning(options) as GeminiReasoningParams | undefined
expect(result).toEqual({ thinkingLevel: "high", includeThoughts: true })
expect(result).toEqual({ thinkingLevel: ThinkingLevel.HIGH, includeThoughts: true })
})

it("should return thinkingLevel for minimal effort", () => {
Expand All @@ -664,7 +665,7 @@ describe("reasoning.ts", () => {
}

const result = getGeminiReasoning(options) as GeminiReasoningParams | undefined
expect(result).toEqual({ thinkingLevel: "minimal", includeThoughts: true })
expect(result).toEqual({ thinkingLevel: ThinkingLevel.MINIMAL, includeThoughts: true })
})

it("should return thinkingLevel for medium effort", () => {
Expand All @@ -687,11 +688,17 @@ describe("reasoning.ts", () => {
}

const result = getGeminiReasoning(options) as GeminiReasoningParams | undefined
expect(result).toEqual({ thinkingLevel: "medium", includeThoughts: true })
expect(result).toEqual({ thinkingLevel: ThinkingLevel.MEDIUM, includeThoughts: true })
})

it("should handle all four Gemini thinking levels", () => {
const levels: GeminiThinkingLevel[] = ["minimal", "low", "medium", "high"]
const expectedThinkingLevels: Record<GeminiThinkingLevel, ThinkingLevel> = {
minimal: ThinkingLevel.MINIMAL,
low: ThinkingLevel.LOW,
medium: ThinkingLevel.MEDIUM,
high: ThinkingLevel.HIGH,
}

levels.forEach((level) => {
const geminiModel: ModelInfo = {
Expand All @@ -718,7 +725,7 @@ describe("reasoning.ts", () => {
}

const result = getGeminiReasoning(options) as GeminiReasoningParams | undefined
expect(result).toEqual({ thinkingLevel: level, includeThoughts: true })
expect(result).toEqual({ thinkingLevel: expectedThinkingLevels[level], includeThoughts: true })
})
})

Expand Down Expand Up @@ -836,7 +843,7 @@ describe("reasoning.ts", () => {
}

const result = getGeminiReasoning(options) as GeminiReasoningParams | undefined
expect(result).toEqual({ thinkingLevel: "medium", includeThoughts: true })
expect(result).toEqual({ thinkingLevel: ThinkingLevel.MEDIUM, includeThoughts: true })
})
})

Expand Down
17 changes: 12 additions & 5 deletions src/api/transform/reasoning.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BetaThinkingConfigParam } from "@anthropic-ai/sdk/resources/beta"
import OpenAI from "openai"
import type { GenerateContentConfig } from "@google/genai"
import { ThinkingLevel, type GenerateContentConfig } from "@google/genai"

import type { ModelInfo, ProviderSettings, ReasoningEffortExtended } from "@roo-code/types"

Expand All @@ -21,7 +21,7 @@ export type AnthropicReasoningParams = BetaThinkingConfigParam

export type OpenAiReasoningParams = { reasoning_effort: OpenAI.Chat.ChatCompletionCreateParams["reasoning_effort"] }

// Valid Gemini thinking levels for effort-based reasoning
// Valid Gemini thinking levels for effort-based reasoning (lowercase for internal use)
const GEMINI_THINKING_LEVELS = ["minimal", "low", "medium", "high"] as const

export type GeminiThinkingLevel = (typeof GEMINI_THINKING_LEVELS)[number]
Expand All @@ -30,10 +30,16 @@ export function isGeminiThinkingLevel(value: unknown): value is GeminiThinkingLe
return typeof value === "string" && GEMINI_THINKING_LEVELS.includes(value as GeminiThinkingLevel)
}

export type GeminiReasoningParams = GenerateContentConfig["thinkingConfig"] & {
thinkingLevel?: GeminiThinkingLevel
// Map lowercase thinking levels to SDK's ThinkingLevel enum
const THINKING_LEVEL_MAP: Record<GeminiThinkingLevel, ThinkingLevel> = {
minimal: ThinkingLevel.MINIMAL,
low: ThinkingLevel.LOW,
medium: ThinkingLevel.MEDIUM,
high: ThinkingLevel.HIGH,
}

export type GeminiReasoningParams = GenerateContentConfig["thinkingConfig"]

export type GetModelReasoningOptions = {
model: ModelInfo
reasoningBudget: number | undefined
Expand Down Expand Up @@ -155,5 +161,6 @@ export const getGeminiReasoning = ({
return undefined
}

return { thinkingLevel: selectedEffort, includeThoughts: true }
// Map lowercase effort to SDK's ThinkingLevel enum (uppercase values)
return { thinkingLevel: THINKING_LEVEL_MAP[selectedEffort], includeThoughts: true }
}
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@
"@anthropic-ai/vertex-sdk": "^0.7.0",
"@aws-sdk/client-bedrock-runtime": "^3.922.0",
"@aws-sdk/credential-providers": "^3.922.0",
"@google/genai": "^1.29.1",
"@google/genai": "^1.30.0",
"@lmstudio/sdk": "^1.1.1",
"@mistralai/mistralai": "^1.9.18",
"@modelcontextprotocol/sdk": "1.12.0",
Expand Down
Loading