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
Log Rust agent run metadata
Magnus Müllerbbc589b69f6f
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex ec5d7a394..c0faf5781 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -851,10 +851,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai- Failed or not-done Rust terminal histories now emit the same user-facing issue/CAPTCHA guidance path that the Python Agent runs after GIF/output handling and before eventbus shutdown.- Proof: `test_rust_agent_run_logs_final_outcome_guidance`.+168. Rust Agent run metadata logging parity+ - Terminal-backed `Agent.run()` now invokes Browser Use run-start metadata logging before Rust terminal execution.+ - The wrapper logs the task and Browser Use library version through the same public helper path that callers can also invoke directly.+ - Proof: `test_rust_agent_run_logs_browser_use_run_metadata`.+## 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` (139 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (140 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 fc945eb39..fcad2bdb4 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -2870,6 +2870,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):on_step_start: AgentHookFunc | None = None,on_step_end: AgentHookFunc | None = None,) -> AgentHistoryList[AgentStructuredOutput]:+ await self._log_agent_run()await self._call_callback(on_step_start, self)self._initialize_run_lifecycle_state()started = time.time()diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 9bb30837a..b26664ce2 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -11,6 +11,16 @@ import pytestfrom pydantic import BaseModel[email protected](autouse=True)+def _disable_rust_agent_latest_version_check(monkeypatch):+ import browser_use.rust.service as rust_service++ async def no_latest_version():+ return None++ monkeypatch.setattr(rust_service, 'check_latest_browser_use_version', no_latest_version)++def _load_real_v8_smoke_module():path = Path(__file__).parents[2] / 'examples' / 'rust_agent' / 'real_v8_smoke.py'spec = importlib.util.spec_from_file_location('real_v8_smoke', path)@@ -3000,6 +3010,9 @@ async def test_rust_agent_run_records_terminal_telemetry(monkeypatch):def info(self, message, *args, **kwargs):pass+ def debug(self, message, *args, **kwargs):+ pass+def error(self, message, *args, **kwargs):self.errors.append(message)@@ -3016,6 +3029,53 @@ async def test_rust_agent_run_records_terminal_telemetry(monkeypatch):assert logger.errors == ['Failed to log telemetry event: telemetry failed']+async def test_rust_agent_run_logs_browser_use_run_metadata(monkeypatch):+ import browser_use.rust.service as rust_service+ from browser_use.rust import Agent++ monkeypatch.setenv('BROWSER_USE_TERMINAL_BINARY', '/tmp/browser-use-terminal')++ async def latest_version():+ return None++ class RecordingLogger:+ def __init__(self):+ self.infos = []+ self.debugs = []+ self.errors = []++ def info(self, message, *args, **kwargs):+ self.infos.append(message)++ def debug(self, message, *args, **kwargs):+ self.debugs.append(message)++ def error(self, message, *args, **kwargs):+ self.errors.append(message)++ logger = RecordingLogger()+ monkeypatch.setattr(rust_service, 'check_latest_browser_use_version', latest_version)+ monkeypatch.setattr(Agent, 'logger', property(lambda self: logger))++ agent = Agent(task='Log run metadata.', llm=type('LLM', (), {'model': 'gpt-test'})())++ async def fake_run_process(argv, timeout_seconds=None):+ assert any(message.endswith('Task: Log run metadata.\033[0m') for message in logger.infos)+ assert any('Browser-Use Library Version' in message for message in logger.debugs)+ return 0, 'Session: 12345678-1234-1234-1234-123456789abc\n', ''++ async def fake_load_events():+ return [{'event_type': 'session.done', 'payload': {'result': 'logged metadata'}}]++ agent._run_process = fake_run_process+ agent._load_events = fake_load_events++ history = await agent.run(max_steps=1)++ assert history.final_result() == 'logged metadata'+ assert logger.errors == []++async def test_rust_agent_run_logs_token_usage_summary(monkeypatch):from browser_use.rust import Agent@@ -3065,6 +3125,9 @@ async def test_rust_agent_run_logs_final_outcome_guidance(monkeypatch):def info(self, message, *args, **kwargs):self.infos.append(message)+ def debug(self, message, *args, **kwargs):+ pass+def error(self, message, *args, **kwargs):self.errors.append(message)