Skip to content

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

Match Rust constructor alias handling

Magnus Müllere460108ccb62
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index 1777da945..debfd4290 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -1046,10 +1046,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
- Default construction now preserves downstream Browser Use defaults that depend on the resolved LLM, including `flash_mode=True`, `settings.page_extraction_llm is agent.llm`, and the public `agent.model` value.
- Proof: `test_rust_agent_defaults_llm_like_browser_use`.
+207. Rust Agent constructor alias parity
+ - Rust-backed construction now matches Browser Use alias precedence by accepting both `tools` and `controller` while choosing `tools` when both are supplied.
+ - The `browser` plus `browser_session` conflict now raises Browser Use's public error message instead of the Rust wrapper's shorter old-interface message.
+ - Proof: `test_rust_agent_constructor_aliases_match_browser_use`.
+
## 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` (175 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (176 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 1714a7101..c2bbeaf99 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -2362,7 +2362,7 @@ def _resolve_tools(
use_vision: bool | Literal['auto'],
display_files_in_done_text: bool,
) -> Any:
- resolved_tools = controller or tools
+ resolved_tools = tools if tools is not None else controller
if resolved_tools is None:
exclude_actions = ['screenshot'] if use_vision is False else []
resolved_tools = Tools(exclude_actions=exclude_actions, display_files_in_done_text=display_files_in_done_text)
@@ -2534,9 +2534,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
):
llm = _resolve_default_llm(llm)
if browser and browser_session:
- raise ValueError('Cannot specify both "browser" and "browser_session".')
- if tools is not None and controller is not None:
- raise ValueError('Cannot specify both "tools" and "controller".')
+ raise ValueError('Cannot specify both "browser" and "browser_session" parameters. Use "browser" for the cleaner API.')
if getattr(llm, 'provider', None) == 'browser-use':
flash_mode = True
if page_extraction_llm is None:
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index cafc32ec2..9eccaa61f 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -2854,6 +2854,52 @@ def test_rust_agent_eventbus_name_matches_browser_use_suffix_prefix():
assert rust_agent_with_hyphen.eventbus.name.isidentifier()
+def test_rust_agent_constructor_aliases_match_browser_use():
+ from browser_use.agent.service import _PythonAgent as BrowserUseAgent
+ from browser_use.rust import Agent as RustAgent
+ from browser_use.tools.service import Tools
+
+ class LLM:
+ model = 'gpt-test'
+ provider = 'test'
+
+ async def ainvoke(self, messages, output_format=None, **kwargs):
+ return type('Result', (), {'usage': None})()
+
+ tools = Tools()
+ controller = Tools()
+
+ browser_use_agent = BrowserUseAgent(
+ task='Resolve aliases.',
+ llm=LLM(),
+ tools=tools,
+ controller=controller,
+ directly_open_url=False,
+ )
+ rust_agent = RustAgent(
+ task='Resolve aliases.',
+ llm=LLM(),
+ tools=tools,
+ controller=controller,
+ directly_open_url=False,
+ )
+
+ assert browser_use_agent.tools is tools
+ assert rust_agent.tools is tools
+
+ expected_error = 'Cannot specify both "browser" and "browser_session" parameters. Use "browser" for the cleaner API.'
+ for agent_class in (BrowserUseAgent, RustAgent):
+ with pytest.raises(ValueError) as exc_info:
+ agent_class(
+ task='Conflicting browser aliases.',
+ llm=LLM(),
+ browser=object(),
+ browser_session=object(),
+ directly_open_url=False,
+ )
+ assert str(exc_info.value) == expected_error
+
+
def test_rust_agent_initializes_tools_and_action_models():
from browser_use.rust import Agent
from browser_use.tools.service import Tools