Skip to content

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

Fix <available_file_paths>

mertunsallc40b5c89f4b9
diff --git a/browser_use/agent/message_manager/service.py b/browser_use/agent/message_manager/service.py
index 9d97041cb..d52e0b45a 100644
--- a/browser_use/agent/message_manager/service.py
+++ b/browser_use/agent/message_manager/service.py
@@ -204,6 +204,7 @@ class MessageManager:
task: str,
system_message: SystemMessage,
file_system: FileSystem,
+ available_file_paths: list[str] | None = None,
settings: MessageManagerSettings = MessageManagerSettings(),
state: MessageManagerState = MessageManagerState(),
):
@@ -215,6 +216,7 @@ class MessageManager:
self.agent_history_description = '<system>Agent initialized</system>\n'
self.read_state_description = ''
self.sensitive_data_description = ''
+ self.available_file_paths = available_file_paths
# Only initialize messages if state is empty
if len(self.state.history.messages) == 0:
self._init_messages()
@@ -343,12 +345,6 @@ My next action is to click on the iPhone link at index [4] to navigate to Apple'
# self._add_message_with_tokens(example_tool_call_2, message_type='init')
# self.add_tool_message(content='Clicked on index [4]. </example_2>', message_type='init')
- if self.settings.available_file_paths:
- filepaths_msg = HumanMessage(
- content=f'<available_file_paths>Here are file paths you can use: {self.settings.available_file_paths}</available_file_paths>'
- )
- self._add_message_with_tokens(filepaths_msg, message_type='init')
-
def add_new_task(self, new_task: str) -> None:
self.task = new_task
self.agent_history_description += f'\n<system>User updated USER REQUEST to: {new_task}</system>\n'
@@ -456,6 +452,7 @@ Next Goal: {model_output.current_state.next_goal}
step_info=step_info,
page_filtered_actions=page_filtered_actions,
sensitive_data=self.sensitive_data_description,
+ available_file_paths=self.available_file_paths,
).get_user_message(use_vision)
self._add_message_with_tokens(state_message)
diff --git a/browser_use/agent/prompts.py b/browser_use/agent/prompts.py
index 9f78f63b1..47911cd25 100644
--- a/browser_use/agent/prompts.py
+++ b/browser_use/agent/prompts.py
@@ -73,6 +73,7 @@ class AgentMessagePrompt:
page_filtered_actions: str | None = None,
max_clickable_elements_length: int = 40000,
sensitive_data: str | None = None,
+ available_file_paths: list[str] | None = None,
):
self.browser_state: 'BrowserStateSummary' = browser_state_summary
self.file_system: 'FileSystem | None' = file_system
@@ -84,6 +85,7 @@ class AgentMessagePrompt:
self.page_filtered_actions: str | None = page_filtered_actions
self.max_clickable_elements_length: int = max_clickable_elements_length
self.sensitive_data: str | None = sensitive_data
+ self.available_file_paths: list[str] | None = available_file_paths
assert self.browser_state
def _get_browser_state_description(self) -> str:
@@ -162,6 +164,8 @@ Interactive elements from top layer of the current page inside the viewport{trun
agent_state += f'<sensitive_data>\n{self.sensitive_data}\n</sensitive_data>\n'
agent_state += f'<step_info>\n{step_info_description}\n</step_info>\n'
+ if self.available_file_paths:
+ agent_state += f'<available_file_paths>\n{self.available_file_paths}\n</available_file_paths>\n'
return agent_state
def get_user_message(self, use_vision: bool = True) -> HumanMessage:
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index 9d5317708..f24f66546 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -298,6 +298,7 @@ class Agent(Generic[Context]):
sensitive_data=sensitive_data,
available_file_paths=self.settings.available_file_paths,
),
+ available_file_paths=self.settings.available_file_paths,
state=self.state.message_manager_state,
)
diff --git a/browser_use/agent/system_prompt.md b/browser_use/agent/system_prompt.md
index ae8b230af..cdcf32309 100644
--- a/browser_use/agent/system_prompt.md
+++ b/browser_use/agent/system_prompt.md
@@ -98,6 +98,7 @@ Strictly follow these rules while using the browser and navigating the web:
- When you `append_file`, ALWAYS put newlines in the beginning and not at the end.
- If the file is too large, you are only given a preview of your file. Use read_file to see the full content if necessary.
- Always use the file system as the source of truth. Do not rely on memory alone for tracking task state.
+- If exists, <available_file_paths> includes files you have downloaded. You can upload them somewhere else if needed.
</file_system>
<task_completion_rules>