Skip to main content
AG2 now integrates Crawl4AI, an open-source web crawler built for AI agents, language models, and data pipelines. This allows your agents to quickly access and process web data in real time, making automation and data collection more efficient.

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