Skip to content

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

improve file system examples

mertunsallcbbfe956db9c
diff --git a/examples/file_system/alphabet_earnings.py b/examples/file_system/alphabet_earnings.py
new file mode 100644
index 000000000..7a8bd6fba
--- /dev/null
+++ b/examples/file_system/alphabet_earnings.py
@@ -0,0 +1,56 @@
+import asyncio
+import os
+import pathlib
+import shutil
+
+from dotenv import load_dotenv
+
+from browser_use import Agent
+from browser_use.browser import BrowserProfile, BrowserSession
+from browser_use.llm import ChatOpenAI
+
+load_dotenv()
+
+''
+SCRIPT_DIR = pathlib.Path(os.path.dirname(os.path.abspath(__file__)))
+agent_dir = SCRIPT_DIR / 'alphabet_earnings'
+agent_dir.mkdir(exist_ok=True)
+
+try:
+ from lmnr import Laminar
+
+ Laminar.initialize(project_api_key=os.getenv('LMNR_PROJECT_API_KEY'))
+except Exception as e:
+ print(f'Error initializing Laminar: {e}')
+
+llm = ChatOpenAI(
+ model='o4-mini',
+)
+
+browser_session = BrowserSession(
+ browser_profile=BrowserProfile(downloads_path=str(agent_dir / 'downloads')),
+)
+
+task = """
+Go to https://abc.xyz/assets/cc/27/3ada14014efbadd7a58472f1f3f4/2025q2-alphabet-earnings-release.pdf.
+Read the PDF and save 3 interesting data points in "alphabet_earnings.pdf" and share it with me!
+""".strip('\n')
+
+agent = Agent(
+ task=task,
+ llm=llm,
+ browser_session=browser_session,
+ file_system_path=str(agent_dir / 'fs'),
+ flash_mode=True,
+)
+
+
+async def main():
+ agent_history = await agent.run()
+ input('Press Enter to clean the file system...')
+ # clean the file system
+ shutil.rmtree(str(agent_dir / 'fs'))
+
+
+if __name__ == '__main__':
+ asyncio.run(main())
diff --git a/examples/file_system/file_system.py b/examples/file_system/file_system.py
index 78eda7ca3..82a0e5b98 100644
--- a/examples/file_system/file_system.py
+++ b/examples/file_system/file_system.py
@@ -10,9 +10,9 @@ from browser_use.llm import ChatOpenAI
load_dotenv()
-''
+
SCRIPT_DIR = pathlib.Path(os.path.dirname(os.path.abspath(__file__)))
-agent_dir = SCRIPT_DIR / 'test_no_thinking'
+agent_dir = SCRIPT_DIR / 'file_system'
agent_dir.mkdir(exist_ok=True)
conversation_dir = agent_dir / 'conversations' / 'conversation'
print(f'Agent logs directory: {agent_dir}')
@@ -34,10 +34,7 @@ Finally, share the file with me.
NOTE: DO NOT USE extract_structured_data action - everything is visible in browser state.
""".strip('\n')
-llm = ChatOpenAI(
- model='gpt-4.1-mini',
-)
-
+llm = ChatOpenAI(model='gpt-4.1-mini')
agent = Agent(
task=task,