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
Sync Rust direct follow-up state
Magnus Müller6e91a92e13e8
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex be3f024cd..555f6d2b0 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -1001,10 +1001,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai- Terminal conversation snapshots continue to write under the resolved directory while preserving the configured file encoding.- Proof: `test_rust_agent_resolves_conversation_path_like_browser_use`.+198. Rust Agent direct follow-up state parity+ - Direct `Agent.follow_up(...)` now updates Browser Use-facing task state through the same follow-up task path as `add_new_task(...)` while clearing the pending follow-up flag because the direct call executes immediately.+ - Follow-up terminal stdout/stderr from both the append and rerun subprocesses are now preserved on the agent and in saved conversation snapshots.+ - Proof: `test_rust_agent_direct_follow_up_updates_task_state_and_transcript`.+## 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` (166 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (167 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 77f7da3ba..9e2faaf5b 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -3054,9 +3054,11 @@ class Agent(Generic[Context, AgentStructuredOutput]):if not self.terminal_session_id:raise RustAgentError('No active Rust session. Call run() before follow_up().')resolved_max_steps = max_steps if max_steps is not None else self.kwargs.get('max_steps', 100)+ self.add_new_task(task)+ self.state.follow_up_task = Falseself._register_run_signal_handler(resolved_max_steps)try:- return await self._follow_up_terminal(task, max_steps=max_steps, resolved_max_steps=resolved_max_steps)+ return await self._follow_up_terminal(self.task, max_steps=max_steps, resolved_max_steps=resolved_max_steps)except asyncio.CancelledError:await self._finalize_exceptional_run(max_steps=resolved_max_steps, agent_run_error='CancelledError')raise@@ -3085,16 +3087,20 @@ class Agent(Generic[Context, AgentStructuredOutput]):[binary, *self._state_dir_args(), 'followup', self.terminal_session_id, task],timeout_seconds=self.settings.step_timeout,)+ self.last_stdout = stdout_text+ self.last_stderr = stderr_textif returncode:raise RustAgentError(stderr_text or stdout_text)- returncode, _stdout_text, stderr_text = await self._run_process(+ returncode, run_stdout_text, run_stderr_text = await self._run_process(self._run_existing_argv(resolved_max_steps),timeout_seconds=self.settings.step_timeout,)+ self.last_stdout = '\n'.join(part for part in (stdout_text.strip(), run_stdout_text.strip()) if part)+ self.last_stderr = '\n'.join(part for part in (stderr_text.strip(), run_stderr_text.strip()) if part)finished = time.time()process_error = Noneif returncode:- process_error = stderr_text.strip() or f'browser-use-terminal exited with code {returncode}'+ process_error = run_stderr_text.strip() or f'browser-use-terminal exited with code {returncode}'self.last_events = await self._load_events()self.result = _history_from_events(self.last_events,diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 331832ab8..bdba25080 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -4184,6 +4184,59 @@ async def test_rust_agent_run_follow_up_invokes_on_step_end(monkeypatch):assert process_calls[1][-3] == 'followup'+async def test_rust_agent_direct_follow_up_updates_task_state_and_transcript(tmp_path, monkeypatch):+ from browser_use.rust import Agent++ monkeypatch.setenv('BROWSER_USE_TERMINAL_BINARY', '/tmp/browser-use-terminal')+ process_calls = []+ load_count = 0+ agent = Agent(+ task='Start direct follow-up state.',+ llm=type('LLM', (), {'model': 'gpt-test'})(),+ task_id='direct-followup',+ save_conversation_path=tmp_path,+ )++ async def fake_run_process(argv, timeout_seconds=None):+ process_calls.append(argv)+ if len(process_calls) == 1:+ return 0, 'Session: 12345678-1234-1234-1234-123456789abc\n', ''+ if len(process_calls) == 2:+ return 0, 'followup accepted\n', 'followup stderr\n'+ return 0, 'rerun stdout\n', 'rerun stderr\n'++ async def fake_load_events():+ nonlocal load_count+ load_count += 1+ return [{'event_type': 'session.done', 'payload': {'result': f'direct follow-up {load_count}'}}]++ agent._run_process = fake_run_process+ agent._load_events = fake_load_events++ initial = await agent.run(max_steps=3)+ history = await agent.follow_up('Direct raw follow-up task.', max_steps=4)++ assert initial.final_result() == 'direct follow-up 1'+ assert history.final_result() == 'direct follow-up 2'+ assert agent.task == 'Direct raw follow-up task.'+ assert agent.state.follow_up_task is False+ assert '<follow_up_user_request> Direct raw follow-up task. </follow_up_user_request>' in agent.message_manager.task+ assert process_calls[1][-3:] == [+ 'followup',+ '12345678-1234-1234-1234-123456789abc',+ 'Direct raw follow-up task.',+ ]+ assert agent.last_stdout == 'followup accepted\nrerun stdout'+ assert agent.last_stderr == 'followup stderr\nrerun stderr'++ files = list(tmp_path.glob('conversation_direct-followup_*.json'))+ assert len(files) == 1+ snapshot = json.loads(files[0].read_text(encoding='utf-8'))+ assert snapshot['task'] == 'Direct raw follow-up task.'+ assert snapshot['stdout'] == 'followup accepted\nrerun stdout'+ assert snapshot['stderr'] == 'followup stderr\nrerun stderr'++async def test_rust_agent_run_logs_browser_use_lifecycle_dispatch(monkeypatch):from browser_use.rust import Agent