Skip to content

Commit da69a18

Browse files
fix(llm): prevent Gemini thinking from being enabled when clamped to off
Fixes #101785
1 parent 082bd45 commit da69a18

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

packages/ai/src/providers/google-shared.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { stripSystemPromptCacheBoundary } from "../utils/system-prompt-cache-bou
3535
import { describeToolResultMediaPlaceholder, extractToolResultText } from "./tool-result-text.js";
3636
import { transformMessages } from "./transform-messages.js";
3737

38-
type GoogleApiType = "google-generative-ai" | "google-vertex";
38+
export type GoogleApiType = "google-generative-ai" | "google-vertex";
3939

4040
/**
4141
* Thinking level for Gemini 3 models.
@@ -48,9 +48,9 @@ export type GoogleThinkingLevel =
4848
| "MEDIUM"
4949
| "HIGH";
5050

51-
type GoogleToolChoice = "auto" | "none" | "any";
51+
export type GoogleToolChoice = "auto" | "none" | "any";
5252

53-
type GoogleThinkingOptions = {
53+
export type GoogleThinkingOptions = {
5454
enabled: boolean;
5555
budgetTokens?: number;
5656
level?: GoogleThinkingLevel;
@@ -86,7 +86,7 @@ type ClampedGoogleThinkingLevel = Exclude<AgentThinkingLevel, "xhigh" | "max">;
8686
*
8787
* See: https://ai.google.dev/gemini-api/docs/thought-signatures
8888
*/
89-
function isThinkingPart(part: Pick<Part, "thought" | "thoughtSignature">): boolean {
89+
export function isThinkingPart(part: Pick<Part, "thought" | "thoughtSignature">): boolean {
9090
return part.thought === true;
9191
}
9292

@@ -557,8 +557,11 @@ export function buildGoogleSimpleThinking<T extends GoogleApiType>(
557557
}
558558

559559
const clampedReasoning = clampThinkingLevel(model, options.reasoning);
560+
if (clampedReasoning === "off") {
561+
return { enabled: false };
562+
}
560563
const effort = (
561-
clampedReasoning === "off" || clampedReasoning === "max" ? "high" : clampedReasoning
564+
clampedReasoning === "max" ? "high" : clampedReasoning
562565
) as ClampedGoogleThinkingLevel;
563566

564567
if (
@@ -615,11 +618,11 @@ export function isGemma4Model<T extends GoogleApiType>(model: Model<T>): boolean
615618
return /gemma-?4/.test(model.id.toLowerCase());
616619
}
617620

618-
function isGemini3ProModel<T extends GoogleApiType>(model: Model<T>): boolean {
621+
export function isGemini3ProModel<T extends GoogleApiType>(model: Model<T>): boolean {
619622
return /gemini-3(?:\.\d+)?-pro/.test(model.id.toLowerCase());
620623
}
621624

622-
function isGemini3FlashModel<T extends GoogleApiType>(model: Model<T>): boolean {
625+
export function isGemini3FlashModel<T extends GoogleApiType>(model: Model<T>): boolean {
623626
return /gemini-3(?:\.\d+)?-flash/.test(model.id.toLowerCase());
624627
}
625628

0 commit comments

Comments
 (0)