Skip to content

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

debug time out llm calls

Gregor Žunič9348cbff57de
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index 70bffe5db..3d212580f 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -699,7 +699,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
self.logger.debug(f'🌐 Step {self.state.n_steps}: Getting browser state...')
# Always take screenshots for all steps
- self.logger.debug(f'📸 Requesting browser state with include_screenshot=True, cached=True')
+ self.logger.debug('📸 Requesting browser state with include_screenshot=True, cached=True')
browser_state_summary = await self.browser_session.get_browser_state_summary(
cache_clickable_elements_hashes=True,
include_screenshot=True,
@@ -708,7 +708,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
if browser_state_summary.screenshot:
self.logger.debug(f'📸 Got browser state WITH screenshot, length: {len(browser_state_summary.screenshot)}')
else:
- self.logger.debug(f'📸 Got browser state WITHOUT screenshot')
+ self.logger.debug('📸 Got browser state WITHOUT screenshot')
# Check for new downloads after getting browser state (catches PDF auto-downloads and previous step downloads)
await self._check_and_update_downloads(f'Step {self.state.n_steps}: after getting browser state')
@@ -752,6 +752,14 @@ class Agent(Generic[Context, AgentStructuredOutput]):
self._get_model_output_with_retry(input_messages), timeout=self.settings.llm_timeout
)
except TimeoutError:
+
+ @observe(name='_llm_call_timed_out_with_input')
+ async def _log_model_input_to_lmnr(input_messages: list[BaseMessage]) -> None:
+ """Log the model input"""
+ pass
+
+ await _log_model_input_to_lmnr(input_messages)
+
raise TimeoutError(
f'LLM call timed out after {self.settings.llm_timeout} seconds. Keep your thinking and output short.'
)
@@ -989,11 +997,13 @@ class Agent(Generic[Context, AgentStructuredOutput]):
# Store screenshot and get path
screenshot_path = None
if browser_state_summary.screenshot:
- self.logger.debug(f"📸 Storing screenshot for step {self.state.n_steps}, screenshot length: {len(browser_state_summary.screenshot)}")
+ self.logger.debug(
+ f'📸 Storing screenshot for step {self.state.n_steps}, screenshot length: {len(browser_state_summary.screenshot)}'
+ )
screenshot_path = await self.screenshot_service.store_screenshot(browser_state_summary.screenshot, self.state.n_steps)
- self.logger.debug(f"📸 Screenshot stored at: {screenshot_path}")
+ self.logger.debug(f'📸 Screenshot stored at: {screenshot_path}')
else:
- self.logger.debug(f"📸 No screenshot in browser_state_summary for step {self.state.n_steps}")
+ self.logger.debug(f'📸 No screenshot in browser_state_summary for step {self.state.n_steps}')
state_history = BrowserStateHistory(
url=browser_state_summary.url,
@@ -1727,7 +1737,6 @@ class Agent(Generic[Context, AgentStructuredOutput]):
# The signal handler should have already reset the flags
# through its reset() method when called from run()
-
def stop(self) -> None:
"""Stop the agent"""
self.logger.info('⏹️ Agent stopping')