页面简介
Learn how to use Browser-Use with Cerebras to enable AI agents to control web browsers for automated navigation, form filling, data extraction, and complex multi-step workflows.
正文摘录
Browser-Use is an open-source project that empowers AI agents to control web browsers, enabling tasks such as automated web navigation, form filling, data extraction, and complex multi-step workflows. By combining Browser-Use with Cerebras’s ultra-fast inference, you can build responsive browser automation agents that execute tasks in real-time. Prerequisites Before you begin, ensure you have: Cerebras API Key - Get a free API key here Python 3.11 or higher - Browser-Use requires Python 3.11+ for optimal performance Playwright - Browser-Use uses Playwright for browser automation Basic understanding of async Python - Browser-Use uses asyncio for concurrent operations Browser-Use works well with fast inference providers like Cerebras. Use gpt-oss-120b for current production browser-control workloads. Configure Browser-Use 1Install required dependenciesFirst, install Browser-Use and its dependencies. Browser-Use will automatically install Playwright and other required packages:pip install browser-use python-dotenv langchain-openai playwright After installation, install the Playwright browsers. This downloads the necessary browser binaries (Chromium, Firefox, WebKit) that Playwright will use for automation:playwright install 2Configure environment variablesCreate a .env file in your project directory to store your API credentials securely. This keeps your API key out of your source code:CEREBRAS_API_KEY=your-cerebras-api-key-here The python-dotenv package (installed in Step 1) will load these variables automatically when you call load_dotenv().3Initialize the Browser-Use agentBrowser-Use integrates seamlessly with any OpenAI-compatible API. Set up a Browser-Use agent with Cerebras to leverage ultra-fast inference for browser automation:PythonJavaScriptimport os import asyncio from dotenv import load_dotenv from langchain_openai import ChatOpenAI from browser_use import Agent # Load environment variables load_dotenv() # Wrapper class for browser-use compatibility with LangChain class CerebrasLLM: def __init__(self, model="gpt-oss-120b"): self.llm = ChatOpenAI( model=model, api_key=os.getenv("CEREBRAS_API_KEY"), base_url="https://api.cerebras.ai/v1", default_headers={"X-Cerebras-3rd-Party-Integration": "browser-use"} ) self.model = model self.model_name = model self.provider = "cerebras" async def ainvoke(self, *args, **kwargs): return await self.llm.ainvoke(*args, **kwargs) # Initialize Cerebras LLM llm = CerebrasLLM() # Create the Browser-Use agent agent = Agent( task="Go to google.com and search for 'Cerebras AI'", llm=llm, ) This creates an agent that will use Cerebras’s gpt-oss-120b model to make decisions about browser actions. The agent can navigate websites, click elements, fill forms, and extract information based on your task description.4Run your first browser automation taskNow let’s run a simple browser automation task. This example navigates to Wikipedia:import os from dotenv import load_dotenv from langchain_openai import ChatOpenAI from browser_use import Agent load_dotenv() # Wrapper class for browser-use compatibility with LangChain class CerebrasLLM: def __init__(self, model="gpt-oss-120b"): self.llm = ChatOpenAI( model=model, api_key=os.getenv("CEREBRAS_API_KEY"), base_url="https://api.cerebras.ai/v1", default_headers={"X-Cerebras-3rd-Party-Integration": "browser-use"} ) self.model = model self.model_name = model self.provider = "cerebras" async def ainvoke(self, *args, **kwargs): return await self.llm.ainvoke(*args, **kwargs) # Initialize Cerebras LLM llm = CerebrasLLM() # Create agent with a task - run with: await agent.run() # agent = Agent(task="Go to wikipedia.org", llm=llm) The agent will open a browser window and navigate to Wikipedia. With Cerebras’s fast inference, navigation decisions happen in milliseconds.You may see some internal “items” errors in the browser-use logs - these are harmless and don’t affect navigation functionality. This is a known issue in browser-use v0.9.5 that will be fixed in future versions.5Extract structured data from websitesYou can navigate to different websites easily. Here’s an example that navigates to the Cerebras website:import os import asyncio from dotenv import load_dotenv from langchain_openai import ChatOpenAI from browser_use import Agent load_dotenv() # Wrapper class for browser-use compatibility with LangChain class CerebrasLLM: def __init__(self, model="gpt-oss-120b"): self.llm = ChatOpenAI( model=model, api_key=os.getenv("CEREBRAS_API_KEY"), base_url="https://api.cerebras.ai/v1", default_headers={"X-Cerebras-3rd-Party-Integration": "browser-use"} ) self.model = model self.model_name = model self.provider = "cerebras" async def ainvoke(self, *args, **kwargs): return await self.llm.ainvoke(*args, **kwargs) async def navigate_cerebras(): llm = CerebrasLLM(model="gpt-oss-120b") agent = Agent( task="Go to cerebras.ai", llm=llm, ) result = await agent.run() print("Navigation completed") if __name__ == "__main__": asyncio.run(navigate_cerebras()) Cerebras’s gpt-oss-120b model is excellent for structured data extraction tasks due to its strong reasoning capabilities and fast inference speed.6Customize browser behaviorYou can navigate to multiple pages in sequence. This example shows navigation to GitHub:import os import asyncio from dotenv import load_dotenv from langchain_openai import ChatOpenAI from browser_use import Agent load_dotenv() # Wrapper class for browser-use compatibility with LangChain class CerebrasLLM: def __init__(self, model="gpt-oss-120b"): self.llm = ChatOpenAI( model=model, api_key=os.getenv("CEREBRAS_API_KEY"), base_url="https://api.cerebras.ai/v1", default_headers={"X-Cerebras-3rd-Party-Integration": "browser-use"} ) self.model = model self.model_name = model self.provider = "cerebras" async def ainvoke(self, *args, **kwargs): return await self.llm.ainvoke(*args, **kwargs) async def navigate_github(): llm = CerebrasLLM() agent = Agent( task="Go to github.com", llm=llm, ) result = await agent.run() print("Navigation completed") if __name__ == "__main__": asyncio.run(navigate_github()) The agent will automatically handle browser initialization. With Cerebras’s ultra-fast inference, the agent can quickly navigate between pages.7Build multi-step workflowsYou can chain multiple navigation tasks together. This example demonstrates navigating to multiple pages in sequence:import os import asyncio from dotenv import load_dotenv from langchain_openai import ChatOpenAI from browser_use import Agent load_dotenv() # Wrapper class for browser-use compatibility with LangChain class CerebrasLLM: def __init__(self, model="gpt-oss-120b"): self.llm = ChatOpenAI( model=model, api_key=os.getenv("CEREBRAS_API_KEY"), base_url="https://api.cerebras.ai/v1", default_headers={"X-Cerebras-3rd-Party-Integration": "browser-use"} ) self.model = model self.model_name = model self.provider = "cerebras" async def ainvoke(self, *args, **kwargs): return await self.llm.ainvoke(*args, **kwargs) async def multi_step_workflow(): llm = CerebrasLLM() # Navigate to multiple pages pages = ["wikipedia.org", "cerebras.ai", "github.com", "python.org"] for page in pages: agent = Agent( task=f"Go to {page}", llm=llm, ) await agent.run() print(f"Navigated to {page}") print("All navigations completed") if __name__ == "__main__": asyncio.run(multi_step_workflow()) Cerebras’s fast inference enables multi-page navigation to complete quickly, making it practical to build efficient browser automation workflows. Why Use Cerebras with Browser-Use? Cerebras’s ultra-fast inference provides several key advantages for browser automation: Real-time responsiveness - Sub-second inference enables agents to react instantly to page changes and dynamic content Complex reasoning - Models like gpt-oss-120b can handle sophisticated multi-step workflows and make intelligent decisions Cost-effective - Fast inference means lower costs for long-running automation tasks and reduced API usage Reliable execution - Low latency reduces timeouts and improves task completion rates, especially for time-sensitive operations Better user experience - Near-instantaneous responses make browser automation feel natural and responsive Available Models Browser-Use works with all Cerebras models for browser automation: ModelParametersBest Forgpt-oss-120b120BProduction text, coding, and tool-use workloadsgemma-4-31b31BPreview multimodal workloads with text and image input Change the model parameter in your CerebrasLLM initialization to switch between models. Next Steps Explore the Browser-Use documentation for advanced features like custom actions and browser contexts Try different Cerebras models to optimize for speed vs. reasoning capability Build multi-agent workflows that combine browser automation with other tools Check out Browser-Use examples for inspiration and real-world use cases Learn about LangChain integration for more advanced agent orchestration Cerebras model catalog Troubleshooting Agent is not finding elements on the pageIf the agent struggles to locate page elements: Be more specific - Provide detailed descriptions of elements in your task (e.g., “the blue submit button in the top right”) Wait for page load - Some dynamic sites need time to render; add explicit wait instructions in your task Simplify selectors - Use clear, unique identifiers when possible (e.g., “the search box with placeholder ‘Enter query’”) Check for dynamic content - Some elements may load via JavaScript; ensure the page is fully loaded before interaction ImportError: cannot import name 'Agent' from 'browser_use'This usually means Browser-Use wasn’t installed correctly:pip uninstall browser-use pip install browser-use --upgrade playwright install Make sure you’re using Python 3.11 or higher. You can check your Python version with:python --version If you’re using an older version, consider using pyenv or conda to install Python 3.11+. How do I handle authentication and cookies?Browser-Use can handle authenticated sessions. The agen