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
Run Rust initial actions for first take step
Magnus Müller2efa0ddf3e60
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex 444c8edf8..f95cd000f 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -926,10 +926,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai- `on_step_start` now fires only when the Rust terminal execution or run-delegated follow-up path is about to execute, so stopped or paused-before-run paths do not report a step start that never happened.- Proof: `test_rust_agent_run_initializes_lifecycle_before_start_callback_error`.+183. Rust Agent first-step initial-actions parity+ - Direct `Agent.take_step(AgentStepInfo(step_number=0, ...))` now invokes configured Browser Use initial actions before the one-step Rust terminal run.+ - Interrupted initial actions are swallowed like Browser Use's first-step path, allowing the caller's one-step execution to continue with current agent state.+ - Proof: `test_rust_agent_take_step_executes_initial_actions_on_first_step`.+## 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` (154 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (155 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 39be9b362..4f00e8c08 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -3623,6 +3623,11 @@ class Agent(Generic[Context, AgentStructuredOutput]):"""Take one Rust terminal turn and return Browser Use-style step status."""if step_info is not None:self.state.n_steps = max(self.state.n_steps, step_info.step_number)+ if step_info.step_number == 0:+ try:+ await self._execute_initial_actions()+ except InterruptedError:+ passhistory = await self.run(max_steps=1)if history.is_done():return True, Truediff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 3428350f9..cba5f5f76 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -4901,6 +4901,51 @@ async def test_rust_agent_take_step_matches_browser_use_non_final_status():assert is_valid is False+async def test_rust_agent_take_step_executes_initial_actions_on_first_step():+ from browser_use.agent.views import AgentStepInfo+ from browser_use.rust import Agent++ agent = Agent(+ task='step once after initial action',+ initial_actions=[{'navigate': {'url': 'https://example.com', 'new_tab': False}}],+ )+ seen = []++ class DoneHistory:+ def is_done(self):+ return True++ async def fake_execute_initial_actions():+ seen.append('initial_actions')++ async def fake_run(max_steps=100, on_step_start=None, on_step_end=None):+ seen.append(('run', max_steps))+ return DoneHistory()++ agent._execute_initial_actions = fake_execute_initial_actions+ agent.run = fake_run++ is_done, is_valid = await agent.take_step(AgentStepInfo(step_number=0, max_steps=3))++ assert seen == ['initial_actions', ('run', 1)]+ assert is_done is True+ assert is_valid is True++ seen.clear()++ async def fake_interrupted_initial_actions():+ seen.append('interrupted_initial_actions')+ raise InterruptedError++ agent._execute_initial_actions = fake_interrupted_initial_actions++ is_done, is_valid = await agent.take_step(AgentStepInfo(step_number=0, max_steps=3))++ assert seen == ['interrupted_initial_actions', ('run', 1)]+ assert is_done is True+ 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