Google Drive

Search and read files from Google Drive.

Search and read files from Google Drive, including Docs, Sheets, and uploaded files. The provider exposes one tool: query_gdrive.

Create a virtual environment, then install the Google Workspace clients and the model SDK:

uv pip install -U agno openai google-api-python-client google-auth-httplib2 google-auth-oauthlib
export OPENAI_API_KEY="your-openai-api-key"

For the personal OAuth example, enable the relevant Google API in your Cloud project, configure its consent screen, and create a Desktop OAuth client. Set GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET and GOOGLE_PROJECT_ID using that client. Authorize access in the browser on first use. The authentication section below also covers service accounts.

For a headless service, provision credentials first and set GOOGLE_OAUTH_NONINTERACTIVE=1. Gmail and Calendar also accept auth=AuthConfig(interactive=False) from agno.tools.google.auth; the current Drive provider does not accept auth=. If credentials cannot be loaded or refreshed, authentication reports an error instead of opening a browser. Provider configuration selects the credentials; forwarding a run’s user ID does not switch Google accounts.

Save as drive_context.py and run python drive_context.py after configuring authentication:

drive_context.py
import asyncio

from agno.agent import Agent
from agno.context.gdrive import GoogleDriveContextProvider
from agno.models.openai import OpenAIResponses

async def main():
    drive = GoogleDriveContextProvider(model=OpenAIResponses(id="gpt-5.4-mini"))
    agent = Agent(
        model=OpenAIResponses(id="gpt-5.4"),
        tools=drive.get_tools(),
        instructions=drive.instructions(),
    )
    await agent.aprint_response("Find the Q4 planning doc and summarize the key milestones")

if __name__ == "__main__":
    asyncio.run(main())

GoogleDriveContextProvider is read-only. There is no update_gdrive tool.

Authentication

OAuth or service account. For service accounts, share folders with the service account email.

export GOOGLE_CLIENT_ID=...
export GOOGLE_CLIENT_SECRET=...
export GOOGLE_PROJECT_ID=...

Token cached to gdrive_token.json.

Configuration

ParameterTypeDefaultDescription
idstr"gdrive"Tool becomes query_<id>.
corporastr"allDrives"Search scope: "user", "domain", "drive", or "allDrives".
drive_idstrNoneRequired when corpora="drive" (single Shared Drive).
modelModelNoneModel for the sub-agent.
modeContextModedefaultSee Mode.

Tools Exposed

ToolDescription
query_gdriveSearch files, list folders, read file contents (including Google Docs/Sheets).

Shared Drive Support

By default, corpora="allDrives" searches across drives available to the configured credentials. These constructor fragments narrow the scope; replace the shared-drive ID with one your credentials can access:

# Personal Drive only
drive = GoogleDriveContextProvider(corpora="user")

# Single Shared Drive
drive = GoogleDriveContextProvider(corpora="drive", drive_id="0ABcd...")

# All files shared to domain
drive = GoogleDriveContextProvider(corpora="domain")

Example queries

QueryWhat happens
"Find the product roadmap document"Searches by title
"What spreadsheets were modified this week?"Searches with time filter
"Read the meeting notes from the design review"Gets file content

Resources