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
Merge branch 'main' into pr/gregpr07/346
Gregor Žuniča92f4466fefc
diff --cc browser_use/agent/service.pyindex d966f28c8,e7fb98f4a..9b18bec96--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@@ -12,7 -12,7 +12,7 @@@ import timimport uuidfrom io import BytesIOfrom pathlib import Path- from typing import Any, Callable, Optional, Type, TypeVar-from typing import Any, Dict, List, Optional, Type, TypeVar++from typing import Any, Callable, Dict, List, Optional, Type, TypeVarfrom dotenv import load_dotenvfrom langchain_core.language_models.chat_models import BaseChatModel@@@ -87,10 -89,8 +89,12 @@@ class Agent],max_error_length: int = 400,max_actions_per_step: int = 10,- tool_calling_method: Optional[str] = 'auto',+ tool_call_in_content: bool = True,- register_new_step_callback: Callable[['BrowserState', 'AgentOutput', int], None]- | None = None,+ initial_actions: Optional[List[Dict[str, Dict[str, Any]]]] = None,++ # Cloud Callbacks++ register_new_step_callback: Callable[['BrowserState', 'AgentOutput', int], None] | None = None,+ register_done_callback: Callable[['AgentHistoryList'], None] | None = None,++ tool_calling_method: Optional[str] = 'auto',):self.agent_id = str(uuid.uuid4()) # unique identifier for the agent@@@ -144,13 -148,8 +152,12 @@@include_attributes=self.include_attributes,max_error_length=self.max_error_length,max_actions_per_step=self.max_actions_per_step,- tool_call_in_content=tool_call_in_content,)+ # Step callback+ self.register_new_step_callback = register_new_step_callback+ self.register_done_callback = register_done_callback+# Tracking variablesself.history: AgentHistoryList = AgentHistoryList(history=[])self.n_steps = 1@@@ -286,11 -319,14 +332,14 @@@@time_execution_async('--get_next_action')async def get_next_action(self, input_messages: list[BaseMessage]) -> AgentOutput:"""Get next action from LLM based on current state"""+ if self.tool_calling_method is None:+ structured_llm = self.llm.with_structured_output(self.AgentOutput, include_raw=True)+ else:+ structured_llm = self.llm.with_structured_output(self.AgentOutput, include_raw=True, method=self.tool_calling_method)- structured_llm = self.llm.with_structured_output(self.AgentOutput, include_raw=True)response: dict[str, Any] = await structured_llm.ainvoke(input_messages) # type: ignore-- parsed: AgentOutput = response['parsed']++ parsed: AgentOutput | None = response['parsed']if parsed is None:raise ValueError('Could not parse response.')diff --cc browser_use/browser/context.pyindex 339767c87,b8de06d33..8efb4335d--- a/browser_use/browser/context.py+++ b/browser_use/browser/context.py@@@ -187,9 -202,11 +202,11 @@@ class BrowserContext),selector_map={},url=page.url,- title=await page.title(),+ title='',screenshot=None,tabs=[],+ pixels_above=0,+ pixels_below=0,)self.session = BrowserSession(