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
Allow other llms
Magnus Müller345aea6d10f9
diff --git a/browser_use/code_use/service.py b/browser_use/code_use/service.pyindex b93fbe153..f1d5cc365 100644--- a/browser_use/code_use/service.py+++ b/browser_use/code_use/service.py@@ -59,6 +59,7 @@ class CodeAgent:self,task: str,# Optional parameters+ llm: BaseChatModel | None = None,browser_session: BrowserSession | None = None,browser: BrowserSession | None = None, # Alias for browser_sessiontools: Tools | None = None,@@ -82,8 +83,8 @@ class CodeAgent:task: The task description for the agentbrowser_session: Optional browser session (will be created if not provided) [DEPRECATED: use browser]browser: Optional browser session (cleaner API)- tools: Optional Tools instance (will create default if not provided) [DEPRECATED: use controller]- controller: Optional Tools instance (cleaner API)+ tools: Optional Tools instance (will create default if not provided)+ controller: Optional Tools instancepage_extraction_llm: Optional LLM for page extractionfile_system: Optional file system for file operationsavailable_file_paths: Optional list of available file paths@@ -93,20 +94,24 @@ class CodeAgent:max_validations: Maximum number of times to run the validator agent (default: 0)use_vision: Whether to include screenshots in LLM messages (default: True)calculate_cost: Whether to calculate token costs (default: False)+ llm: Optional ChatBrowserUse LLM instance (will create default if not provided)**kwargs: Additional keyword arguments for compatibility (ignored)"""# Log and ignore unknown kwargs for compatibilityif kwargs:logger.debug(f'Ignoring additional kwargs for CodeAgent compatibility: {list(kwargs.keys())}')- # Create ChatBrowserUse LLM (used internally by CodeAgent)- try:- from browser_use import ChatBrowserUse+ if llm is None:+ try:+ from browser_use import ChatBrowserUse- llm = ChatBrowserUse()- logger.debug('CodeAgent using ChatBrowserUse')- except Exception as e:- raise RuntimeError(f'Failed to initialize CodeAgent LLM: {e}')+ llm = ChatBrowserUse()+ logger.debug('CodeAgent using ChatBrowserUse')+ except Exception as e:+ raise RuntimeError(f'Failed to initialize CodeAgent LLM: {e}')++ if "ChatBrowserUse" not in llm.__class__.__name__:+ raise ValueError('This agent works only with ChatBrowserUse.')# Handle browser vs browser_session parameter (browser takes precedence)if browser and browser_session: