diff --git a/autogen/tools/experimental/browser_use/browser_use.py b/autogen/tools/experimental/browser_use/browser_use.py index da04bee20..ca512242f 100644 --- a/autogen/tools/experimental/browser_use/browser_use.py +++ b/autogen/tools/experimental/browser_use/browser_use.py @@ -46,7 +46,8 @@ class BrowserUseTool(Tool): def __init__( # type: ignore[no-any-unimported] self, *, - llm_config: dict[str, Any], + model: str, + api_key: str, browser: Optional["Browser"] = None, agent_kwargs: Optional[dict[str, Any]] = None, browser_config: Optional[dict[str, Any]] = None, @@ -54,7 +55,8 @@ def __init__( # type: ignore[no-any-unimported] """Use the browser to perform a task. Args: - llm_config: The LLM configuration. + model: The model to use. + api_key: The API key to use. browser: The browser to use. If defined, browser_config must be None agent_kwargs: Additional keyword arguments to pass to the Agent browser_config: The browser configuration to use. If defined, browser must be None @@ -81,12 +83,6 @@ def __init__( # type: ignore[no-any-unimported] if "generate_gif" not in agent_kwargs: agent_kwargs["generate_gif"] = False - try: - model: str = llm_config["config_list"][0]["model"] # type: ignore[index] - api_key: str = llm_config["config_list"][0]["api_key"] # type: ignore[index] - except (KeyError, TypeError): - raise ValueError("llm_config must be a valid config dictionary.") - async def browser_use( # type: ignore[no-any-unimported] task: Annotated[str, "The task to perform."], api_key: Annotated[str, Depends(on(api_key))], diff --git a/notebook/tools_browser_use.ipynb b/notebook/tools_browser_use.ipynb index ee3340c8e..1d11f2d2a 100644 --- a/notebook/tools_browser_use.ipynb +++ b/notebook/tools_browser_use.ipynb @@ -95,7 +95,9 @@ "metadata": {}, "outputs": [], "source": [ - "browser_use_tool = BrowserUseTool(llm_config=llm_config, browser_config={\"headless\": False})\n", + "browser_use_tool = BrowserUseTool(\n", + " model=config_list[0][\"model\"], api_key=config_list[0][\"api_key\"], browser_config={\"headless\": False}\n", + ")\n", "\n", "browser_use_tool.register_for_execution(user_proxy)\n", "browser_use_tool.register_for_llm(assistant)" diff --git a/test/tools/experimental/browser_use/test_browser_use.py b/test/tools/experimental/browser_use/test_browser_use.py index e569e7886..033d4d313 100644 --- a/test/tools/experimental/browser_use/test_browser_use.py +++ b/test/tools/experimental/browser_use/test_browser_use.py @@ -28,7 +28,11 @@ def _use_imports(self) -> None: self._Agent = Agent def test_broser_use_tool_init(self, mock_credentials: Credentials) -> None: - browser_use_tool = BrowserUseTool(llm_config=mock_credentials.llm_config) + config = mock_credentials.config_list[0] + model: str = config["model"] # type: ignore[index] + api_key: str = config["api_key"] # type: ignore[index] + + browser_use_tool = BrowserUseTool(model=model, api_key=api_key) assert browser_use_tool.name == "browser_use" assert browser_use_tool.description == "Use the browser to perform a task." assert isinstance(browser_use_tool.func, Callable) # type: ignore[arg-type] @@ -46,7 +50,10 @@ def test_broser_use_tool_init(self, mock_credentials: Credentials) -> None: @pytest.fixture() def browser_use_tool(self, credentials_gpt_4o_mini: Credentials) -> BrowserUseTool: - return BrowserUseTool(llm_config=credentials_gpt_4o_mini.llm_config) + config = credentials_gpt_4o_mini.config_list[0] + model = config["model"] + api_key = config["api_key"] + return BrowserUseTool(model=model, api_key=api_key) @pytest.mark.openai @pytest.mark.asyncio