Deep Research - AG2

Deep Research

AG2 recommends two approaches for autonomous deep research: the built-in DeepResearchTool and the GPT Researcher multi-agent integration.

DeepResearchTool is a composable AG2 tool that any agent can call directly. It is the right choice when you want research capabilities tightly integrated into your AG2-based agent, without a separate orchestration layer.

GPT Researcher is a standalone research agent with a built-in orchestration pipeline optimized for recursive querying and structured report generation. It is a good choice when you want a pre-built, highly configurable research agent that can operate independently or alongside other AG2 agents.

DeepResearchTool

Inspired by OpenAI's Deep Research, DeepResearchTool is designed to tackle complex, multi-step research tasks, synthesizing insights from diverse online sources.

Installation

DeepResearchTool is built on top of Browser Use, which requires Python 3.11 or higher.

To get started with the DeepResearchTool, follow these steps:

  1. Install AG2 with the browser-use extra:

    pip install ag2[openai,browser-use]
    

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

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

    or

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

    as 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.

    pip install nest_asyncio
    

You're all set! Now you can start using browsing features in AG2.

Imports

import os
import nest_asyncio

from autogen import AssistantAgent, UserProxyAgent, LLMConfig
from autogen.tools.experimental import DeepResearchTool

nest_asyncio.apply()

Agent Configuration

Configure the agents for the interaction.

llm_config = LLMConfig(config_list={
    "api_type": "openai",
    "model": "gpt-5",
    "api_key": os.environ["OPENAI_API_KEY"],
})

user_proxy = UserProxyAgent(name="user_proxy", human_input_mode="NEVER")

assistant = AssistantAgent(name="assistant", llm_config=llm_config)

DeepResearchTool Configuration

Once the DeepResearchTool is created, it needs to be registered to the agents.

deep_research_tool = DeepResearchTool(llm_config=llm_config)
deep_research_tool.register_for_execution(user_proxy)
deep_research_tool.register_for_llm(assistant)

Initiate Chat

result = user_proxy.initiate_chat(
    recipient=assistant,
    message="What was the impact of DeepSeek on stock prices and why?",
    max_turns=2,
)

Response from Assistant

DeepSeek search technology significantly impacted stock prices, particularly in the technology sector, by introducing increased market volatility and substantial fluctuations. Here's a detailed breakdown:

Overview

How DeepSeek Functions

Changes in Stock Prices

Mechanisms Influencing Stock Prices

  1. Market Erosion: DeepSeek’s operational cost advantages and open-source nature disrupted major AI competitors, eroding their market share and prompting a reevaluation of tech stock valuations.
  2. Valuation Reassessments: Concerns over tech stock valuations heightened market anxiety, driven by competitive threats from DeepSeek.

Conclusion

Overall, DeepSeek challenged tech giants globally, leading to valuation adjustments and increased stock market volatility. This necessitated a broader reassessment of the technological landscape by investors, culminating in significant financial impacts.

GPT Researcher

GPT Researcher is an autonomous research agent that orchestrates a team of specialized agents to produce comprehensive research reports. The AG2 integration uses AG2 as the orchestration layer for the research pipeline.

Research Team

The pipeline coordinates eight specialized agents:

Installation

Clone the GPT Researcher repository and install the dependencies:

git clone https://github.com/assafelovic/gpt-researcher.git
cd gpt-researcher
pip install -r requirements.txt
pip install -r multi_agents_ag2/requirements.txt

Environment Setup

export OPENAI_API_KEY={your_openai_key}
export TAVILY_API_KEY={your_tavily_key}

A Tavily API key is required for web search. See Tavily Search Tool for setup details and standalone usage with AG2 agents.

Configure the Research Task

Customize the research task by editing multi_agents_ag2/task.json:

{
  "query": "Is AI in a hype cycle?",
  "max_sections": 3,
  "max_revisions": 3,
  "publish_formats": {
    "markdown": true,
    "pdf": true,
    "docx": true
  },
  "include_human_feedback": false,
  "follow_guidelines": false,
  "model": "gpt-4o",
  "guidelines": [\
    "The report MUST be written in APA format",\
    "Each sub section MUST include supporting sources using hyperlinks."\
  ],
  "verbose": true
}
Parameter Description
query The research question
max_sections Maximum number of report sections
max_revisions Maximum revision cycles per section
publish_formats Output formats: markdown, pdf, docx
include_human_feedback Whether to prompt for human input during research
model LLM model to use
follow_guidelines Whether to enforce the guidelines list

Run the Research

python -m multi_agents_ag2.main

The pipeline runs through five stages: planning, data gathering and analysis, quality review and revision, writing, and publishing.

Resources