← Back to Blog

Your First Inbox Agent: Use OpenClaw to Triage Email and Organize Your Google Drive

Your First Inbox Agent: Use OpenClaw to Triage Email and Organize Your Google Drive

You open your laptop at 9 AM and there are 84 unread emails. Twenty of them are client messages. Twelve are invoices. The rest are noise. You spend 45 minutes sorting before you do a single thing that moves the needle.

That's not a productivity problem — it's an automation gap. The tools exist to close it, and you don't need a no-code platform subscription or a dedicated ops hire to do it. A properly configured AI Gmail agent in OpenClaw can read your inbox, flag what matters, file attachments into the right Google Drive folders, and drop you a morning summary before your first coffee is cold.

This post walks you through building exactly that — from blank config to a working daily-driver agent.


What the Agent Actually Does

Before touching a config file, it helps to be concrete about scope. This agent does four things:

  1. Reads your Gmail inbox via the Google Workspace API on a schedule
  2. Flags messages that match rules you define (sender domain, subject keywords, thread age)
  3. Files attachments into labeled Google Drive folders automatically
  4. Produces a daily digest — a short structured summary sent to a Slack channel or written to a Drive doc

It does not reply to emails on your behalf (you can add that later, once you trust the triage logic). Start narrow. Expand when the baseline is solid.


Prerequisites

You need:

  • An OpenClaw workspace (self-hosted or cloud tier — either works)
  • A Google Cloud project with the Gmail API and Drive API enabled
  • A service account JSON key, or an OAuth2 credential scoped to your personal account
  • Your AGENTS.md workspace file already initialized

If your workspace isn't initialized yet, the agents-md-openclaw-workspace-setup guide covers the baseline setup. Do that first.


Enabling the Google Workspace Tools

OpenClaw uses a tools: block in your agent config to declare which integrations are active. For a Gmail + Drive agent, your agent.yaml starts like this:

agent_id: inbox-triage
model: claude-opus-4
schedule: "0 7 * * 1-5"  # 7 AM, Monday–Friday

tools:
  - name: gmail_read
    scopes:
      - https://www.googleapis.com/auth/gmail.readonly
    credential: env:GOOGLE_SERVICE_ACCOUNT_JSON

  - name: gmail_label
    scopes:
      - https://www.googleapis.com/auth/gmail.modify
    credential: env:GOOGLE_SERVICE_ACCOUNT_JSON

  - name: drive_upload
    scopes:
      - https://www.googleapis.com/auth/drive.file
    credential: env:GOOGLE_SERVICE_ACCOUNT_JSON

  - name: slack_post
    webhook: env:SLACK_WEBHOOK_URL

Two things to notice: the gmail_read and gmail_label scopes are separate. Read-only is safer to test with first. Add gmail.modify only when you're ready for the agent to actually apply labels.

Store your service account JSON in your environment, not in the config file. If you're unsure how OpenClaw handles secret injection, check fixing-the-7-most-common-openclaw-setup-mistakes-before-they-cost-you-hours — credential leaks are the most common early mistake.


Writing the Triage Rules

The triage logic lives in your SOUL.md file — the behavioral contract that tells the agent what to prioritize and how to make decisions.

Here's a working triage rule block:

## Inbox Triage Rules

### Flag as URGENT (apply label: Agent/Urgent)
- Sender domain matches: client-a.com, client-b.io, legalteam.com
- Subject contains: "invoice overdue", "urgent", "action required"
- Thread has no reply after 48 hours AND sender is in contacts list

### Flag as REVIEW (apply label: Agent/Review)
- Contains an attachment with extension .pdf, .docx, .xlsx
- Sender is known but not in URGENT domain list

### Archive silently (skip summary)
- Sender domain matches: newsletters.substack.com, mail.beehiiv.com
- Subject starts with: "[No reply]", "Your receipt from", "You have a new follower"

Keep the rules explicit and narrow. A rule like "flag anything that seems important" gives the model too much latitude and produces inconsistent results. Specific patterns — domains, subject prefixes, attachment types — give you predictable behavior you can audit.


Filing Attachments to Google Drive

The Drive filing logic works best when you map attachment types to specific folder IDs up front. Add this to your agent config:

drive_filing:
  rules:
    - match:
        attachment_extension: [".pdf", ".docx"]
        subject_keyword: ["invoice", "contract", "agreement"]
      destination_folder_id: "1abc123XYZ_invoices_folder_id"
      rename_pattern: "{YYYY-MM-DD}_{sender_domain}_{filename}"

    - match:
        attachment_extension: [".xlsx", ".csv"]
      destination_folder_id: "1def456_data_folder_id"
      rename_pattern: "{YYYY-MM-DD}_{filename}"

    - match:
        attachment_extension: [".png", ".jpg", ".jpeg"]
      destination_folder_id: "1ghi789_images_folder_id"
      rename_pattern: "{YYYY-MM-DD}_{filename}"

