You probably didn’t set out to become a full‑time email sorter.
If you run a small business or solo practice, your Gmail and Drive slowly turn into a second job: inbox zero becomes a myth, invoices get buried under newsletters, and shared folders multiply for every client.
In 2026, you don’t need another "smart inbox" tab. You need an AI agent that actually logs into your Google Workspace, applies rules you understand, and runs every day on your own server.
In this guide, you’ll build exactly that: an OpenClaw agent that uses the new Google Workspace CLI to process Gmail and keep Drive tidy. You’ll see where each piece lives in the OpenClaw workspace, how to keep it safe, and how to deploy it without giving a third‑party SaaS the keys to your data.
What you’re building: a Google Workspace housekeeping agent
Before we touch configs, define the job.
Your agent will:
- Read from one or more Gmail inboxes using Google Workspace CLI commands
- Label and archive routine messages (newsletters, promos, notifications)
- Flag and group high‑value emails (clients, invoices, support requests)
- Move or copy attachments into structured Drive folders
- Run on a schedule via OpenClaw’s HEARTBEAT system
- Ping you on Telegram/Slack when something looks important or broken
Equally important: what it will not do by default.
- It will not send replies on your behalf without an explicit rule
- It will not have shell access beyond the Google Workspace CLI tool
- It will not read private folders you don’t point it at explicitly
Those constraints live in your workspace files: SOUL.md, AGENTS.md, TOOLS.md, and HEARTBEAT.md.
You own them, you can git‑diff them, and you can roll them back if you don’t like how the agent behaves.
Prerequisites: what you need before running the wizard
To follow along, you’ll need:
- A running OpenClaw server (test or production)
- A Google Workspace account with API access enabled
- Google Workspace CLI installed on the same machine as OpenClaw
- A basic understanding of how OpenClaw agents use tools and heartbeats
If you’re not there yet, start with a generic OpenClaw install, then come back. This tutorial assumes OpenClaw is healthy and you can already chat with a simple agent from Telegram or another channel.
Step 1: Design your Gmail + Drive workflow like a human
The biggest mistake people make with AI agents is skipping the boring part: writing down the workflow.
Before you open OpenAgents.mom, answer these questions on paper (or in a note):
- What counts as important email?
- Client domains, senders, or subject keywords.
- What can be auto‑archived?
- Newsletters, comment notifications, receipts.
- Where should attachments go?
- Shared Drive folders by client or project.
- How fast do you need alerts?
- Immediate for money‑related emails, daily digest for the rest.
Turn that into something your agent can act on. For example:
- "Any email from
@mybestclient.comgets labelClient / Best Clientand a Telegram ping." - "Newsletters from
@substack.comget labelReading / Newslettersand are auto‑archived." - "PDF invoices go into
Drive:/Finance/Invoices/2026/and are grouped by month."
You’ll feed this directly into the wizard so it can write a precise SOUL.md and AGENTS.md instead of vague "be helpful" instructions.
Step 2: Use OpenAgents.mom to generate the workspace bundle
OpenAgents.mom is a guided interview that spits out a complete OpenClaw workspace. For this agent, you’ll lean on questions about tools, data access, and recurring tasks.
When the wizard asks about the agent’s purpose, answer in plain language, for example:
"This agent keeps my Google Workspace healthy. It triages Gmail, labels and archives low‑value mail, flags important messages, and organizes Drive attachments into the right folders. It never sends emails on its own."
When it asks about channels, pick where you want alerts and control:
- Telegram for quick pings
- Slack if your team lives there
- Email digests if you prefer summaries
In the capabilities/tools section, describe the Google Workspace CLI explicitly:
"The agent can run the
gogor Workspace CLI commands to list Gmail threads, apply labels, move messages, and move files in Drive. It should treat these as powerful tools and ask for confirmation before bulk changes."
Behind the scenes, the wizard uses your answers to fill in:
SOUL.mdwith the agent’s values and boundariesAGENTS.mdwith operating rules and session behaviorTOOLS.mdwith Google Workspace CLI access notesHEARTBEAT.mdwith starting schedules for inbox sweeps and Drive clean‑ups
When you’re done, download the ZIP bundle and unpack it into your OpenClaw agents directory. You now have a file‑based definition of your Gmail + Drive agent.
Step 3: Wire up Google Workspace CLI safely
Next, you need the agent to talk to Google Workspace.
In TOOLS.md, you’ll define how the agent is allowed to call the Workspace CLI.
A simplified example:
# TOOLS.md (excerpt)
## google-workspace-cli
kind: exec
command_prefix: "gog"
allowed_subcommands:
- "gmail threads list"
- "gmail threads read"
- "gmail labels apply"
- "drive files list"
- "drive files move"
timeout_seconds: 20
max_results_per_call: 100
safety_notes:
- "Never delete emails or files. Archiving only."
- "Ask the user before applying label changes to more than 50 messages."
The exact syntax will depend on your OpenClaw config, but the pattern is the same:
- Give the agent a narrow set of commands
- Prefer list/read and label/move operations over mutation or deletion
- Document safety rules in plain language inside the file
Security reminder: keep API credentials and tokens outside the workspace as environment variables or OpenClaw secrets. Your agent config should reference those variables, not hard‑code secrets.
Step 4: Teach the agent your email rules in SOUL.md and AGENTS.md
Tools without rules are how you end up with a rogue inbox cleaner.
Open your generated SOUL.md and look for the sections where the wizard described:
- Who the agent serves (you, your team)
- What "success" looks like for each run
- Hard boundaries (what it must never do)
Add concrete examples from your design step:
## Success Definition
- Inbox has fewer than 20 unlabelled messages at the end of each day.
- All newsletters are labelled `Reading / Newsletters` and archived.
- Client messages from @mybestclient.com are labelled `Client / Best Client` and pinned for review.
## Hard Boundaries
- Never send emails or drafts without explicit human approval.
- Never delete messages or files.
- Never move files outside the `/Clients` and `/Finance` folders configured in TOOLS.md.
Then open AGENTS.md and tighten the operating manual.
For example, you might add:
## Daily Run Workflow
1. List new Gmail threads since last run.
2. Apply newsletter rules first and archive those threads.
3. Apply client rules and raise notifications for priority senders.
4. Extract attachments from invoices and move them into the Finance folder.
5. Summarize actions taken and send a digest to the human via Telegram.
By keeping this logic in Markdown, you can review it in a pull request the same way you review code.
If you don’t like a behavior, you change text in SOUL.md or AGENTS.md, not a black‑box flowchart.
Step 5: Schedule inbox sweeps with HEARTBEAT.md
Now you want this agent to run on its own.
That’s what HEARTBEAT.md is for.
A simple heartbeat schedule for Gmail and Drive might look like this:
# HEARTBEAT.md (excerpt)
## Tasks
- id: gmail-morning-sweep
schedule: "0 7 * * 1-5" # Weekdays at 07:00
description: "Process overnight email and label/archive according to rules."
max_runtime_seconds: 120
- id: gmail-afternoon-sweep
schedule: "0 15 * * 1-5" # Weekdays at 15:00
description: "Catch late‑day client emails and send summary."
max_runtime_seconds: 90
- id: drive-weekly-cleanup
schedule: "0 9 * * 1" # Mondays at 09:00
description: "Move stray attachments into correct Drive folders."
max_runtime_seconds: 300
OpenClaw’s scheduler reads this file and triggers your agent on the specified cron patterns. If a task runs too long or fails, logs stay on your server for inspection.
Security reminder: start with conservative schedules. It’s better to run twice a day and gradually increase frequency than to bombard the API or spam your own notifications.
Step 6: Test the workflow in a sandboxed Google Workspace
Before you let the agent loose on your real inbox, run it against a test account or a narrow label.
A safe way to stage this:
- Create a test Gmail account or a dedicated label like
agent-test. - Update
TOOLS.mdso list/read calls filter to that label only. - Forward a sample of real emails to the test inbox.
- Run the agent manually from your OpenClaw interface or via a one‑off heartbeat.
Watch what it does:
- Are newsletters being labelled and archived correctly?
- Are client‑like emails being flagged as expected?
- Are attachments landing in the right Drive folders?
Only once you’re happy with the behavior should you expand its scope to your primary inbox.
Step 7: Add human‑in‑the‑loop checks for sensitive actions
Even with good rules, there are cases where you want the agent to ask first.
Examples:
- Moving a whole folder tree in Drive
- Mass relabeling hundreds of messages
- Touching invoices or contracts
You can model this in AGENTS.md and in your OpenClaw approvals:
## Human Approval Required
- Any operation affecting more than 50 Gmail threads.
- Any Drive move that changes the top‑level folder.
- Any modification to files in the Finance or Legal folders.
When in doubt, the agent must:
- Prepare a summary of the proposed change.
- Ask the human for confirmation in Telegram or Slack.
- Only execute after an explicit "YES" response.
Pair this with OpenClaw’s human‑approval patterns so you can click "Approve" or "Reject" from your chat client.
Step 8: Deploy to production and monitor like a DevOps engineer
Once you’re confident in staging, it’s time to point the agent at your real Google Workspace.
Checklist before you flip the switch:
- [ ] Credentials stored securely (no secrets in Markdown files)
- [ ]
TOOLS.mdlimits commands to label/move, no delete - [ ]
SOUL.mdandAGENTS.mdspell out hard boundaries - [ ]
HEARTBEAT.mduses sane schedules - [ ] Logging is enabled so you can audit what happened
After deployment, treat this like any other production service:
- Set up a daily digest message summarizing how many emails were touched and where files went
- Keep logs for at least 30 days for auditability
- Add basic alerts if a heartbeat fails repeatedly
Because everything lives in plain files, you can:
- Put the workspace under version control
- Review config diffs in pull requests
- Roll back to a known good state in seconds
Common Mistakes when building a Google Workspace agent
Use this list as a quick self‑audit before and after deployment.
-
Giving the agent delete permissions too early.
- Start with labels and archives.
- Only add deletion after weeks of clean runs, and even then, keep strict rules.
-
Hard‑coding secrets in workspace files.
- Tokens and client secrets belong in environment variables or secret stores.
- Your workspace should reference them symbolically (e.g.
$GWORKSPACE_TOKEN).
-
Letting the agent touch every folder in Drive.
- Scope it to a few top‑level folders like
/Clientsand/Finance. - Expand only when you’re sure the rules are correct.
- Scope it to a few top‑level folders like
-
No staging environment.
- Always test with a dummy inbox or restricted label first.
- Treat config changes like code changes.
-
Over‑eager scheduling.
- Running every minute will annoy Google’s API and inflate your token costs.
- Most humans don’t need sub‑hourly inbox automation.
Security Guardrails for OpenClaw + Google Workspace
Security is not optional when you connect an AI agent to your email and files. Walk through these guardrails before you trust it.
-
Principle of least privilege.
- Use a Google Workspace service account or delegated account with only the scopes you need.
- Keep Drive access limited to specific folders, not the entire domain.
-
Workspace‑level sandboxing.
- In OpenClaw, give this agent a narrow
exectool profile. - No generic shell, no internet scraping tools unless you have a clear reason.
- In OpenClaw, give this agent a narrow
-
Audit trails by default.
- Log every Gmail and Drive action with timestamp, command, and result.
- Store logs somewhere you can grep without exposing sensitive content to third parties.
-
Human override channel.
- Make it easy to pause the agent from Telegram/Slack if you see weird behavior.
- Document the pause procedure in
AGENTS.mdso you remember it under stress.
-
Regular config reviews.
- Schedule a quarterly review of
SOUL.md,AGENTS.md,TOOLS.md, andHEARTBEAT.md. - As your business changes, so should your agent’s rules.
- Schedule a quarterly review of
Where OpenAgents.mom fits into this picture
You could hand‑craft all these files yourself. But in practice, most people stall out trying to remember every OpenClaw field or copy‑pasting from old agents.
OpenAgents.mom shortcuts that work:
- You answer plain‑language questions about your Gmail and Drive workflow
- The wizard generates a complete, security‑first workspace bundle
- You download a ZIP and drop it onto your OpenClaw server
- You customize the files the same way you’d tweak code
You still own everything: plain Markdown, under your version control, running on your infrastructure. No hosted black box, no surprise price hikes, no mystery logic.
Turn Your Messy Inbox Into a Reliable Agent
If your Gmail and Drive feel like a second job, you need an agent that lives on your server, follows your rules, and respects your security boundaries. Walk through the guided interview and get a production-ready workspace bundle in one evening.