Skip to content

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

Add real v8 Rust agent smoke runner

Magnus Müller6e06a564bc53
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index b7c520ab5..503863aff 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -36,9 +36,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at latest pulled mai
- Proof: managed-headless smoke returned `Example Domain` for `https://example.com`.
- Proof: remote-CDP smoke against an externally launched Chromium DevTools endpoint returned `Example Domain`.
+7. real_v8 smoke runner
+ - `examples/rust_agent/real_v8_smoke.py` loads `terminal/datasets/real_v8.json`, selects one benchmark case by zero-based index or `task_id`, and runs it through the same Rust-backed `Agent` API.
+ - It accepts `BU_CDP_URL` or `BROWSER_USE_CDP_URL` so the same script can target a Browser Use cloud browser CDP endpoint when credentials are available.
+ - Proof: `test_real_v8_smoke_selects_case_by_index_and_task_id`.
+ - Proof: remote-CDP e2e smoke on real_v8 `task_id=18` returned `Paramjit Uppal, Founder`.
+
## 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`
+- `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`
- `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`
@@ -49,8 +55,12 @@ Terminal core branch: `magnus/browser-use-rust-integration` at latest pulled mai
- Launch external Chromium with `--remote-debugging-port=49333`.
- `BROWSER_USE_TERMINAL_BINARY=/home/exedev/Developer/terminal/target/debug/browser-use-terminal BROWSER_USE_CDP_URL=http://127.0.0.1:49333 BU_TASK='Open https://example.com and report the page title only.' BU_MAX_STEPS=12 timeout 300 uv run python examples/rust_agent/basic.py`
- Output: `Example Domain`
+- real_v8 remote-CDP end-to-end:
+ - Launch external Chromium with `--remote-debugging-port=49333`.
+ - `BROWSER_USE_TERMINAL_BINARY=/home/exedev/Developer/terminal/target/debug/browser-use-terminal BROWSER_USE_CDP_URL=http://127.0.0.1:49333 timeout 600 uv run python examples/rust_agent/real_v8_smoke.py --task-id 18 --max-steps 30`
+ - Output: `{"task_id": "18", "successful": true, "final_result": "Paramjit Uppal, Founder"}`
## Not Verified Yet
- Browser Use cloud remote browser end-to-end was not run because `browser-use-terminal auth status` reports `Browser Use cloud key: not connected`. The remote-CDP path has been verified against an external CDP browser.
-- Real v8 eval smoke was not rerun after this reset because the current objective prioritizes the latest-main integration branch and the VM has no connected Browser Use cloud key.
+- real_v8 was verified through remote CDP against an external local Chromium endpoint, not a Browser Use cloud browser, because the VM has no connected Browser Use cloud key.
diff --git a/examples/rust_agent/real_v8_smoke.py b/examples/rust_agent/real_v8_smoke.py
new file mode 100644
index 000000000..10e7d8ca3
--- /dev/null
+++ b/examples/rust_agent/real_v8_smoke.py
@@ -0,0 +1,122 @@
+"""Run one real_v8 benchmark task through the Rust-backed Browser Use Agent.
+
+Set BROWSER_USE_TERMINAL_BINARY when the terminal binary is not on PATH.
+Set BU_CDP_URL or BROWSER_USE_CDP_URL to attach to a remote Browser Use cloud browser.
+"""
+
+from __future__ import annotations
+
+import argparse
+import asyncio
+import json
+import os
+from pathlib import Path
+from typing import Any
+
+from browser_use import Agent, BrowserSession
+
+
+DEFAULT_DATASET = Path('/home/exedev/Developer/terminal/datasets/real_v8.json')
+
+
+def load_cases(dataset: Path) -> list[dict[str, str]]:
+ with dataset.open(encoding='utf-8') as file:
+ raw_cases = json.load(file)
+ if not isinstance(raw_cases, list):
+ raise ValueError(f'{dataset} must contain a JSON array')
+
+ cases: list[dict[str, str]] = []
+ for idx, raw_case in enumerate(raw_cases):
+ if not isinstance(raw_case, dict):
+ raise ValueError(f'{dataset} case {idx} must be an object')
+ task_id = raw_case.get('task_id')
+ task = raw_case.get('confirmed_task') or raw_case.get('task')
+ if not isinstance(task_id, str) or not isinstance(task, str) or not task.strip():
+ raise ValueError(f'{dataset} case {idx} must contain string task_id and confirmed_task')
+ cases.append({'task_id': task_id, 'confirmed_task': task})
+ return cases
+
+
+def select_case(cases: list[dict[str, str]], *, index: int | None, task_id: str | None) -> dict[str, str]:
+ if index is not None and task_id is not None:
+ raise ValueError('Select by index or task_id, not both')
+ if task_id is not None:
+ for case in cases:
+ if case['task_id'] == task_id:
+ return case
+ raise ValueError(f'task_id {task_id!r} was not found')
+ selected_index = 0 if index is None else index
+ if selected_index < 0 or selected_index >= len(cases):
+ raise ValueError(f'index {selected_index} is outside dataset range 0..{len(cases) - 1}')
+ return cases[selected_index]
+
+
+def _int_from_env(name: str, default: int) -> int:
+ value = os.environ.get(name)
+ return int(value) if value else default
+
+
+def parse_args() -> argparse.Namespace:
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument(
+ '--dataset',
+ type=Path,
+ default=Path(os.environ.get('REAL_V8_DATASET', DEFAULT_DATASET)),
+ help='Path to real_v8.json.',
+ )
+ parser.add_argument(
+ '--index',
+ type=int,
+ default=int(os.environ['REAL_V8_INDEX']) if os.environ.get('REAL_V8_INDEX') else None,
+ help='Zero-based case index. Defaults to 0 when --task-id is not set.',
+ )
+ parser.add_argument(
+ '--task-id',
+ default=os.environ.get('REAL_V8_TASK_ID'),
+ help='Task id from the dataset.',
+ )
+ parser.add_argument(
+ '--max-steps',
+ type=int,
+ default=_int_from_env('BU_MAX_STEPS', 40),
+ help='Maximum Rust terminal agent turns.',
+ )
+ parser.add_argument(
+ '--cdp-url',
+ default=os.environ.get('BU_CDP_URL') or os.environ.get('BROWSER_USE_CDP_URL'),
+ help='Optional remote browser CDP endpoint.',
+ )
+ parser.add_argument('--list', action='store_true', help='Print task ids and first task line, then exit.')
+ return parser.parse_args()
+
+
+async def run_smoke(args: argparse.Namespace) -> None:
+ cases = load_cases(args.dataset)
+ if args.list:
+ for idx, case in enumerate(cases):
+ first_line = case['confirmed_task'].strip().splitlines()[0]
+ print(f'{idx}\t{case["task_id"]}\t{first_line[:120]}')
+ return
+
+ case = select_case(cases, index=args.index, task_id=args.task_id)
+ browser_session = BrowserSession(cdp_url=args.cdp_url) if args.cdp_url else None
+ agent = Agent(task=case['confirmed_task'], browser_session=browser_session, task_id=case['task_id'])
+ history = await agent.run(max_steps=args.max_steps)
+ final_result = history.final_result()
+ print(json.dumps(_summary(case, final_result, history.is_successful(), agent), indent=2))
+
+
+def _summary(case: dict[str, str], final_result: str | None, is_successful: bool | None, agent: Any) -> dict[str, Any]:
+ errors = [error for error in agent.history.errors() if error]
+ return {
+ 'task_id': case['task_id'],
+ 'successful': is_successful,
+ 'session_id': agent.session_id,
+ 'final_result': final_result,
+ 'errors': errors,
+ 'urls': agent.history.urls(),
+ }
+
+
+if __name__ == '__main__':
+ asyncio.run(run_smoke(parse_args()))
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index 8bf6aa873..24f13c33a 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -1,8 +1,23 @@
from __future__ import annotations
+import importlib.util
+import json
+from pathlib import Path
+
+import pytest
from pydantic import BaseModel
+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)
+ assert spec is not None
+ assert spec.loader is not None
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ return module
+
+
def test_top_level_agent_uses_rust_wrapper():
from browser_use import Agent as TopLevelAgent
from browser_use.rust import Agent as RustAgent
@@ -151,3 +166,24 @@ def test_rust_history_marks_missing_terminal_result_as_error():
assert history.final_result() is None
assert history.is_done() is False
assert history.errors() == ['Rust terminal session did not produce a final result.']
+
+
+def test_real_v8_smoke_selects_case_by_index_and_task_id(tmp_path):
+ module = _load_real_v8_smoke_module()
+ dataset = tmp_path / 'real_v8.json'
+ dataset.write_text(
+ json.dumps(
+ [
+ {'task_id': '1', 'confirmed_task': 'first task'},
+ {'task_id': '2', 'confirmed_task': 'second task'},
+ ]
+ ),
+ encoding='utf-8',
+ )
+
+ cases = module.load_cases(dataset)
+
+ assert module.select_case(cases, index=1, task_id=None)['confirmed_task'] == 'second task'
+ assert module.select_case(cases, index=None, task_id='1')['confirmed_task'] == 'first task'
+ with pytest.raises(ValueError, match='Select by index or task_id'):
+ module.select_case(cases, index=0, task_id='1')