The rename_pattern field prevents the agent from clobbering files with identical names. Using the date prefix also makes your Drive folders scannable without opening each file.

Get your Drive folder IDs from the URL when you open the folder in your browser: https://drive.google.com/drive/folders/1abc123XYZ — the long string after /folders/ is the ID.


Building the Daily Summary

The daily digest is where the agent earns its keep. Add a summary block to your SOUL.md:

## Daily Summary Format

Generate a summary at the end of each run. Format:

**Date:** {today}
**Processed:** {n} messages

### Urgent (needs your attention)
{list: sender, subject, received time, reason flagged}

### Filed to Drive
{list: filename, source sender, destination folder}

### Skipped / Archived
{count only — do not list individual messages}

Send to Slack via webhook. Keep the total under 400 words.

The "skipped count only" instruction matters. You don't need a list of every newsletter the agent deleted — just confirmation it ran and a count keeps the digest readable.

If you'd rather write the summary to a Drive doc than Slack, swap slack_post in the tools block for a second drive_upload action and point it at a dedicated Summaries folder.


Running It for the First Time

Before you let the schedule trigger the agent, run it manually against a small batch:

openclaw run inbox-triage --dry-run --limit 10

The --dry-run flag tells OpenClaw to simulate all actions without applying labels or uploading files. Read the output carefully. You're looking for:

  • Messages that should be URGENT but aren't flagged
  • Messages that are flagged URGENT but shouldn't be
  • Any attachment the agent couldn't match to a Drive rule

Adjust your SOUL.md rules, run again. Do this until the dry-run output matches your expectations on 10 consecutive messages. Then drop the --dry-run flag and let it run live on a 20-message batch.

Common Mistakes

  • Overly broad URGENT rules. Flagging on the word "urgent" in subject lines will catch marketing emails. Use sender domain as the primary filter, subject keywords as secondary.
  • Missing attachment rules. If no Drive rule matches, the agent skips the file silently. Add a catch-all rule pointing to a Drive/Unsorted folder so nothing disappears.
  • Scheduling before dry-run validation. Running the schedule before testing means the agent may label dozens of messages incorrectly before you notice. Dry-run first, always.

Locking Down Permissions

This agent has access to your email and file storage. That's not a trivial scope.

Security Guardrails

  • Scope your OAuth credentials tightly. Use gmail.readonly + gmail.modify only. Do not grant gmail.compose or gmail.send unless you've deliberately added reply logic and reviewed it.
  • Rotate service account keys on a schedule. A key sitting in your environment for 18 months is a liability. Set a quarterly reminder.
  • Log every Drive upload. OpenClaw's audit_log: true flag writes tool calls to a local file. Enable it from day one so you have a record if something gets filed incorrectly.
  • Restrict Drive folder access. The service account should only have write access to the specific folders in your config — not your entire Drive.

The openclaw-security-checklist-15-things-to-lock-down-before-you-trust-an-agent covers the full permission model if you want to go deeper.


Iterating After the First Week

After seven days of running, pull your audit log and look at the numbers:

  • What percentage of URGENT flags were actually urgent?
  • Which Drive folder has the most unmatched attachments?
  • Is the daily summary the right length, or are you skimming it?

This is where most agents stall — people set them up, get the initial result, and stop tuning. A weekly 10-minute review of the audit log is what separates an agent that saves you 30 minutes a day from one that adds noise.

For a more structured approach to turning a first-run agent into something you rely on daily, from-demo-to-daily-driver-turn-your-first-openclaw-agent-into-a-reliable-worker walks through that exact iteration loop.


What This Agent Is Not (Yet)

This setup reads, labels, files, and summarizes. It doesn't:

  • Draft replies (you can add this, but it needs its own review loop)
  • Unsubscribe from mailing lists on your behalf
  • Handle calendar invites or meeting scheduling
  • Run on mobile push (it's schedule-based, not event-driven)

Those are real extensions you can build once the triage baseline is stable. Start with what you can verify. An agent that reliably files invoices and flags client emails is more useful than one that tries to do everything and gets unpredictable.


You now have a working blueprint for an AI Gmail agent OpenClaw setup that actually fits a solopreneur's workflow — not a demo, not a prototype, but a scheduled agent with explicit rules, Drive integration, and a daily summary you'll actually read.

If you want a pre-built config that wires up the Gmail, Drive, and Slack tools with sensible defaults already in place, the wizard below generates one based on your specific inbox rules and folder structure.

Wire Up Your Inbox Agent With the Right Config From Day One

Skip the trial-and-error config writing. The OpenClaw wizard generates a Gmail triage agent with Drive filing rules and audit logging already wired in — tailored to your inbox.

Generate My Inbox Agent Config

Share