Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
support for reasoning models o1, o1-mini, etc for planner
Anish Hiranandani9ea07efdc41d
diff --git a/browser_use/agent/prompts.py b/browser_use/agent/prompts.pyindex b78cfe5bc..8a36af9ec 100644--- a/browser_use/agent/prompts.py+++ b/browser_use/agent/prompts.py@@ -1,7 +1,7 @@import datetimeimport importlib.resourcesfrom datetime import datetime-from typing import TYPE_CHECKING, List, Optional+from typing import TYPE_CHECKING, List, Optional, Unionfrom langchain_core.messages import HumanMessage, SystemMessage@@ -139,9 +139,8 @@ Interactive elements from top layer of the current page inside the viewport:class PlannerPrompt(SystemPrompt):- def get_system_message(self) -> SystemMessage:- return SystemMessage(- content="""You are a planning agent that helps break down tasks into smaller steps and reason about the current state.+ def get_system_message(self, is_planner_reasoning) -> Union[SystemMessage, HumanMessage]:+ planner_prompt_text = """You are a planning agent that helps break down tasks into smaller steps and reason about the current state.Your role is to:1. Analyze the current state and history2. Evaluate progress towards the ultimate goal@@ -162,4 +161,12 @@ Your output format should be always a JSON object with the following fields:Ignore the other AI messages output structures.Keep your responses concise and focused on actionable insights."""- )++ if is_planner_reasoning:+ return HumanMessage(+ content=planner_prompt_text+ )+ else:+ return SystemMessage(+ content=planner_prompt_text+ )diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex a29d341f2..abddb72ec 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -134,6 +134,7 @@ class Agent(Generic[Context]):page_extraction_llm: Optional[BaseChatModel] = None,planner_llm: Optional[BaseChatModel] = None,planner_interval: int = 1, # Run planner every N steps+ is_planner_reasoning: bool = False,# Inject stateinjected_agent_state: Optional[AgentState] = None,#@@ -168,6 +169,7 @@ class Agent(Generic[Context]):page_extraction_llm=page_extraction_llm,planner_llm=planner_llm,planner_interval=planner_interval,+ is_planner_reasoning=is_planner_reasoning,)# Initialize state@@ -968,7 +970,7 @@ class Agent(Generic[Context]):# Create planner message history using full message historyplanner_messages = [- PlannerPrompt(self.controller.registry.get_prompt_description()).get_system_message(),+ PlannerPrompt(self.controller.registry.get_prompt_description()).get_system_message(self.settings.is_planner_reasoning),*self._message_manager.get_messages()[1:], # Use full message history except the first]diff --git a/browser_use/agent/views.py b/browser_use/agent/views.pyindex 1cec01f55..2c81a2458 100644--- a/browser_use/agent/views.py+++ b/browser_use/agent/views.py@@ -58,6 +58,7 @@ class AgentSettings(BaseModel):page_extraction_llm: Optional[BaseChatModel] = Noneplanner_llm: Optional[BaseChatModel] = Noneplanner_interval: int = 1 # Run planner every N steps+ is_planner_reasoning: bool = False, # type: ignoreclass AgentState(BaseModel):