Skip to main content

Author:

Robert Jambrecic

Machine Learning Engineer at Airt

Introduction

Previously, in our Cross-Framework LLM Tool Integration guide, we combined tools from frameworks like LangChain, CrewAI, and PydanticAI to enhance AG2. Now, we’re taking AG2 even further by integrating Browser Use and Crawl4AI, enabling agents to navigate websites, extract dynamic content, and interact with web pages. This unlocks new possibilities for automated data collection, web automation, and more. Browser Use Example

Browser Use Integration

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.

Crawl4AI Integration

The integration process follows a straightforward approach.

Installation

To integrate Crawl4AI with AG2, follow these steps:
  1. Install AG2 with the crawl4ai 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.
Once installed, you’re ready to start using the 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.
Crawl4AI is built on top of LiteLLM and supports the same models as LiteLLM.We had great experience with OpenAI, Anthropic, Gemini and Ollama. However, as of this writing, DeepSeek is encountering some issues.

Web Browsing with Crawl4AI

Crawl4AITool offers three integration modes:
  1. Basic Web Scraping (No LLM):
  1. Web Scraping with LLM Processing:
  1. LLM Processing with Schema for Structured Data:
We’ll proceed with the most advanced option: LLM Processing with Structured Data Schema. After creating the tool instance, register the agents:

Initiate Chat

Conclusion

With Browser Use and Crawl4AI, AG2 gets a serious upgrade for web browsing and data extraction. Browser Use makes it easy to navigate and interact with web pages, while Crawl4AI helps scrape and structure data, with or without AI processing. Whether you need quick web access, detailed data extraction, or AI-powered insights, these tools make it simple to integrate real-time web content into your projects. Now you’re all set to build smarter, more automated agents that can browse, extract, and use web data with ease. 🚀