Communitygithub.com

aiagentwithdhruv/skills

自动将 Gmail 收件箱中的电子邮件标记为“需要处理”、“等待回复”和“参考”类别。当用户要求标记邮件、管理收件箱、分类邮件或整理 Gmail 时使用。

skills 是什么?

这是一个用于 Gmail 邮箱的自动标签分类技能,能够通过并行子代理高效地将收件箱中的电子邮件分类为“需要处理”、“等待回复”和“参考”三类。该技能主要面向使用 Claude Code 等 AI 代理工具的开发者,帮助自动化收件箱管理,减少手动分类的工作量。技能支持并行执行模式,通过将邮件切分为多个分块,同时启动多个子代理进行分类,大幅提升处理速度——对 100 封邮件,分类时间可从 34 秒缩短至 19 秒。最终通过 Gmail API 批量应用标签。该技能依赖于 Sonnet 模型进行低成本、高效的分类判断,并提供了详细的分类指南和账户注册机制。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/aiagentwithdhruv/skills/tree/HEAD/gmail-label

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Gmail 自动标签

目标

获取收件箱中的邮件,通过并行子代理将其分类为“需要处理”、“等待回复”和“参考”,并通过 Gmail API 批量应用标签。

脚本

  • ./scripts/gmail_label_fetch.py — 获取邮件摘要,输出紧凑 JSON
  • ./scripts/gmail_label_split.py — 将邮件拆分为 N 个分块,用于并行分类
  • ./scripts/gmail_label_merge.py — 合并已分类的分块为单个 labels.json
  • ./scripts/gmail_label_apply.py — 批量应用标签分类

子代理

  • email-classifier — 定义在 .claude/agents/email-classifier.md
  • 模型:Sonnet 4.5(快速、经济的分类)
  • 每个子代理读取一个分块,写入一个分类后的输出文件

流程(并行模式 — 默认)

步骤 1:获取邮件

python3 .claude/skills/gmail-label/scripts/gmail_label_fetch.py \
  --account ACCOUNT --query "in:inbox" --limit 100 --output .tmp/emails.json

步骤 2:拆分为分块

python3 .claude/skills/gmail-label/scripts/gmail_label_split.py \
  --input .tmp/emails.json --chunks 10 --output-dir .tmp/chunks

步骤 3:并行分类(启动 10 个子代理)

在后台启动 10 个 email-classifier 子代理,每个代理处理一个分块。每个子代理:

  • 读取 .tmp/chunks/chunk_N.json
  • 对每封邮件进行分类
  • 写入 .tmp/chunks/classified_N.json

使用任务工具,设置 run_in_background: true 和 model: "sonnet"。在单条消息中启动全部 10 个任务以实现真正的并行:

For each chunk 0-9, spawn a Task with:
  subagent_type: "email-classifier"
  model: "sonnet"
  run_in_background: true
  prompt: "Read /absolute/path/.tmp/chunks/chunk_N.json, classify each email, write results to /absolute/path/.tmp/chunks/classified_N.json"

关键:不要使用 TaskOutput 读取子代理结果。 子代理将结果写入文件——主代理无需看到分类数据。读取 TaskOutput 会淹没上下文窗口,导致大批量(500+ 封邮件)时出现“提示过长”错误。

改为轮询文件是否存在:

# 等待所有分类文件创建完成(超时 120 秒)
for i in $(seq 0 9); do
  while [ ! -f ".tmp/chunks/classified_$i.json" ]; do sleep 2; done
done

然后直接进入步骤 4(合并)。

步骤 4:合并分类结果

python3 .claude/skills/gmail-label/scripts/gmail_label_merge.py \
  --input-dir .tmp/chunks --output .tmp/labels.json

步骤 5:应用标签

python3 .claude/skills/gmail-label/scripts/gmail_label_apply.py \
  --account ACCOUNT --input .tmp/labels.json

分类指南

需要处理:

  • 需要验证的安全警报
  • 即将过期的信用卡/域名续费(有截止日期)
  • Slack @提及提问
  • 需要问候的新团队成员(Slack 加入通知)
  • 需要回复的客户邮件
  • 商家信息更新(Google Business Profile、Bing Places)
  • Stripe 需要操作的通知

