OpenClaw + Google Workspace CLI: Build an AI Agent for Gmail, Docs, and Classroom
- Xuebin Wei

- 4 days ago
- 5 min read
Stop just chatting with AI—start building an agent that actually works. In this tutorial, we integrate the powerful OpenClaw framework with the new Google Workspace CLI to create a fully autonomous office assistant. We move beyond simple text generation and show you how to give your AI agent the "hands" it needs to manage your professional life across Gmail, Drive, Docs, and Google Classroom.
⚠️ Note: The Google Workspace CLI is an open-source project and not an officially supported Google product.

Watch the full video tutorial here:
Building on Our OpenClaw Foundation
To execute this Google Workspace integration, you will need your cloud environment and agent up and running first. If you haven't set up your base infrastructure yet, we highly recommend starting with our foundational tutorial on deploying your 24/7 Personal AI Assistant to Google Cloud.
Once your agent is live in the cloud, you can give it a platform to manage code by building a Real AI Teammate with GitHub. Finally, to learn how to give your agent specific operating procedures and tools, check out our guide, "Guiding AI Agents for Data Analytics with OpenClaw Skills." With those core concepts mastered, you are ready to connect OpenClaw to Google Workspace!

Understanding the Openclaw-Google Workspace Architecture: The Two-Account Strategy
To make this automation work securely, we split our workflow across two accounts. We use a Developer Account to set up the Google Cloud Project and generate a "Client Secret" (the app's ID badge). However, we use a separate User Account to authorize the actual access to the Workspace data. This ensures your agent only has access to a specific demo account, protecting your primary data from accidental deletions.

Phase 1: Google Cloud Setup & API Configuration
Before we run any commands, we need to lay the cloud foundation using your Developer Account.
Create a Dedicated Project: In the Google Cloud Console, create a new project specifically for your Workspace CLI. Keeping this separate from your OpenClaw VM project is a best practice.
Enable APIs: Navigate to the "APIs & Services" library and enable the specific apps your agent needs. For this tutorial, enable the APIs for Google Drive, Gmail, Calendar, Google Docs, Sheets, Slides, Tasks, and Google Classroom.

Configure the OAuth Consent Screen: Go to the Authentication platform. Choose External for your user type. Fill in the app name and the developer's contact email.
Add Your Test User: In the "Audience" or "Test Users" section, enter the email address for your User Account (your demo account).
Generate the Client Secret: Go to Credentials, click "Create Credentials," and choose OAuth client ID. Select Desktop App as the application type. Once created, download the JSON file. This is your Client Secret.
Phase 2: Local Computer Authorization
Because your remote Virtual Machine (VM) running OpenClaw does not have a web browser, we must first generate the OAuth authorization token on your local computer.

First, create the hidden configuration folder where the CLI expects to find your credentials, and copy the client secret file you downloaded from Google Cloud into it:
# 1. Create the hidden config directory on your local machine
mkdir "%USERPROFILE%\.config\gws"
# 2. Copy your downloaded Google Cloud secret to this new folder
copy "your_downloaded_client_secret.json" "%USERPROFILE%\.config\gws\client_secret.json"
Next, initiate the login process. This command will securely open your web browser, allowing you to log in with your demo User Account and grant the specific permissions your agent needs:
# 3. Request authorization for specific Workspace apps via your browser
gws auth login -s drive,gmail,calendar,docs,sheets,slides,tasks,classroom

Once you have clicked "Allow" in the browser, check your status and export the final authorized token to a new file.
# 4. Verify successful login
gws auth status
# 5. Export the authorized token to a new JSON file
gws auth export --unmasked > credentials.json
Phase 3: Remote VM Configuration
Now, switch to your remote Linux VM where OpenClaw is installed. You need to create a config folder, paste the authorized JSON token you just generated into it locally, and set the file permissions to lock it down securely.
# 1. Create the config directory on the remote VM
mkdir -p ~/.config/gws
# 2. Open a text editor to paste the contents of your exported credentials.json
nano ~/.config/gws/credentials.json

# 3. Tell the CLI exactly where to find your credentials file
export GOOGLE_WORKSPACE_CLI_CREDENTIALS_FILE=~/.config/gws/credentials.json
# 4. Restrict file permissions so only the owner can read the token
chmod 600 ~/.config/gws/credentials.jsonIf you do not have the Google Workspace CLI installed on your VM yet, you can build it securely from the source using Rust/Cargo:
# Install required dependencies and Rust
sudo apt update
sudo apt install -y curl build-essential pkg-config libssl-dev git
curl https://sh.rustup.rs -sSf | sh -s -- -y
source "$HOME/.cargo/env"
# Build and install the Google Workspace CLI
cargo install --git https://github.com/googleworkspace/cli --locked
# Verify the VM is successfully authenticated with Google Workspace
gws auth status

Phase 4: Installing OpenClaw Skills
We have the token and the tools, but we finally need to teach OpenClaw how to use the Google Workspace CLI. We will clone the Google Workspace repository and copy the predefined skills into OpenClaw's active skills folder.
# 1. Navigate to the home directory and clone the CLI repository
cd ~
git clone https://github.com/googleworkspace/cli.git googleworkspace-cli
# 2. Ensure the OpenClaw skills directory exists
mkdir -p ~/.openclaw/skills
# 3. Copy all the Workspace skills into OpenClaw's system
cp -r ~/googleworkspace-cli/skills/gws-* ~/.openclaw/skills/
# 4. Verify the skills are recognized by OpenClaw
openclaw skills list

Conclusion: Testing Your AI Agent
With these commands executed, your OpenClaw agent now has direct, authorized access to manage your digital workspace. Launch OpenClaw (openclaw), open Telegram, and give your agent a command!

You can now ask your agent to summarize unread emails, schedule calendar events, or attach newly generated Docs to Google Classroom assignments.



Comments