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
improved observability
Robert Kimd9d5a615089a
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex 45f264694..3d862761d 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -241,6 +241,7 @@ class Agent:raise InterruptedErrorreturn False+ @observe(name='agent.step', ignore_output=True, ignore_input=True)@time_execution_async('--step')async def step(self, step_info: Optional[AgentStepInfo] = None) -> None:"""Execute one step of the task"""@@ -485,7 +486,7 @@ class Agent:))- @observe(name='agent.run')+ @observe(name='agent.run', ignore_output=True)async def run(self, max_steps: int = 100) -> AgentHistoryList:"""Execute the task with maximum number of steps"""try:diff --git a/browser_use/controller/service.py b/browser_use/controller/service.pyindex 7dc36271b..9d1fbe850 100644--- a/browser_use/controller/service.py+++ b/browser_use/controller/service.py@@ -4,6 +4,7 @@ import loggingfrom typing import Callable, Dict, Optional, Typefrom langchain_core.prompts import PromptTemplate+from lmnr import Laminar, observefrom pydantic import BaseModelfrom browser_use.agent.views import ActionModel, ActionResult@@ -188,7 +189,7 @@ class Controller:if params.amount is not None:await page.evaluate(f'window.scrollBy(0, {params.amount});')else:- await page.keyboard.press('PageDown')+ await page.evaluate('window.scrollBy(0, window.innerHeight);')amount = f'{params.amount} pixels' if params.amount is not None else 'one page'msg = f'🔍 Scrolled down the page by {amount}'@@ -208,7 +209,7 @@ class Controller:if params.amount is not None:await page.evaluate(f'window.scrollBy(0, -{params.amount});')else:- await page.keyboard.press('PageUp')+ await page.evaluate('window.scrollBy(0, -window.innerHeight);')amount = f'{params.amount} pixels' if params.amount is not None else 'one page'msg = f'🔍 Scrolled up the page by {amount}'@@ -439,6 +440,7 @@ class Controller:"""return self.registry.action(description, **kwargs)+ @observe(name='controller.multi_act')@time_execution_async('--multi-act')async def multi_act(self,@@ -493,17 +495,28 @@ class Controller:sensitive_data: Optional[Dict[str, str]] = None,) -> ActionResult:"""Execute an action"""+try:for action_name, params in action.model_dump(exclude_unset=True).items():if params is not None:- # remove highlights- result = await self.registry.execute_action(- action_name,- params,- browser=browser_context,- page_extraction_llm=page_extraction_llm,- sensitive_data=sensitive_data,- )+ with Laminar.start_as_current_span(+ name=action_name,+ input={+ 'action': action_name,+ 'params': params,+ },+ span_type='TOOL',+ ):+ result = await self.registry.execute_action(+ action_name,+ params,+ browser=browser_context,+ page_extraction_llm=page_extraction_llm,+ sensitive_data=sensitive_data,+ )++ Laminar.set_span_output(result)+if isinstance(result, str):return ActionResult(extracted_content=result)elif isinstance(result, ActionResult):diff --git a/docs/development/observability.mdx b/docs/development/observability.mdxindex d8d988c29..955e0388e 100644--- a/docs/development/observability.mdx+++ b/docs/development/observability.mdx@@ -22,7 +22,7 @@ To get your project API key, you can either:- Or spin up a local Laminar instance and get the key from the settings page```bash-pip install lmnr+pip install 'lmnr[all]'export LMNR_PROJECT_API_KEY=<your-project-api-key>```@@ -56,6 +56,7 @@ You can view traces in the Laminar UI by going to the traces tab in your projectWhen you select a trace, you can see both the browser session recording and the agent execution steps.Timeline of the browser session is synced with the agent execution steps, timeline highlights indicate the agent's current step synced with the browser session.+In the trace view, you can also see the agent's current step, the tool it's using, and the tool's input and output. Tools are highlighted in the timeline with a yellow color.<img className="block" src="/images/laminar.png" alt="Laminar" />diff --git a/docs/images/laminar.png b/docs/images/laminar.pngindex 78795c8d0..ded8ee403 100644Binary files a/docs/images/laminar.png and b/docs/images/laminar.png differdiff --git a/pyproject.toml b/pyproject.tomlindex af0b396c5..74a4acdcc 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -29,7 +29,7 @@ dependencies = ["posthog>=3.7.0","playwright>=1.49.0","setuptools>=75.8.0",- "lmnr[langchain]>=0.4.53",+ "lmnr[langchain]>=0.4.59","markdownify==0.14.1"]