Skip to main content

Author:

Robert Jambrecic

Machine Learning Engineer at Airt

Introduction

In our Adding Browsing Capabilities to AG2 guide, we explored how to build agents with basic web surfing capabilities. Now, let’s take it to the next level with WebSurferAgent—a powerful agent that comes with built-in web browsing tools right out of the box! With WebSurferAgent, your agents can seamlessly browse the web, retrieve real-time information, and interact with web pages—all with minimal setup. WebSurferAgent Example

WebSurferAgent with BrowserUseTool

Browser Use requires Python 3.11 or higher.

Installation

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

Configure WebSurferAgent with Browser Use

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.
WebSurferAgent is the one responsible for browsing the web and retrieving information. The web_tool="browser_use" tells the agent to use the BrowserUseTool to surf the web. After creating the WebSurferAgent there are two ways to start the chat session: The new run method simplifies the process by eliminating the need for manual UserProxyAgent creation.
  • Easier setup – No need to manually register tools

Manual Setup: Using initiate_chat Method

This method requires manually creating a UserProxyAgent and registering tools for execution.
  • ⚠️ More setup required
  • ⚠️ Must manually register tools

Output

WebSurferAgent with Crawl4AITool

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

Configure WebSurferAgent with Crawl4AI

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.
The only difference from the previous example is that the web_tool parameter must be set to crawl4ai in order for the Crawl4AITool to be used. As in previous example, there are two ways to start the chat session: The new run method simplifies the process by eliminating the need for manual UserProxyAgent creation.
  • Easier setup – No need to manually register tools

Manual Setup: Using initiate_chat Method

This method requires manually creating a UserProxyAgent and registering tools for execution.
  • ⚠️ More setup required
  • ⚠️ Must manually register tools

Output

Conclusion

In this post, we’ve shown how to boost your agents with web browsing abilities using the WebSurferAgent. By using tools like BrowserUseTool and Crawl4AITool, your agents can easily fetch real-time information from the web. This makes your agents more useful and flexible, whether you’re getting data from specific pages or gathering info across different topics. With these tools, AG2 helps you create smarter agents that can navigate the web and bring back the details you need with minimal effort.