Skip to content

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

Preserve Rust follow-up task text

Magnus Müller7abe7fbc4e4f
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index db3cd55d8..53362e8d0 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -991,10 +991,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
- Reruns retry both terminal process exceptions and returned Browser Use history errors, raise after the final attempt when `skip_failures=False`, and otherwise return an error `ActionResult` instead of silently dropping the failure.
- Proof: `test_rust_agent_rerun_history_honors_retry_and_skip_controls`.
+196. Rust Agent follow-up task text parity
+ - Rust-backed `add_new_task(...)` now preserves Browser Use's raw follow-up task text on `agent.task` instead of appending structured-output schema instructions.
+ - Delegated terminal follow-up runs now send the same raw follow-up text through `browser-use-terminal followup ...`, while the existing `output_model_schema` remains attached to the agent for result parsing.
+ - Proof: `test_rust_agent_add_new_task_preserves_browser_use_raw_followup_task`.
+
## 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` (164 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (165 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.py
index 09726ffcd..62efd7e2b 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -3827,7 +3827,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
def add_new_task(self, new_task: str) -> None:
"""Add a follow-up task while keeping the same Browser Use-style agent object."""
- self.task = _task_with_schema(new_task, self.output_model_schema)
+ self.task = new_task
self._message_manager.add_new_task(new_task)
self.state.follow_up_task = True
self.state.stopped = False
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index 99431a3e6..1d6397130 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -4578,6 +4578,47 @@ def test_rust_agent_initializes_message_manager_and_followup_state():
assert agent.eventbus.name.isidentifier()
+async def test_rust_agent_add_new_task_preserves_browser_use_raw_followup_task(monkeypatch):
+ from browser_use.rust import Agent
+
+ class Answer(BaseModel):
+ answer: str
+
+ monkeypatch.setenv('BROWSER_USE_TERMINAL_BINARY', '/tmp/browser-use-terminal')
+ agent = Agent(
+ task='Initial structured task.',
+ llm=type('LLM', (), {'model': 'gpt-test'})(),
+ output_model_schema=Answer,
+ )
+ process_calls = []
+ load_count = 0
+
+ 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', ''
+ return 0, '', ''
+
+ async def fake_load_events():
+ nonlocal load_count
+ load_count += 1
+ return [{'event_type': 'session.done', 'payload': {'result': '{"answer":"ok"}'}}]
+
+ agent._run_process = fake_run_process
+ agent._load_events = fake_load_events
+
+ await agent.run(max_steps=2)
+ agent.add_new_task('Follow up with raw text.')
+
+ assert agent.task == 'Follow up with raw text.'
+ assert 'Expected output JSON schema' not in agent.task
+ assert '<follow_up_user_request> Follow up with raw text. </follow_up_user_request>' in agent.message_manager.task
+
+ await agent.run(max_steps=2)
+
+ assert process_calls[1][-3:] == ['followup', '12345678-1234-1234-1234-123456789abc', 'Follow up with raw text.']
+
+
def test_rust_agent_initializes_browser_use_session_and_file_system(tmp_path):
from browser_use.browser import BrowserProfile, BrowserSession
from browser_use.rust import Agent