等待回复:

  • 等待回复的外发销售邮件
  • 等待解决的支持工单
  • 已发送待回复的提案

参考:

  • 营销新闻通讯(DigitalMarketer 等)
  • 慈善/非营利新闻通讯(RAPS 等)
  • Google Business Profile 效果报告
  • 促销优惠(Blinkist、促销等)
  • 平台更新通知(Google Play、Apify 等)
  • 确认码(已使用)
  • 房地产新闻通讯(Westbank 等)
  • 游戏账户邮件(Riot Games 等)
  • 信息性安全警报(已开启双因素认证等)
  • 健康建议
  • 法律/政策更新通知

账户注册

账户存储在工作空间根目录的 gmail_accounts.json 中。每个账户需要:

  • email — Gmail 地址
  • token_file — OAuth 令牌路径

添加新账户

python3 .claude/skills/gmail-inbox/scripts/gmail_multi_auth.py --account ACCOUNT_NAME --email EMAIL

性能

  • 串行流程:100 封邮件约 36 秒(获取 1 秒 + 分类 34 秒 + 应用 1 秒)
  • 并行流程:100 封邮件约 30 秒(分类 19 秒 + 合并 <1 秒 + 应用约 10 秒)
  • 分类是瓶颈;10 个并行子代理将其从 34 秒降至 19 秒(约 1.8 倍加速)
  • 代理启动开销(约 4 秒的错开时间)限制了理论增益
  • 应用步骤可能因 Gmail API 限流而有所变化

架构

输入

名称类型必填描述
account字符串是注册表中的 Gmail 账户名称
query字符串否Gmail 搜索查询(默认:'in:inbox')
limit整数否最大分类邮件数量(默认:100)
chunks整数否并行分类分块数(默认:10)

输出

名称类型描述
labels_applied对象每个类别的计数:需要处理、等待回复、参考

凭证

名称来源
credentials.json文件
token_*.json文件(自动生成)

可组合技能

与此技能衔接良好的技能:gmail-inbox

成本

Claude Sonnet API 用于分类

Individual skills in this repo

This repo contains 10 individual skills — each has its own dedicated page.

aiagentwithdhruv/skills

Add new Modal webhooks for event-driven execution. Use when user asks to create a webhook, add an endpoint, or set up event triggers.

aiagentwithdhruv/skills

Answer Euron Gen AI Bootcamp doubts instantly. Covers Euri API setup across all frameworks (Python, LangChain, OpenAI SDK, TypeScript, n8n, curl), MCP server setup, common errors, model recommendations, and token limits. Use when someone in the bootcamp asks a question.

aiagentwithdhruv/skills

Manage emails across multiple Gmail accounts with unified tooling. Use when user asks to check email, read inbox, label emails, archive messages, or manage Gmail across accounts.

aiagentwithdhruv/skills

Scrape Google Maps for B2B leads with deep website enrichment and contact extraction. Use when user asks to find local businesses, scrape Google Maps, generate contractor lists, or build local service business databases.

aiagentwithdhruv/skills

Run Claude orchestrator locally with Cloudflare tunneling. Use when user asks to run locally, start local server, or test webhooks locally.

aiagentwithdhruv/skills

MCP server for AI-powered macOS control — apps, display, audio, files, screenshots, clipboard

aiagentwithdhruv/skills

Deploy execution scripts to Modal cloud. Use when user asks to deploy to Modal, push code to cloud, or update Modal functions.

aiagentwithdhruv/skills

Scrape and verify business leads using Apify, classify with LLM, enrich emails, and save to Google Sheets. Use when user asks to find leads, scrape businesses, generate prospect lists, or build lead databases for any industry or location.

aiagentwithdhruv/skills

Query Skool community content using RAG pipeline with vector search. Use when user asks to search Skool knowledge, find community answers, or query Skool content.

aiagentwithdhruv/skills

Scrape Upwork jobs and generate personalized proposals with cover letters. Use when user asks to find Upwork jobs, create Upwork proposals, or apply to Upwork listings.

相关技能