凌晨3点47分,我还在和那个报表对视。 世界上有一种痛苦叫"重复性工作",它像永动机一样吞噬着你的时间。直到我遇见了Agent Skills——原来,自动化可以这么优雅。
🎯 什么是Agent Skills工作流?
Agent Skills工作流是将多个Skill串联起来,形成端到端的自动化流程。核心概念:
- Trigger(触发器):定时任务、Webhook、消息事件
- Pipeline(管线):Skill按顺序执行,前一步的输出是后一步的输入
- Action(动作):最终执行的操作,如发送消息、创建文件、调用API
- Delivery(投递):结果通知,支持announce、webhook、channel等模式
📊 典型工作流:竞品监控
- 定时触发:每天早上9点执行
- 数据采集:抓取竞品网站更新
- 内容分析:提取关键信息并总结
- 结果输出:生成报告并发送到飞书
🚀 实战案例1:每日新闻聚合
📰 场景
每天早上8点,自动抓取AI技术博客RSS,筛选重要新闻,生成摘要,发送到Discord。
Step 1:创建Cron定时任务
{
"name": "daily-ai-news",
"schedule": { "kind": "cron", "expr": "0 8 * * *", "tz": "Asia/Shanghai" },
"payload": {
"kind": "agentTurn",
"message": "执行每日AI新闻聚合任务:1)抓取OpenAI、Anthropic、HuggingFace的RSS 2)筛选重要新闻 3)生成中文摘要 4)发送到Discord #ai-news频道"
},
"delivery": { "mode": "announce", "channel": "discord" }
}
Step 2:RSS采集Skill
---
name: rss_collector
version: 1.0.0
description: 多源RSS聚合采集
tools:
- name: collect
description: 从多个RSS源采集新闻
parameters:
feeds:
type: array
description: RSS源URL列表
required: true
since_hours:
type: number
description: 仅获取N小时内的新文章
default: 24
- name: summarize
description: AI生成中文摘要
parameters:
articles:
type: array
description: 文章列表
required: true
max_items:
type: number
description: 最多摘要数量
default: 10
---
💡 关键优化
- 使用
sessionTarget: "isolated"隔离执行环境 - 设置
timeoutSeconds防止任务超时 - 配合
failureAlert在失败时自动告警
🚀 实战案例2:GitHub自动运营
🐙 场景
监控GitHub仓库Discussions,自动回答问题,标记issue,每日生成运营报告。
多步骤Cron配置
# 早上9点 - 监控并回复Discussions
{
"name": "github-morning-patrol",
"schedule": { "kind": "cron", "expr": "0 9 * * *", "tz": "Asia/Shanghai" },
"payload": {
"kind": "agentTurn",
"message": "检查GitHub Discussions新帖:1)用gh CLI列出过去1小时的新帖子 2)分析内容分类(question/bug/feature) 3)搜索知识库生成回复 4)对无法回答的打上needs-attention标签"
},
"delivery": { "mode": "none" },
"failureAlert": { "after": 3, "channel": "discord" }
}
# 晚上6点 - 生成运营日报
{
"name": "github-daily-report",
"schedule": { "kind": "cron", "expr": "0 18 * * *", "tz": "Asia/Shanghai" },
"payload": {
"kind": "agentTurn",
"message": "GitHub运营日报:1)统计今日回答数、新建issue数、star增长 2)分析热点讨论话题 3)生成Markdown报告保存到/var/www/miaoquai/github-report.html"
}
}
🚀 实战案例3:多渠道智能客服
💬 场景
飞书+Discord+邮件三渠道统一管理,AI自动分类、回复、升级。
消息路由逻辑
---
name: customer_service_router
version: 2.0.0
description: 智能客服消息路由与回复
tools:
- name: route_message
description: 根据消息内容自动分类路由
parameters:
message:
type: string
description: 客户消息原文
required: true
channel:
type: string
description: 来源渠道
required: true
returns:
type: object
properties:
category:
type: string
enum: [sales, support, billing, partnership, general]
confidence:
type: number
suggested_response:
type: string
- name: auto_reply
description: 基于知识库自动回复
parameters:
message_id:
type: string
description: 消息ID
required: true
response:
type: string
description: 回复内容
required: true
- name: escalate
description: 升级到人工客服
parameters:
message_id:
type: string
required: true
reason:
type: string
required: true
priority:
type: string
enum: [low, medium, high, urgent]
default: medium
---
# 路由规则
## 销售类 → sales_agent
关键词:价格、多少钱、付费、套餐、优惠、购买
## 技术支持 → support_agent
关键词:bug、报错、无法、错误、崩溃、安装
## 账单问题 → billing_agent
关键词:发票、退款、扣费、账单、续费
## 合作咨询 → business_agent
关键词:合作、商务、API、集成、企业版
## 默认 → general_agent
使用知识库搜索最佳匹配答案
📊 工作流编排最佳实践
1. 原子化Skill设计
每个Skill只做一件事。复杂流程通过组合实现,而非写"万能Skill"。就像乐高积木——小块灵活拼装,远比一块大砖头有用。
2. 错误隔离与容错
# ✅ 好实践:独立执行,容错处理
for step in workflow_steps:
try:
result = execute_step(step)
checkpoint(step.name, result)
except Exception as e:
log_error(step.name, e)
if step.critical:
alert_team(step.name, e)
continue # 非关键步骤跳过,不中断流程
3. 幂等性保证
# 幂等操作:重复执行不会产生副作用
def create_daily_report(date):
existing = check_report_exists(date)
if existing:
return existing # 已存在则返回
return generate_and_save_report(date)
# 非幂等操作:需要去重
def send_notification(user, message):
if already_sent(user.id, message.hash):
return # 避免重复发送
deliver(user, message)
4. 监控与可观测性
| 指标 | 说明 | 告警阈值 |
|---|---|---|
| 执行时长 | 单次工作流耗时 | > 300秒 |
| 成功率 | 步骤完成比例 | < 95% |
| 失败次数 | 连续失败计数 | > 3次 |
| 队列积压 | 待处理任务数 | > 100 |
⚡ 高级模式:SubAgent并行编排
# 使用sessions_spawn并行执行多个子Agent
# 主Agent编排
{
"plan": [
{ "agent": "news_collector", "task": "抓取AI新闻RSS", "mode": "run" },
{ "agent": "github_monitor", "task": "检查GitHub新讨论", "mode": "run" },
{ "agent": "competitor_watcher", "task": "监控竞品动态", "mode": "run" },
{ "agent": "report_generator", "task": "汇总所有数据生成日报", "mode": "run", "depends_on": ["news_collector", "github_monitor", "competitor_watcher"] }
]
}
# 子Agent调用示例
sessions_spawn(
task="抓取以下RSS源的新闻:OpenAI Blog、Anthropic Blog、HuggingFace Blog。返回JSON格式结果。",
mode="run", # 一次性执行
runtime="subagent",
label="news_collector"
)
🔥 性能提示
- 独立任务用
mode="run"并行执行,比串行快3-5倍 - 需要持续交互用
mode="session"绑定线程 - 复杂编码任务用
runtime="acp"接入专业编码Agent
⚠️ 常见坑点
- 忘记设置timeoutSeconds,Agent任务无限挂起
- cron任务没有failureAlert,失败无人知晓
- 子Agent间没有依赖管理,数据竞争
- 重复执行产生副作用(如重复发消息、重复创建文件)