Skip to content

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

- Updated ActionResult to include an attachments field for displaying files in the done message. - Enhanced logging in the Agent class to inform users about available attachments after task completion. - Revised system prompt guidelines to clarify the use of text and files_to_display in the done action.

mertunsallbbc8d26f6362
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index 1f30c2a82..f39bc2d51 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -1001,6 +1001,10 @@ class Agent(Generic[Context]):
if len(result) > 0 and result[-1].is_done:
self.logger.info(f'📄 Result: {result[-1].extracted_content}')
+ if result[-1].attachments:
+ self.logger.info('📎 Click links below to access the attachments:')
+ for file_path in result[-1].attachments:
+ self.logger.info(f'👉 {file_path}')
self.state.consecutive_failures = 0
diff --git a/browser_use/agent/system_prompt.md b/browser_use/agent/system_prompt.md
index 38b1f5e15..74df326f3 100644
--- a/browser_use/agent/system_prompt.md
+++ b/browser_use/agent/system_prompt.md
@@ -116,14 +116,13 @@ You must call the `done` action in one of two cases:
- When you reach the final allowed step (`max_steps`), even if the task is incomplete.
- If it is ABSOLUTELY IMPOSSIBLE to continue.
-In the `done` action:
-- Set `success` to `true` only if the full USER REQUEST has been completed with no missing components so that the user can be happy.
+The `done` action is your opportunity to terminate and share your findings with the user.
+- Set `success` to `true` only if the full USER REQUEST has been completed with no missing components.
- 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, e.g. `["results.md"]` if you used it. NEVER display `todo.md`.
+- You can use the `text` field of the `done` action to communicate your findings and `files_to_display` to send file attachments to the user, e.g. `["results.md"]`.
+- Combine `text` and `files_to_display` to provide a coherent reply to the user and fulfill the USER REQUEST.
- You are ONLY ALLOWED to call `done` as a single action. Don't call it together with other actions.
-- Make the user happy.
-- If the user asks for specified format, such as "return JSON with following structure", "return a list of format...", MAKE sure to use the right format in `done` message.
+- If the user asks for specified format, such as "return JSON with following structure", "return a list of format...", MAKE sure to use the right format in your answer.
</task_completion_rules>
<action_rules>
diff --git a/browser_use/agent/views.py b/browser_use/agent/views.py
index a535d9dec..c13ba740d 100644
--- a/browser_use/agent/views.py
+++ b/browser_use/agent/views.py
@@ -111,6 +111,7 @@ class ActionResult(BaseModel):
include_in_memory: bool = False # whether to include in past messages as context or not
memory: str | None = None # Memory of this action
update_read_state: bool = False # Whether the extracted content should be used to update the read_state
+ attachments: list[str] | None = None # Files to display in the done message
class StepMetadata(BaseModel):
diff --git a/browser_use/controller/service.py b/browser_use/controller/service.py
index 4aeffc3c3..ae80532a5 100644
--- a/browser_use/controller/service.py
+++ b/browser_use/controller/service.py
@@ -89,6 +89,7 @@ class Controller(Generic[Context]):
if len_text > len_max_memory:
memory += f' - {len_text - len_max_memory} more characters'
+ attachments = []
if params.files_to_display:
file_msg = ''
for file_name in params.files_to_display:
@@ -97,13 +98,18 @@ class Controller(Generic[Context]):
file_content = file_system.display_file(file_name)
if file_content:
file_msg += f'\n\n{file_name}:\n{file_content}'
+ attachments.append(file_name)
if file_msg:
user_message += '\n\nAttachments:'
user_message += file_msg
else:
logger.warning('Agent wanted to display files but none were found')
- return ActionResult(is_done=True, success=params.success, extracted_content=user_message, memory=memory)
+ attachments = [str(file_system.get_dir() / file_name) for file_name in attachments]
+
+ return ActionResult(
+ is_done=True, success=params.success, extracted_content=user_message, memory=memory, attachments=attachments
+ )
# Basic Navigation Actions
@self.registry.action(
@@ -191,11 +197,8 @@ class Controller(Generic[Context]):
if params.index not in selector_map:
# Return informative message with the new state instead of error
max_index = max(selector_map.keys()) if selector_map else -1
- return ActionResult(
- extracted_content=f'Element with index {params.index} does not exist. Page has {len(selector_map)} interactive elements (indices 0-{max_index}). State has been refreshed - please use the updated element indices.',
- include_in_memory=True,
- success=False,
- )
+ msg = f'Element with index {params.index} does not exist. Page has {len(selector_map)} interactive elements (indices 0-{max_index}). State has been refreshed - please use the updated element indices.'
+ return ActionResult(extracted_content=msg, include_in_memory=True, success=False, memory=msg)
element_node = await browser_session.get_dom_element_by_index(params.index)
initial_pages = len(browser_session.tabs)
diff --git a/browser_use/filesystem/file_system.py b/browser_use/filesystem/file_system.py
index f7a4c176c..b4562aa07 100644
--- a/browser_use/filesystem/file_system.py
+++ b/browser_use/filesystem/file_system.py
@@ -26,6 +26,9 @@ class FileSystem:
self.results_file.touch(exist_ok=True)
self.todo_file.touch(exist_ok=True)
+ def get_dir(self) -> Path:
+ return self.dir
+
def _is_valid_filename(self, file_name: str) -> bool:
"""Check if filename matches the required pattern: name.extension"""
pattern = r'^[a-zA-Z0-9_\-]+\.(txt|md)$'