Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Track Rust agent downloaded files
Magnus Müller4611788d2a89
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex 17abf93bf..34f2a01e8 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -2,7 +2,7 @@Branch: `magnus/browser-use-rust-core-integration`-Terminal core branch: `magnus/browser-use-rust-integration` at terminal main `f82ef73` plus small CLI/browser-mode support commits.+Terminal core branch: `magnus/browser-use-rust-integration` at terminal main `f036761` plus small CLI/browser-mode support commits.## Built Features@@ -401,10 +401,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at terminal main `f8- The wrapper now creates Browser Use-style `agent_directory`, `file_system`, `file_system_path`, restored `file_system_state`, and download-path tracking attributes while preserving duck-typed profile/session inputs for lightweight tests and custom callers.- Proof: `test_rust_agent_initializes_browser_use_session_and_file_system`.+79. Rust Agent downloaded file tracking+ - The Rust-backed `Agent` now mirrors Browser Use's downloaded-file bookkeeping for supplied sessions by syncing `browser_session.downloaded_files` into `available_file_paths` after Rust runs and follow-ups.+ - The wrapper also exposes `save_file_system_state()` so callers can persist the Browser Use `FileSystem` state back onto the agent state.+ - Proof: `test_rust_agent_tracks_downloaded_files_and_saves_file_system_state`.+## Current Verification- `python3 -m py_compile browser_use/rust/service.py browser_use/rust/__init__.py browser_use/__init__.py tests/ci/test_rust_agent.py examples/rust_agent/basic.py examples/rust_agent/real_v8_smoke.py`-- `uv run pytest -q tests/ci/test_rust_agent.py` (53 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (54 tests)- `cargo build -q -p browser-use-cli`- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-agent selected_remote_cdp_mode_allows_remote_cdp_connect -- --nocapture`- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-agent bare_browser_connect_resolves_to_selected_managed_mode_with_launch_args -- --nocapture`diff --git a/browser_use/rust/service.py b/browser_use/rust/service.pyindex 1f2e95eec..5cce7d316 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -1174,6 +1174,7 @@ class Agent(Generic[AgentStructuredOutput]):)self.history = self.resultself._sync_state_from_history()+ await self._check_and_update_downloads('run')await self._save_conversation_if_requested()await self._call_new_step_callback()await self._call_callback(on_step_end, self)@@ -1210,6 +1211,7 @@ class Agent(Generic[AgentStructuredOutput]):)self.history = self.resultself._sync_state_from_history()+ await self._check_and_update_downloads('follow_up')await self._save_conversation_if_requested()await self._call_new_step_callback()await self._call_done_callback()@@ -1221,6 +1223,41 @@ class Agent(Generic[AgentStructuredOutput]):def usage(self) -> UsageSummary | None:return self.history.usage+ async def _check_and_update_downloads(self, context: str = '') -> None:+ """Mirror Browser Use's downloaded-file tracking for supplied sessions."""+ if not self.has_downloads_path or self.browser_session is None:+ return+ try:+ current_downloads = getattr(self.browser_session, 'downloaded_files', None)+ if callable(current_downloads):+ current_downloads = current_downloads()+ if inspect.isawaitable(current_downloads):+ current_downloads = await current_downloads+ if not isinstance(current_downloads, list):+ return+ if current_downloads != self._last_known_downloads:+ self._update_available_file_paths(current_downloads)+ self._last_known_downloads = list(current_downloads)+ except Exception:+ _ = context++ def _update_available_file_paths(self, downloads: list[str]) -> None:+ """Update available_file_paths with downloaded files, preserving caller order."""+ if not self.has_downloads_path:+ return+ current_files = list(self.available_file_paths or [])+ seen = set(current_files)+ for file_path in downloads:+ if not isinstance(file_path, str) or not file_path or file_path in seen:+ continue+ current_files.append(file_path)+ seen.add(file_path)+ self.available_file_paths = current_files++ def save_file_system_state(self) -> None:+ """Save current Browser Use file system state back onto AgentState."""+ self.state.file_system_state = self.file_system.get_state()+async def take_step(self, step_info: AgentStepInfo | None = None) -> tuple[bool, bool]:"""Take one Rust terminal turn and return Browser Use-style step status."""if step_info is not None:diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 148670d72..6917ef80d 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -791,6 +791,36 @@ def test_rust_agent_initializes_browser_use_session_and_file_system(tmp_path):assert agent.state.file_system_state is not None+async def test_rust_agent_tracks_downloaded_files_and_saves_file_system_state(tmp_path):+ from browser_use.rust import Agent++ class BrowserProfile:+ downloads_path = tmp_path / 'downloads'++ class BrowserSession:+ browser_profile = BrowserProfile()+ downloaded_files = ['/tmp/report.csv', '/tmp/report.csv']++ agent = Agent(+ task='Use downloaded files.',+ browser_session=BrowserSession(),+ available_file_paths=['/tmp/input.txt'],+ file_system_path=str(tmp_path / 'agent-files'),+ )++ await agent._check_and_update_downloads('test')+ BrowserSession.downloaded_files = ['/tmp/report.csv', '/tmp/summary.pdf']+ await agent._check_and_update_downloads('test')++ agent.state.file_system_state = None+ agent.save_file_system_state()++ assert agent.available_file_paths == ['/tmp/input.txt', '/tmp/report.csv', '/tmp/summary.pdf']+ assert agent._last_known_downloads == ['/tmp/report.csv', '/tmp/summary.pdf']+ assert agent.state.file_system_state is not None+ assert agent.state.file_system_state.base_dir == str(tmp_path / 'agent-files')++def test_rust_agent_adds_available_files_to_task_context():from browser_use.rust import Agent