Open In Colab Open on GitHub

DeepResearchAgent helps break down complex tasks into smaller steps, using web scraping and other techniques to find the information you need. Instead of handling everything at once, it tackles each part step by step, making research easier and more efficient. Whether you’re looking for specific details, gathering data, or just trying to solve a tricky problem, this agent does the heavy lifting for you.

Installation

Note: DeepResearchAgent is built on top of Browser Use, which requires Python 3.11 or higher.

To get started with the DeepResearchAgent agent, follow these steps:

  1. Install AG2 with the browser-use extra:

    pip install -U ag2[openai,browser-use]
    

    Note: If you have been using autogen or pyautogen, all you need to do is upgrade it using:

    pip install -U autogen[openai,browser-use]
    

    or

    pip install -U pyautogen[openai,browser-use]
    

    as pyautogen, autogen, and ag2 are aliases for the same PyPI package.

  2. Set up Playwright:

    # Installs Playwright and browsers for all OS
    playwright install
    # Additional command, mandatory for Linux only
    playwright install-deps
    
  3. For running the code in Jupyter, use nest_asyncio to allow nested event loops. bash pip install nest_asyncio

You’re all set! Now you can start solving complex tasks.

Imports

import os

import nest_asyncio

from autogen.agents.experimental import DeepResearchAgent

nest_asyncio.apply()

Starting the Conversation

This code initializes DeepResearchAgent and asks it to find out What was the impact of DeepSeek on stock prices and why? using GPT-4o.

Note: Models like gpt-4o-mini often don’t perform well enough for complex tasks.

llm_config = {
    "config_list": [{"model": "gpt-4o", "api_key": os.environ["OPENAI_API_KEY"]}],
}

agent = DeepResearchAgent(
    name="DeepResearchAgent",
    llm_config=llm_config,
)

message = "What was the impact of DeepSeek on stock prices and why?"

result = agent.run(
    message=message,
    tools=agent.tools,
    max_turns=2,
    user_input=False,
    summary_method="reflection_with_llm",
)

result.summary