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:
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.
export GOOGLE_SERVICE_ACCOUNT_FILE=/path/to/service-account.jsonShare folders/files with the service account email to grant access.
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
id | str | "gdrive" | Tool becomes query_<id>. |
corpora | str | "allDrives" | Search scope: "user", "domain", "drive", or "allDrives". |
drive_id | str | None | Required when corpora="drive" (single Shared Drive). |
model | Model | None | Model for the sub-agent. |
mode | ContextMode | default | See Mode. |
Tools Exposed
| Tool | Description |
|---|---|
query_gdrive | Search 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
| Query | What 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 |