top of page

LBSocial

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

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.


Telegram sends tasks to Gemini AI on Google Cloud via OpenClaw, which accesses Google Workspace services. Cute crab AI illustration.
The OpenClaw workflow: Sending tasks via Telegram to your AI agent, which directly accesses Google Workspace using the installed CLI skills.

Watch the full video tutorial here:

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


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!


Split screen showing a Google Classroom page with a Python intro and a chat in a messaging app discussing an announcement about a GitHub document.
In this tutorial, we build an agent that manages Google Docs and Google Classroom directly via Telegram commands.

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.


Flowchart comparing Google Cloud project setup and user authorization, featuring a cartoon crab, icons for APIs, and green authorization steps.
Conceptual Chart: Google Cloud Project Setup vs. User Authorization.

Phase 1: Google Cloud Setup & API Configuration


Before we run any commands, we need to lay the cloud foundation using your Developer Account.


  1. 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.

  2. 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.


Google Cloud console showing Google Classroom API details as enabled. Notifications list several enabled services like Sheets and Docs.
Manually enabling the required Google Workspace APIs in your new Google Cloud Project.

  1. 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.

  2. Add Your Test User: In the "Audience" or "Test Users" section, enter the email address for your User Account (your demo account).

  3. 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.


Local computer authorizes apps via OAuth, creating a .json token sent to a virtual machine. Blue and white design with arrows indicating flow.
Passing the generated OAuth token from your Local Computer to the Virtual Machine.

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

Popup showing "OpenClaw Workspace Agent" requesting Google Account access, with options for Drive, Slides, Docs, and more on the right.
Authorizing the specific scopes via the browser on your local machine.

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

SSH browser interface shows GNU nano editing credentials.json. Gray background with JSON fields. Toolbar at the bottom includes commands.
 Securely pasting the authorized credentials into the remote VM using the nano editor.

# 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.json

If 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

Text lines in a terminal window showing URLs related to Google Classroom API permissions, with SSH-in-browser header and toolbar.
Verifying that the remote VM has successfully authenticated using the uploaded credentials.

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

Console display with text in columns, showing "ready" status and Google Workspace features like admin reports and calendar. Dark background.
Confirming OpenClaw has successfully recognized and loaded the Google Workspace skills.

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!


Google Classroom and messaging app split screen. Left: Python Programming Spring 2026 class stream with announcements. Right: Chat about class setup.
Testing the integration by commanding the agent to draft a new Google Doc from Telegram.

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


Comments


bottom of page