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 Yair22ea904b98ca
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index 5cf1750e1..646c4ba9b 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -136,9 +136,6 @@ class Agent:
except Exception as e:
result = self._handle_step_error(e)
self._last_result = result
-
- model_output = None
-
if result.error:
self.telemetry.capture(
AgentStepErrorTelemetryEvent(
@@ -146,8 +143,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"""