Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

feat: updated the thinking budget

Saurav Panda041d03a93f94
diff --git a/browser_use/llm/google/chat.py b/browser_use/llm/google/chat.py
index 7c8260197..44d65170d 100644
--- a/browser_use/llm/google/chat.py
+++ b/browser_use/llm/google/chat.py
@@ -88,7 +88,8 @@ class ChatGoogle(BaseChatModel):
temperature: float | None = 0.5
top_p: float | None = None
seed: int | None = None
- thinking_budget: int | None = None # for gemini-2.5 flash, flash-lite, and gemini-3 models, default will be set to 0
+ thinking_budget: int | None = None # for Gemini 2.5: 0 disables (flash), -1 for dynamic, or token count
+ thinking_level: Literal['low', 'high'] | None = None # for Gemini 3: 'low' minimizes latency, 'high' maximizes depth
max_output_tokens: int | None = 8096
config: types.GenerateContentConfigDict | None = None
include_system_in_user: bool = False
@@ -230,15 +231,36 @@ class ChatGoogle(BaseChatModel):
if self.seed is not None:
config['seed'] = self.seed
- # set default for flash, flash-lite, gemini-flash-lite-latest, gemini-flash-latest, and gemini-3 models
- if self.thinking_budget is None and (
- 'gemini-2.5-flash' in self.model or 'gemini-flash' in self.model or 'gemini-3' in self.model
- ):
- self.thinking_budget = 0
+ # Configure thinking based on model version
+ # Gemini 3 uses thinking_level; Gemini 2.5 uses thinking_budget
+ is_gemini_3 = 'gemini-3' in self.model
- if self.thinking_budget is not None:
- thinking_config_dict: types.ThinkingConfigDict = {'thinking_budget': self.thinking_budget}
+ if is_gemini_3:
+ # Validate: thinking_budget should not be set for Gemini 3
+ if self.thinking_budget is not None:
+ self.logger.warning(
+ f'thinking_budget={self.thinking_budget} is deprecated for Gemini 3 models and may cause '
+ f'suboptimal performance. Use thinking_level instead ("low" or "high").'
+ )
+ # Gemini 3: use thinking_level (not thinking_budget)
+ if self.thinking_level is None:
+ self.thinking_level = 'low' # default to 'low' for latency/cost optimization
+ level = types.ThinkingLevel.LOW if self.thinking_level == 'low' else types.ThinkingLevel.HIGH
+ thinking_config_dict: types.ThinkingConfigDict = {'thinking_level': level}
config['thinking_config'] = thinking_config_dict
+ else:
+ # Validate: thinking_level should not be set for Gemini 2.5
+ if self.thinking_level is not None:
+ self.logger.warning(
+ f'thinking_level="{self.thinking_level}" is not supported for Gemini 2.5 models. '
+ f'Use thinking_budget instead (0 to disable, -1 for dynamic, or token count).'
+ )
+ # Gemini 2.5 and earlier: use thinking_budget
+ if self.thinking_budget is None and ('gemini-2.5-flash' in self.model or 'gemini-flash' in self.model):
+ self.thinking_budget = 0
+ if self.thinking_budget is not None:
+ thinking_config_dict: types.ThinkingConfigDict = {'thinking_budget': self.thinking_budget}
+ config['thinking_config'] = thinking_config_dict
if self.max_output_tokens is not None:
config['max_output_tokens'] = self.max_output_tokens
diff --git a/examples/simple.py b/examples/simple.py
index 449237819..321f6471a 100644
--- a/examples/simple.py
+++ b/examples/simple.py
@@ -6,12 +6,12 @@ Setup:
from dotenv import load_dotenv
-from browser_use import Agent, ChatBrowserUse
+from browser_use import Agent, ChatGoogle
load_dotenv()
agent = Agent(
- task='Find the number of stars of the following repos: browser-use, playwright, stagehand, react, nextjs',
- llm=ChatBrowserUse(model='bu-2-0'),
+ task='Who are founders of Browser Use',
+ llm=ChatGoogle(model='gemini-3-pro-preview'),
)
agent.run_sync()