Skip to content

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

allow done action to be called ONLY as a single action, i.e. disable calling done within a series of actions

mertunsall853d2aa4617d
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index d7f05216e..da9d98ca6 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -1521,6 +1521,13 @@ class Agent(Generic[Context]):
await self.browser_session.remove_highlights()
for i, action in enumerate(actions):
+ # DO NOT ALLOW TO CALL `done` AS A SINGLE ACTION
+ if i > 0 and action.model_dump(exclude_unset=True).get('done') is not None:
+ msg = f'Done action is allowed only as a single action - stopped after action {i} / {len(actions)}.'
+ logger.info(msg)
+ results.append(ActionResult(extracted_content=msg, include_in_memory=True, memory=msg))
+ break
+
if action.get_index() is not None and i != 0:
new_browser_state_summary = await self.browser_session.get_state_summary(cache_clickable_elements_hashes=False)
new_selector_map = new_browser_state_summary.selector_map
diff --git a/browser_use/agent/system_prompt.md b/browser_use/agent/system_prompt.md
index c035f6f9c..7a11c0f50 100644
--- a/browser_use/agent/system_prompt.md
+++ b/browser_use/agent/system_prompt.md
@@ -113,6 +113,8 @@ In the `done` action:
- If any part of the request is missing, incomplete, or uncertain, set `success` to `false`.
- In all cases, include all relevant findings and outputs in the `text` field of the `done` action.
- Use `files_to_display` field to provide a list of files to display to the user.
+
+- You are ONLY ALLOWED to call `done` as a single action.
</task_completion_rules>
<action_rules>