Google Drive Tools
Google Drive Tools
The Google Drive integration in AG2 empowers users to seamlessly access and manage their files within the AG2 framework. With this integration, users can easily list, download, and interact with files stored in their Google Drive, providing a smooth and efficient way to handle documents, images, and other data in real time.
Installation
Before using Google APIs, you need to enable them in your Google Cloud project. You can enable multiple APIs within a single project.
-
Follow the Setup environment guide from Google Workspace to get started.
-
Once you’ve completed the setup, you should have the
credentials.json
file downloaded to your local machine. -
Install AG2 with the
google-api
extra. Since our examples also useopenai
, install it as well:Note: If you have been using
autogen
orpyautogen
, all you need to do is upgrade it using:or
as
pyautogen
,autogen
, andag2
are aliases for the same PyPI package.
You’re all set! Now you can start using Google Drive with AG2.
Imports
Google Authentication
Configure authentication to allow AG2 to access Google Drive: -
client_secret_file
: The path to the client secret file, which you can
download from the Google Cloud Console. This file contains the necessary
credentials to authenticate the user with Google services. -
token_file
: The path to a file that will store the access token. After
the first run of the script, this token will be saved and used for
subsequent authentications, avoiding the need for repeated login
processes. - provider
(GoogleCredentialsLocalProvider
): The provider
is responsible for managing the authentication process. - credentials
:
This variable stores the credentials object, which will be used by the
system to authenticate the user and gain access to their Google Drive
resources.
Note: The first execution opens a Google Authentication page in your browser.
Agent Configuration
Register Google Drive Tools
The GoogleDriveToolkit
class provides a set of predefined tools for
seamless interaction with Google Drive. These tools include: -
list_drive_files_and_folders
: Allows the user to list all files and
folders in their Google Drive. - download_file_from_drive
: Enables
downloading files directly from Google Drive to a specified local
folder.
Once the tool map is registered with the agent using register_for_llm
,
the agent becomes capable of suggesting these tool calls.
Start the Conversation
With the setup complete, you can now use the assistant to list and download files from your Google Drive.
Custom GoogleDriveToolkit
You can easily customize the predefined GoogleDriveToolkit
based on
your specific requirements. By subclassing GoogleDriveToolkit
, you can
modify the toolset available to your agent.
For example: - Add custom tools: You can introduce new tools, like
list_docs
, to specifically retrieve document files from a folder. -
Remove existing tools: You can eliminate unnecessary tools, such as
list_drive_files_and_folders
, to streamline functionality and focus on
relevant features.