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
Match Rust completion messages
Magnus Müller2571b4953412
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex 65a4cdda6..daabd975c 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -1081,10 +1081,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai- This preserves caller-visible log filtering and diagnostics that depend on `agent.logger.name`.- Proof: `test_rust_agent_logger_name_matches_browser_use`.+214. Rust Agent completion-message parity+ - Rust-backed `log_completion()` now emits Browser Use's exact success and failure completion messages.+ - This preserves the visible task-completion status feedback for direct helper calls and run-level done-callback ordering.+ - Proof: `test_rust_agent_log_completion_matches_browser_use`.+## Current Verification- `python3 -m py_compile browser_use/agent/service.py 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` (182 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (183 tests)- `cargo build -q -p browser-use-cli` on terminal branch `magnus/browser-use-rust-main-integration`- `cargo test -q -p browser-use-cli run_codex_session_command_accepts_task_id_and_model -- --nocapture`- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-agent selected_remote_cdp_mode_allows_remote_cdp_connect -- --nocapture`diff --git a/browser_use/rust/service.py b/browser_use/rust/service.pyindex 5ebb6b5f3..662b8496c 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -4033,9 +4033,9 @@ class Agent(Generic[Context, AgentStructuredOutput]):async def log_completion(self) -> None:"""Log Browser Use-style task completion."""if self.history.is_successful():- self.logger.info('Task completed successfully')+ self.logger.info('✅ Task completed successfully')else:- self.logger.info('Task completed without success')+ self.logger.info('❌ Task completed without success')def run_sync(self,diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 8fa33aa33..de4d090a1 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -5345,7 +5345,73 @@ async def test_rust_agent_logs_completion_before_done_callback(monkeypatch):await agent.run(max_steps=1)assert seen == [('logged', None), ('done', 'logged answer')]- assert 'Task completed successfully' in logged_messages+ assert '✅ Task completed successfully' in logged_messages+++async def test_rust_agent_log_completion_matches_browser_use(monkeypatch):+ import browser_use.rust.service as rust_service+ from browser_use.agent.service import _PythonAgent as BrowserUseAgent+ from browser_use.rust import Agent as RustAgent++ class RecordingLogger:+ def __init__(self):+ self.infos = []++ def debug(self, message, *args, **kwargs):+ pass++ def info(self, message, *args, **kwargs):+ self.infos.append(message)++ def warning(self, message, *args, **kwargs):+ pass++ def error(self, message, *args, **kwargs):+ pass++ class LLM:+ model = 'gpt-test'+ provider = 'test'++ async def ainvoke(self, messages, output_format=None, **kwargs):+ return type('Result', (), {'usage': None})()++ def make_history(success: bool):+ events = [{'event_type': 'session.done', 'payload': {'result': 'done'}}] if success else []+ return rust_service._history_from_events(+ events,+ model='gpt-test',+ started=1.0,+ finished=2.0,+ output_model_schema=None,+ process_error=None if success else 'failed',+ )++ for index, success in enumerate((True, False)):+ browser_use_logger = RecordingLogger()+ rust_logger = RecordingLogger()+ monkeypatch.setattr(BrowserUseAgent, 'logger', property(lambda self, logger=browser_use_logger: logger))+ monkeypatch.setattr(RustAgent, 'logger', property(lambda self, logger=rust_logger: logger))++ browser_use_agent = BrowserUseAgent(+ task='Log completion parity.',+ llm=LLM(),+ task_id=f'browsercompletionbu{index}',+ directly_open_url=False,+ )+ rust_agent = RustAgent(+ task='Log completion parity.',+ llm=LLM(),+ task_id=f'rustcompletionrs{index}',+ directly_open_url=False,+ )+ browser_use_agent.history = make_history(success)+ rust_agent.history = make_history(success)++ await browser_use_agent.log_completion()+ await rust_agent.log_completion()++ assert rust_logger.infos == browser_use_logger.infosasync def test_rust_agent_generates_gif_after_done_callback(monkeypatch, tmp_path):