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
Match Rust agent constructor type hints
Magnus Müller3b6b17cbd192
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex 6bd9cf899..3669b084c 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -561,10 +561,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at terminal main `ee- Hyphenated task-id suffixes are sanitized into valid identifiers, and follow-up task event buses keep the same base prefix with a unique suffix.- Proof: `test_rust_agent_eventbus_name_matches_browser_use_suffix_prefix`.+111. Rust Agent constructor type-hint parity+ - The Rust-backed `Agent.__init__(...)` now exposes Browser Use's constructor type metadata for the core public parameters that users and tooling introspect.+ - LLM, callback, structured-output, extraction-LLM, sample-image, and tools/controller annotations now mirror Browser Use's concrete types, while unannotated `**kwargs` and constructor return metadata stay unannotated like the Python Agent.+ - Proof: `test_rust_agent_constructor_type_hints_match_browser_use_core_params`.+## 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` (84 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (85 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`@@ -629,5 +634,5 @@ Terminal core branch: `magnus/browser-use-rust-integration` at terminal main `ee## Not Verified Yet-- Browser Use cloud remote browser end-to-end was not run because `browser-use-terminal auth status` reports `Browser Use cloud key: not connected`. The remote-CDP path has been verified against an external CDP browser.-- real_v8 was verified through remote CDP against an external local Chromium endpoint, not a Browser Use cloud browser, because the VM has no connected Browser Use cloud key.+- Browser Use cloud remote browser end-to-end has not been rerun yet after locating `/home/exedev/.evaluation_tool_env`; when that file is sourced, `browser-use-terminal auth status` reports the Browser Use cloud key as connected.+- real_v8 was verified through remote CDP against an external local Chromium endpoint, not a Browser Use cloud browser. The next E2E verification target is rerunning this with the sourced Browser Use cloud key.diff --git a/browser_use/rust/service.py b/browser_use/rust/service.pyindex dfbd71bf7..170e2a58b 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -33,12 +33,15 @@ from browser_use.agent.views import (AgentSettings,AgentState,AgentStepInfo,+ AgentStructuredOutput,StepMetadata,)from browser_use.browser import BrowserProfile, BrowserSessionfrom browser_use.browser.profile import CHROME_DETERMINISTIC_RENDERING_ARGS, CHROME_DISABLE_SECURITY_ARGS, CHROME_DOCKER_ARGS-from browser_use.browser.views import BrowserStateHistory, TabInfo+from browser_use.browser.views import BrowserStateHistory, BrowserStateSummary, TabInfofrom browser_use.filesystem.file_system import FileSystem+from browser_use.llm.base import BaseChatModel+from browser_use.llm.messages import ContentPartImageParam, ContentPartTextParamfrom browser_use.screenshots.service import ScreenshotServicefrom browser_use.telemetry.service import ProductTelemetryfrom browser_use.telemetry.views import AgentTelemetryEvent@@ -49,9 +52,12 @@ from browser_use.utils import URL_PATTERN, check_latest_browser_use_version, getContext = TypeVar('Context')-AgentStructuredOutput = TypeVar('AgentStructuredOutput', bound=BaseModel)AgentHookFunc = Callable[[Any], Awaitable[None] | None]-AgentDoneCallback = Callable[[AgentHistoryList], Awaitable[None] | None]+AgentNewStepCallback = (+ Callable[[BrowserStateSummary, AgentOutput, int], None]+ | Callable[[BrowserStateSummary, AgentOutput, int], Awaitable[None]]+)+AgentDoneCallback = Callable[[AgentHistoryList], Awaitable[None]] | Callable[[AgentHistoryList], None]class RustAgentError(RuntimeError):@@ -1061,15 +1067,15 @@ class Agent(Generic[Context, AgentStructuredOutput]):def __init__(self,task: str,- llm: Any | None = None,+ llm: BaseChatModel | None = None,browser_profile: BrowserProfile | None = None,browser_session: BrowserSession | None = None,browser: BrowserSession | None = None,- tools: Any | None = None,- controller: Any | None = None,+ tools: Tools[Context] | None = None,+ controller: Tools[Context] | None = None,sensitive_data: dict[str, str | dict[str, str]] | None = None,initial_actions: list[dict[str, dict[str, Any]]] | None = None,- register_new_step_callback: Callable[..., Awaitable[None] | None] | None = None,+ register_new_step_callback: AgentNewStepCallback | None = None,register_done_callback: AgentDoneCallback | None = None,register_external_agent_status_raise_error_callback: Callable[[], Awaitable[bool]] | None = None,register_should_stop_callback: Callable[[], Awaitable[bool]] | None = None,@@ -1087,7 +1093,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):use_thinking: bool = True,flash_mode: bool = False,max_history_items: int | None = None,- page_extraction_llm: Any | None = None,+ page_extraction_llm: BaseChatModel | None = None,injected_agent_state: AgentState | None = None,source: str | None = None,file_system_path: str | None = None,@@ -1100,11 +1106,11 @@ class Agent(Generic[Context, AgentStructuredOutput]):step_timeout: int = 120,directly_open_url: bool = True,include_recent_events: bool = False,- sample_images: list[Any] | None = None,+ sample_images: list[ContentPartTextParam | ContentPartImageParam] | None = None,final_response_after_failure: bool = True,_url_shortening_limit: int = 25,- **kwargs: Any,- ) -> None:+ **kwargs,+ ):if browser and browser_session:raise ValueError('Cannot specify both "browser" and "browser_session".')if tools is not None and controller is not None:diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex bdce78e28..ecaedd016 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -5,7 +5,7 @@ import importlib.utilimport jsonimport sysfrom pathlib import Path-from typing import get_args, get_origin+from typing import get_args, get_origin, get_type_hintsimport pytestfrom pydantic import BaseModel@@ -94,6 +94,40 @@ def test_rust_agent_constructor_signature_matches_browser_use_order(tmp_path):assert agent.task_id == 'signature-task-id'+def test_rust_agent_constructor_type_hints_match_browser_use_core_params():+ from browser_use.agent.service import _PythonAgent as BrowserUseAgent+ from browser_use.rust import Agent as RustAgent+ from browser_use.tools.service import Tools++ browser_use_hints = get_type_hints(BrowserUseAgent.__init__)+ rust_hints = get_type_hints(RustAgent.__init__)++ for name in (+ 'llm',+ 'register_new_step_callback',+ 'register_done_callback',+ 'output_model_schema',+ 'page_extraction_llm',+ 'sample_images',+ ):+ assert rust_hints[name] == browser_use_hints[name]++ def assert_tools_context_hint(annotation):+ inner = [arg for arg in get_args(annotation) if arg is not type(None)]+ assert len(inner) == 1+ assert get_origin(inner[0]) is Tools+ type_args = get_args(inner[0])+ assert len(type_args) == 1+ assert type_args[0].__name__ == 'Context'++ for name in ('tools', 'controller'):+ assert_tools_context_hint(browser_use_hints[name])+ assert_tools_context_hint(rust_hints[name])++ assert 'kwargs' not in rust_hints+ assert 'return' not in rust_hints++def test_rust_events_reconstruct_browser_use_history():from browser_use.rust.service import _history_from_events