Skip to content

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

make available_file_paths more reliable

mertunsall4febeeada0a0
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index f24f66546..739b50c56 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -15,6 +15,7 @@ from pathlib import Path
from threading import Thread
from typing import Any, Generic, TypeVar
+import anyio
from dotenv import load_dotenv
load_dotenv()
@@ -506,8 +507,14 @@ class Agent(Generic[Context]):
return ActionResult(extracted_content=result, include_in_memory=True, long_term_memory=result)
@self.controller.registry.action('Read file_name from file system')
- async def read_file(file_name: str):
- result = await self.file_system.read_file(file_name)
+ async def read_file(file_name: str, available_file_paths: list[str]):
+ if file_name in available_file_paths:
+ async with await anyio.open_file(file_name, 'r') as f:
+ content = await f.read()
+ result = f'Read from file {file_name}.\n<content>\n{content}\n</content>'
+ else:
+ result = await self.file_system.read_file(file_name)
+
MAX_MEMORY_SIZE = 1000
if len(result) > MAX_MEMORY_SIZE:
lines = result.splitlines()
diff --git a/browser_use/agent/system_prompt.md b/browser_use/agent/system_prompt.md
index cdcf32309..1eab4ef10 100644
--- a/browser_use/agent/system_prompt.md
+++ b/browser_use/agent/system_prompt.md
@@ -98,7 +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.
+- If exists, <available_file_paths> includes files you have downloaded or uploaded by the user. You can only read or upload these files but you don't have write access.
</file_system>
<task_completion_rules>