Skip to content

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

Fixed exception handling bug in agent step

Shahar Yair5a8882b8093a
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index 5cf1750e1..c32379e67 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -137,8 +137,6 @@ class Agent:
result = self._handle_step_error(e)
self._last_result = result
- model_output = None
-
if result.error:
self.telemetry.capture(
AgentStepErrorTelemetryEvent(
@@ -146,8 +144,10 @@ class Agent:
error=result.error,
)
)
- if state:
- self._make_history_item(model_output, state, result)
+ model_output = None
+ finally:
+ if state:
+ self._make_history_item(model_output, state, result)
def _handle_step_error(self, error: Exception) -> ActionResult:
"""Handle all types of errors that can occur during a step"""