Skip to main content
AG2 now integrates Browser Use, allowing your agents to navigate websites, extract dynamic content, and interact with web pages. This makes automated data collection, web automation, and other tasks easier and more efficient. Browser Use Example

Installation

Browser Use requires Python 3.11 or higher.
To get started with the Browser Use integration in AG2, follow these steps:
  1. Install AG2 with the browser-use extra:
    If you have been using autogen or ag2, all you need to do is upgrade it using:
    or
    as autogen and ag2 are aliases for the same PyPI package.
  2. Set up Playwright:
  3. For running the code in Jupyter, use nest_asyncio to allow nested event loops.
You’re all set! Now you can start using browsing features in AG2.

Imports

Agent Configuration

Configure the agents for the interaction.
  • config_list defines the LLM configurations, including the model and API key.
  • UserProxyAgent simulates user inputs without requiring actual human interaction (set to NEVER).
  • AssistantAgent represents the AI agent, configured with the LLM settings.
Browser Use supports the following models: Supported ModelsWe had great experience with OpenAI, Anthropic, and Gemini. However, DeepSeek and Ollama haven’t performed as well.

Web Browsing with Browser Use

The BrowserUseTool allows agents to interact with web pages—navigating, searching, and extracting information. To see the agent’s activity in real-time, set headless to False in the browser_config. If True, the browser runs in the background.

Initiate Chat

Now, let’s run a task where the assistant searches Reddit for “AG2,” clicks the first post, and retrieves the first comment.