Skip to content

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

add thinking budget to gemini and fix evals

mertunsall05ef50fdf1c8
diff --git a/browser_use/llm/google/chat.py b/browser_use/llm/google/chat.py
index 4a9495a0a..fe76b417f 100644
--- a/browser_use/llm/google/chat.py
+++ b/browser_use/llm/google/chat.py
@@ -74,6 +74,7 @@ class ChatGoogle(BaseChatModel):
# Model configuration
model: VerifiedGeminiModels | str
temperature: float | None = None
+ thinking_budget: int | None = None
config: types.GenerateContentConfigDict | None = None
# Client initialization parameters
@@ -134,7 +135,8 @@ class ChatGoogle(BaseChatModel):
usage = ChatInvokeUsage(
prompt_tokens=response.usage_metadata.prompt_token_count or 0,
- completion_tokens=response.usage_metadata.candidates_token_count or 0,
+ completion_tokens=(response.usage_metadata.candidates_token_count or 0)
+ + (response.usage_metadata.thoughts_token_count or 0),
total_tokens=response.usage_metadata.total_token_count or 0,
prompt_cached_tokens=response.usage_metadata.cached_content_token_count,
prompt_cache_creation_tokens=None,
@@ -179,6 +181,9 @@ class ChatGoogle(BaseChatModel):
if system_instruction:
config['system_instruction'] = system_instruction
+ if self.thinking_budget is not None:
+ config['thinking_budget'] = types.ThinkingBudget(thinking_budget=self.thinking_budget)
+
async def _make_api_call():
if output_format is None:
# Return string response
diff --git a/eval/service.py b/eval/service.py
index 1aa8acace..ebc84a63f 100644
--- a/eval/service.py
+++ b/eval/service.py
@@ -723,9 +723,25 @@ SUPPORTED_MODELS = {
# Google
'gemini-1.5-flash': {'provider': 'google', 'model_name': 'gemini-1.5-flash-latest', 'api_key_env': 'GEMINI_API_KEY'},
'gemini-2.0-flash-lite': {'provider': 'google', 'model_name': 'gemini-2.0-flash-lite', 'api_key_env': 'GEMINI_API_KEY'},
- 'gemini-2.0-flash': {'provider': 'google', 'model_name': 'gemini-2.0-flash', 'api_key_env': 'GEMINI_API_KEY'},
+ 'gemini-2.0-flash': {
+ 'provider': 'google',
+ 'model_name': 'gemini-2.0-flash',
+ 'api_key_env': 'GEMINI_API_KEY',
+ 'thinking_budget': 0,
+ },
'gemini-2.5-pro': {'provider': 'google', 'model_name': 'gemini-2.5-pro', 'api_key_env': 'GEMINI_API_KEY'},
- 'gemini-2.5-flash': {'provider': 'google', 'model_name': 'gemini-2.5-flash', 'api_key_env': 'GEMINI_API_KEY'},
+ 'gemini-2.5-flash': {
+ 'provider': 'google',
+ 'model_name': 'gemini-2.5-flash',
+ 'api_key_env': 'GEMINI_API_KEY',
+ 'thinking_budget': 0,
+ },
+ 'gemini-2.5-flash-lite': {
+ 'provider': 'google',
+ 'model_name': 'gemini-2.5-flash-lite-preview-06-17',
+ 'api_key_env': 'GEMINI_API_KEY',
+ 'thinking_budget': 0,
+ },
'gemini-2.5-pro-preview-05-06': {
'provider': 'google',
'model_name': 'gemini-2.5-pro-preview-05-06',