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 step method parity
Magnus Müllereb5e3f54e505
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex 6ea027d50..fec7809ed 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -426,10 +426,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at terminal main `ee- `add_new_task(...)` now updates the message manager follow-up history, resets pause/stop state, and recreates a valid event bus name without depending on the Python Agent run loop.- Proof: `test_rust_agent_initializes_message_manager_and_followup_state`.+84. Rust Agent step method parity+ - The Rust-backed `Agent` now exposes Browser Use's async `step(...)` method and routes it through a single Rust terminal turn.+ - Single-step Rust results now synchronize into `agent.state.last_result`, so Browser Use callers can inspect the last action result after `step(...)`, `take_step(...)`, `run(...)`, or `follow_up(...)`.+ - Proof: `test_rust_agent_step_runs_single_terminal_turn_and_updates_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` (57 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (58 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 350d1689f..dcd661d30 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -1439,6 +1439,10 @@ class Agent(Generic[AgentStructuredOutput]):"""Save current Browser Use file system state back onto AgentState."""self.state.file_system_state = self.file_system.get_state()+ async def step(self, step_info: AgentStepInfo | None = None) -> None:+ """Execute one Browser Use-style step through the Rust terminal core."""+ await self.take_step(step_info)+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:@@ -1682,6 +1686,9 @@ class Agent(Generic[AgentStructuredOutput]):metadata = self.history.history[-1].metadataif metadata is not None:self.state.n_steps = metadata.step_number+ action_results = self.history.action_results()+ if action_results:+ self.state.last_result = action_resultsasync def _save_conversation_if_requested(self) -> None:if not self.settings.save_conversation_path:diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 87e4b991f..ad084b38d 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -1156,6 +1156,39 @@ async def test_rust_agent_take_step_runs_one_terminal_turn():assert is_valid is True+async def test_rust_agent_step_runs_single_terminal_turn_and_updates_state(monkeypatch):+ from browser_use.rust import Agent++ monkeypatch.setenv('BROWSER_USE_TERMINAL_BINARY', '/tmp/browser-use-terminal')+ agent = Agent(task='step once', llm=type('LLM', (), {'model': 'gpt-test'})())+ seen = []++ async def fake_run_process(argv, timeout_seconds=None):+ seen.append((argv, timeout_seconds))+ return 0, 'Session: 12345678-1234-1234-1234-123456789abc\n', ''++ async def fake_load_events():+ return [+ {'event_type': 'browser.state', 'payload': {'url': 'https://example.com', 'title': 'Example'}},+ {'event_type': 'session.done', 'payload': {'result': 'step answer'}},+ ]++ agent._run_process = fake_run_process+ agent._load_events = fake_load_events++ result = await agent.step()++ assert result is None+ assert len(seen) == 1+ assert seen[0][0][0] == '/tmp/browser-use-terminal'+ assert 'max_turns=1' in seen[0][0]+ assert seen[0][1] == agent.settings.step_timeout+ assert agent.history.final_result() == 'step answer'+ assert agent.state.last_result is not None+ assert agent.state.last_result[-1].is_done is True+ assert agent.state.last_result[-1].extracted_content == 'step answer'++async def test_rust_agent_multi_act_preserves_done_action():from browser_use.rust import Agent