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
Add Rust agent completion logging parity
Magnus Müller0b8320ba22b3
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex 517644eba..b94b6c06d 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -436,10 +436,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at terminal main `ee- Callers can use `agent.screenshot_service.store_screenshot(...)` and `get_screenshot(...)` with the same storage layout as the Python Agent.- Proof: `test_rust_agent_initializes_screenshot_service`.+86. Rust Agent completion logging parity+ - The Rust-backed `Agent` now exposes Browser Use's async `log_completion()` method.+ - Completed Rust-backed runs now log task completion before invoking any registered done callback, matching the Python Agent lifecycle surface.+ - Proof: `test_rust_agent_logs_completion_before_done_callback`.+## 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` (59 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (60 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 795d06079..2cee6233f 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -1544,6 +1544,13 @@ class Agent(Generic[AgentStructuredOutput]):"""return None+ async def log_completion(self) -> None:+ """Log Browser Use-style task completion."""+ if self.history.is_successful():+ self.logger.info('Task completed successfully')+ else:+ self.logger.info('Task completed without success')+def run_sync(self,max_steps: int = 100,@@ -1667,7 +1674,10 @@ class Agent(Generic[AgentStructuredOutput]):await resultasync def _call_done_callback(self) -> None:- if self.register_done_callback is None or not self.history.is_done():+ if not self.history.is_done():+ return+ await self.log_completion()+ if self.register_done_callback is None:returnresult = self.register_done_callback(self.history)if inspect.isawaitable(result):diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex a775d314c..9a77cc7cb 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -1012,6 +1012,54 @@ async def test_rust_agent_invokes_browser_use_style_callbacks(monkeypatch):]+async def test_rust_agent_logs_completion_before_done_callback(monkeypatch):+ import logging++ from browser_use.rust import Agent++ monkeypatch.setenv('BROWSER_USE_TERMINAL_BINARY', '/tmp/browser-use-terminal')+ seen = []+ logged_messages = []+ original_info = logging.Logger.info++ def recording_info(logger, message, *args, **kwargs):+ logged_messages.append(str(message))+ return original_info(logger, message, *args, **kwargs)++ monkeypatch.setattr(logging.Logger, 'info', recording_info)++ def done_callback(history):+ seen.append(('done', history.final_result()))++ agent = Agent(+ task='start',+ task_id='completion-logs',+ llm=type('LLM', (), {'model': 'gpt-test'})(),+ register_done_callback=done_callback,+ )+ original_log_completion = agent.log_completion++ async def recording_log_completion():+ await original_log_completion()+ seen.append(('logged', None))++ agent.log_completion = recording_log_completion++ async def fake_run_process(argv, timeout_seconds=None):+ return 0, 'Session: 12345678-1234-1234-1234-123456789abc\n', ''++ async def fake_load_events():+ return [{'event_type': 'session.done', 'payload': {'result': 'logged answer'}}]++ agent._run_process = fake_run_process+ agent._load_events = fake_load_events++ await agent.run(max_steps=1)++ assert seen == [('logged', None), ('done', 'logged answer')]+ assert 'Task completed successfully' in logged_messages++async def test_rust_agent_invokes_new_step_callback(monkeypatch):from browser_use.rust import Agent