Skip to main content
The YouTube Search integration in AG2 allows users to search for YouTube videos and retrieve video details directly within the AG2 framework. This is useful for extracting valuable information from video content, staying updated with the latest tutorials, reviews, and educational materials.

Installation

To get started with the YouTube Search integration in AG2, follow these steps: Install AG2 with the google-search extra, which includes the necessary dependencies for YouTube search. Since our examples also use openai, install it as well:
Note: 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.
You’re all set! Now you can start using YouTube Search with AG2.

Imports

Setup YouTube Data API

Before using the YouTube Search tool, you need to set up a YouTube Data API key:
  1. Go to the Google Cloud Console
  2. Create a new project or select an existing one
  3. Navigate to APIs & Services > Library
  4. Search for YouTube Data API v3 and enable it
  5. Go to APIs & Services > Credentials
  6. Click on Create Credentials > API key and copy your API key
  7. Set the API key as an environment variable:

Agent Configuration

YoutubeSearchTool Initialization

Create a YoutubeSearchTool with your YouTube API key.
Let’s start with a basic search to find YouTube videos on a particular topic.

Output

Advanced Features

The YoutubeSearchTool provides several advanced features:

1. Video Details Retrieval

The tool can retrieve detailed information about videos, including:
  • Video title and description
  • Channel name
  • Publication date
  • View count, like count, and comment count
  • Video duration and quality

2. Customizable Search Parameters

You can customize your search with these parameters:
  • max_results: Control the number of videos returned (default is 5)
  • include_video_details: Whether to include detailed video statistics (default is True)