Skip to main content

Google Drive

Use documents and folders from your Google Drive as context for your Squid AI agent.

The Google Drive connector allows you to let users choose files or folders from their Google Drive to upload as context for their Squid AI agent. An AI agent can then respond to client prompts using the selected files as sources of information. For more information on creating custom AI agents, view the AI agent documentation.

Using the Google Drive connector requires a Google Cloud project and some configuration steps for Google Cloud. The required steps are outlined in this documentation along with links to relevant Google documentation.

Enable Google Drive APIs

To get started with this Google Drive connector, first enable the required Google APIs on your Google Cloud project.

  1. In the Google Cloud Console, select a project for your application or create a new project.

  2. Follow the Set up your environment steps in the Google Cloud documentation to enable the Google Drive API and create the necessary credentials. You will need your API key, client ID, and client secret.

  3. In the Google Cloud Console, enable the Google Picker API.

Add the connector

  1. In the Squid Console, navigate to the Connectors tab.

  2. Click Available Connectors.

  3. Find the Google Drive connector, and select Add Connector.

  4. Provide the following configuration details:

Connector ID: A string that uniquely identifies the connector in your code.

Client ID: Your OAuth2 client ID from Google Cloud Console.

Client Secret: Your OAuth2 client secret from Google Cloud Console.

Redirect URI: Your OAuth2 redirect URI (must match what you configured in Google Cloud).

Using the connector

Once you have created your Google Drive connector, you can use it either in the studio or SDK

Note

The personal storage methods of the Squid SDK require access to your Squid API key. The API key enables admin access, so only use personal storage in a secure admin environment like the Squid backend.

No-code Studio

Create no-code solutions in the Squid Agent Studio.

  1. Navigate to the Studio tab in the Squid Console.

  2. Click Create AI Agent.

  3. Provide an Agent ID and description, such as "gdrive-agent" and "This agent helps the user search for content inside Google Drive".

  4. Click Add Abilities, scroll to the Storage section, and select the Google Drive connector you created earlier.

  5. Provide instructions for how the agent should use this connection, such as "Call this when a user asks for about Google Drive content."

  6. Click on Test and try asking the agent "Please search my Google Drive for project proposals and list them."

Basic building blocks in code

To use the Google Drive connector in a Squid application, install the @squidcloud/google-drive-client npm package

npm install @squidcloud/google-drive-client

Client setup

import { GoogleDriveClient, GOOGLE_DRIVE_SCOPES } from '@squidcloud/google-drive-client';
import { Squid } from '@squidcloud/client';

const squid = new Squid({
appId: 'your-app-id',
region: 'us-east-1.aws',
environmentId: 'dev',
});

const driveClient = new GoogleDriveClient(
squid,
'google_drive' // your connector ID
);

Authentication

The Google Drive client uses Squid's External Authentication API for OAuth2 token management. Please refer to the documentation for more details.

After obtaining an authorization code:

const response = await driveClient.saveAuthCode(authCode, userId);

For Google-specific OAuth2 requirements, refer to Google OAuth2 documentation

OAuth2 Scopes

The Google Drive connector requires the following OAuth2 scopes:

const GOOGLE_DRIVE_SCOPES = [
'openid',
'email',
'https://www.googleapis.com/auth/drive.readonly',
'https://www.googleapis.com/auth/drive.metadata.readonly'
];

The constant GOOGLE_DRIVE_SCOPES has been exported from the @squidcloud/google-drive-client package for convenience.

Using the Google Picker API

To allow users to select files to save as context, use the Google Picker API. Follow the steps provided in the Google documentation to load and display the Google Picker, passing the access token generated by your Squid Drive client as the value for accessToken.

const showPicker = () => {
// TODO(developer): Replace with your API key
const picker = new google.picker.PickerBuilder()
.addView(google.picker.ViewId.DOCS)
.setOAuthToken(accessToken) // From Squid
.setDeveloperKey('API_KEY')
.setCallback(pickerCallback)
.setAppId(APP_ID)
.build();
picker.setVisible(true);
};

Refer to the Google Picker documentation for the most up-to-date information on implementation.

Indexing documents and folders

Use the indexDocumentOrFolder method to index documents for AI processing. You can index individual files or entire folders (which will recursively index all files within):

// Index a single document
const errors = await driveClient.indexDocumentOrFolder(
documentId,
userId,
{
category: 'documentation',
description: 'Product documentation',
}
);

// Index an entire folder recursively
const folderErrors = await driveClient.indexDocumentOrFolder(
folderId,
userId,
{
category: 'project-files',
}
);

if (folderErrors.length > 0) {
console.error('Some files failed to index:', folderErrors);
}

Listing indexed documents

// List all indexed documents
const allDocuments = await driveClient.listIndexedDocuments(userId);

// List only files
const files = await driveClient.listIndexedDocuments(userId, 'file');

// List only folders
const folders = await driveClient.listIndexedDocuments(userId, 'folder');

Extracting document content

// Extract text content from a document
const extractedData = await driveClient.extractDataFromDocument(
documentId,
userId
);

console.log('Pages:', extractedData.pages.length);
extractedData.pages.forEach((page, i) => {
console.log(`Page ${i + 1}: ${page.content.substring(0, 200)}...`);
});

Removing documents from index

// Unindex a document or folder
const errors = await driveClient.unindexDocumentOrFolder(
documentId,
userId
);

if (errors.length === 0) {
console.log('Successfully unindexed');
}

Automatic document synchronization

Indexed documents are automatically kept in sync with your Google Drive through a background reindexing process. This ensures your AI agents always have access to the latest content.

The automatic sync process:

  • Detects file changes: Updates indexed documents when they're modified in Google Drive
  • Handles deletions: Automatically removes documents from the index when they're deleted from Drive
  • Processes folder updates: Monitors folders for new files, modifications, and deletions
  • Preserves metadata: Maintains your custom metadata during reindexing

No action is required on your part - documents stay current automatically once indexed.

Using with AI Agents

The Google Drive connector provides AI functions that enable your AI agents to work with indexed documents. The user identifier can be configured on the agent or passed at runtime.

Configuring the agent

// Configure the agent with Google Drive integration and user identifier
const agent = squid.ai().agent('document_agent');
await agent.upsert({
options: {
model: 'gpt-4o-mini',
connectedIntegrations: [
{
integrationId: 'google_drive',
integrationType: 'google_drive',
options: {
identifier: userId, // unique identifier per user
},
},
],
},
});
Note

No-code Studio support for configuring the identifier is coming soon. For now, you'll need to use the SDK to configure an AI Agent with an identifier.

Querying with indexed documents

Once documents are indexed, the AI agent can answer questions using the indexed content:

// The agent will search through indexed documents to answer
const response = await agent.ask(
'In Google Drive, what are the key points in the product documentation?'
);

Using AI functions

The Google Drive connector provides an AI function to list indexed documents:

// List documents using AI function
const response = await agent.ask(
'List all my indexed Google Drive documents',
{
agentContext: { identifier: userId }, // Override default identifier if needed
}
);

Dynamic user context

You can override the default identifier per request:

// Use a different user's documents for this query
const response = await agent.ask('Search for project proposals in my Google Drive', {
agentContext: { identifier: differentUserId },
});

Congratulations! You can now search for content in your Google Drive through your AI agent!