Google Drive

GoogleDriveTools let an Agent list, search, read, upload, and download Google Drive files, with smart export of Workspace documents.

GoogleDriveTools give an Agent access to Google Drive. Reading tools (list_files, search_files, read_file) are enabled by default. Writing tools (upload_file, download_file) are off by default and must be opted into. Workspace files (Docs, Sheets, Slides) are auto-exported to text the LLM can consume.

Getting Started

Install dependencies

1uv pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib

Setup Google Cloud project

Enable the Google Drive API, create OAuth credentials, and download the client JSON. First run opens a browser for consent and saves a token for reuse.

Example

1from kern.agent import Agent
2from kern.models.openai import OpenAIResponses
3from kern.tools.google.drive import GoogleDriveTools
4
5# Read-only agent (default: upload and download disabled)
6read_only_agent = Agent(
7 model=OpenAIResponses(id="gpt-5.4"),
8 tools=[GoogleDriveTools()],
9 markdown=True,
10)
11
12# Full-access agent with upload and download enabled
13full_agent = Agent(
14 model=OpenAIResponses(id="gpt-5.4"),
15 tools=[GoogleDriveTools(upload_file=True, download_file=True)],
16 markdown=True,
17)

Authentication

MethodHow
OAuthPass creds_path (client JSON) and token_path, or use the default credentials.json.
Service accountPass service_account_path (or set GOOGLE_SERVICE_ACCOUNT_FILE). Use delegated_user for domain-wide delegation.
Pre-built credsPass a Credentials object directly via creds.

Scopes are auto-inferred from the enabled tools (read-only by default, write scope added when upload_file=True). Override with scopes.

Shared Drives

Set the Drive API passthrough params to search across Shared Drives:

1GoogleDriveTools(
2 corpora="drive", # "user" | "domain" | "drive" | "allDrives"
3 drive_id="0AB...", # required when corpora="drive"
4 supports_all_drives=True,
5 include_items_from_all_drives=True,
6)

Toolkit Params

ParameterTypeDefaultDescription
list_filesboolTrueEnable the list_files tool.
search_filesboolTrueEnable the search_files tool.
read_fileboolTrueEnable the read_file tool.
upload_fileboolFalseEnable the upload_file tool.
download_fileboolFalseEnable the download_file tool.
download_dirPath.Save location for download_file. Writes are sandboxed here.
include_trashedboolFalseInclude trashed files in search/list results.
max_read_sizeint10485760Max file size (bytes) read_file loads for non-Workspace files.
scopesOptional[List[str]]auto-inferredOAuth scopes. Inferred from enabled tools when None.
creds_pathOptional[str]NoneOAuth client credentials JSON path.
token_pathOptional[str]NoneOAuth token file path.
service_account_pathOptional[str]NoneService account JSON path. Alternative to OAuth.
delegated_userOptional[str]NoneUser to impersonate via domain-wide delegation.
corporastr"user"Shared Drive scope: user/domain/drive/allDrives.
drive_idOptional[str]NoneShared Drive ID. Required when corpora="drive".

Toolkit Functions

FunctionDescription
list_filesList files, optionally filtered by a Drive query.
search_filesSearch files by Drive query, returns metadata and links.
read_fileRead a file's content. Workspace files are exported to text/CSV.
upload_fileUpload a local file to Drive.
download_fileDownload a file to download_dir. Workspace files export to native formats.

All functions have sync and async variants.

Developer Resources