Skip to content

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

Return the agent the result from init actions

Magnus Müller84cdd347437c
diff --git a/browser_use/agent/message_manager/service.py b/browser_use/agent/message_manager/service.py
index ffe426ac6..99e48aff8 100644
--- a/browser_use/agent/message_manager/service.py
+++ b/browser_use/agent/message_manager/service.py
@@ -212,10 +212,16 @@ class MessageManager:
# Build the history item
if model_output is None:
- # Only add error history item if we have a valid step number
- if step_number is not None and step_number > 0:
- history_item = HistoryItem(step_number=step_number, error='Agent failed to output in the right format.')
- self.state.agent_history_items.append(history_item)
+ # Add history item for initial actions (step 0) or errors (step > 0)
+ if step_number is not None:
+ if step_number == 0 and action_results:
+ # Step 0 with initial action results
+ history_item = HistoryItem(step_number=step_number, action_results=action_results)
+ self.state.agent_history_items.append(history_item)
+ elif step_number > 0:
+ # Error case for steps > 0
+ history_item = HistoryItem(step_number=step_number, error='Agent failed to output in the right format.')
+ self.state.agent_history_items.append(history_item)
else:
history_item = HistoryItem(
step_number=step_number,