Skill 技能开发与应用 · 编写与封装 · 2026-03-30

学习笔记:从 Agent 到 Skills — AI 智能体架构的范式转变

AI智能体架构正经历从单体Agent到模块化Skills的变革,Anthropic引领的这一转变正在重塑行业标准。

核心内容:

  1. Anthropic推动的MCP协议与Agent Skills开放标准发展历程
  2. 主流科技公司快速跟进Skills生态的行业现状
  3. 通过相册美化项目展示Skills架构的实际应用场景

报告日期:2026-02-28 关键词: Agent Skills, MCP, OpenClaw, A2A, Agentic AI, 模块化架构

一、谁提出了从 Agent 到 Skills 的转变?

1.1 起源:Anthropic 的两步棋

Anthropic 在不到 14 个月内连续发布了两个开放标准:

时间 事件 意义
2024年11月 Anthropic 开源 MCP(Model Context Protocol) 解决 AI 模型与外部工具/数据的连接问题
2025年10月 Anthropic 在 Claude Code 中推出 Agent Skills 解决 AI 模型的领域专业知识加载问题
2025年12月18日 Anthropic 将 Agent Skills 作为开放标准发布 48小时内被 Microsoft、OpenAI 采纳
2025年12月 MCP 捐赠给 Linux 基金会(Agentic AI Foundation) 从公司项目升级为行业标准

Anthropic 工程博客原文: "Building a skill for an agent is like putting together an onboarding guide for a new hire. Instead of building fragmented, custom-designed agents for each use case, anyone can now specialize their agents with composable capabilities."

1.2 行业响应

Agent Skills 开放标准发布后,各家跟进很快:

Gartner 2024年的预测已经应验:到2026年,75% 的 AI 项目聚焦于可组合的 Skills 而非单体 Agent。

二、一个真实项目:自动化美化相册

后续所有概念都将围绕这个项目展开,让读者在具体场景中理解抽象概念。项目所涉及的skills和代码均已开源,开源地址见文章最后。

业务目标

将旅行手机照片自动处理为社交媒体发布内容:

手机原图 → AI去杂物 → AI风格化(3种) → 拼接对比图 → 生成GIF → AI写推文 → 待发布

技术栈

组件 技术选型
AI 模型 Ming-flash-omni-2.0(多模态图文生成)
API 网关 Zenmux(Vertex AI 兼容接口)
Agent 运行环境 OpenClaw(本地自主代理框架)/ Claude Code(对比方案,详见第五章)
Agent 推理模型 Kimi K2.5 (OpenClaw) / Claude Opus 4.6 (Claude Code,仅编写时)
Skill 载体 auto-twitter-campaign Skill
文件系统 MCP @modelcontextprotocol/server-filesystem(stdio,已验证 14 个 Tools 全部可用)
微信消息通道 键盘模拟直接控制(wechat-mcp v2 协议层可通但实际操作不可用,详见第五章)

实际目录布局

## === 独立工程(各有各的 Git 仓库)===# Filesystem MCP Server(Anthropic 官方维护,已验证可用)# 安装方式:npx -y @modelcontextprotocol/server-filesystem <允许目录># 提供 14 个 Tools:read_file, write_file, edit_file, # list_directory, search_files, get_file_info, ...# 传输方式:stdio(标准输入输出)# === OpenClaw Skills — 两个目录,不同用途 ===~/.openclaw/workspace/skills/ ← "重型" Skills(带脚本的业务流水线)├── auto-twitter-campaign/ ← 本文主角:图片处理 + 文案生成│ ├── SKILL.md│ └── scripts/│ ├── campaign.py ← 编排器│ └── batch_compare.py ← 图像处理流水线├── ming-flash-omni/ ← 单图交互 Skill├── stock-analysis/ ← 股票分析└── x-trends-nvdfx/ ← Twitter 趋势~/.openclaw/skills/ ← "轻型" Skills(MCP 的使用说明书)├── filesystem/ ← 教 Agent 怎么用 Filesystem MCP│ ├── skill.json│ └── prompt.md└── wechat/ ← 教 Agent 怎么用微信键盘模拟 ├── skill.json ├── prompt.md └── scripts/send_message.sh 等# === MCP 注册配置 ===~/.claude.json → mcpServers ← 告诉 Agent 每个 MCP Server 怎么启动# === 业务数据 ===~/campaign_images/├── images/new/ ← 待处理原图(输入)├── candidates/ ← 中间产物└── results/ ← 最终产出(对比图/GIF/推文)
注意:它们是"分层引用"关系,不是"包含"关系。
层 位置 角色
MCP Server @modelcontextprotocol/server-filesystem Anthropic 官方 Node.js 包(npx 直接运行)
MCP 注册 ~/.claude.json 的 mcpServers 告诉 Agent "Server 怎么启动"
Skill 说明书 ~/.openclaw/skills/filesystem/ 教 Agent "MCP Tools 怎么用"
Skill 业务脚本 ~/.openclaw/workspace/skills/auto-twitter-campaign/ 自包含流水线,不依赖 MCP

auto-twitter-campaign 里不需要放文件系统操作或消息通道的代码。它只负责图片处理和文案。需要读取文件时 Agent 会通过 Filesystem MCP Server 操作。

三、四个核心概念 — 用同一个项目逐一拆解

3.1 Agent:如果把一切塞进 Prompt

传统 AI Agent 是一个单体式的自主推理实体,将所有能力内嵌于一个大型系统提示或模型权重中。

┌─────────────────────────────────┐│ Monolithic Agent ││ ││ ┌───────────────────────────┐ ││ │ 巨大的 System Prompt │ ││ │ (所有知识 + 所有指令) │ ││ └───────────────────────────┘ ││ ┌───────────────────────────┐ ││ │ 硬编码的工具调用逻辑 │ ││ └───────────────────────────┘ ││ ┌───────────────────────────┐ ││ │ 自定义 API 集成 │ ││ └───────────────────────────┘ │└─────────────────────────────────┘
痛点:

反模式示例:如果用纯 Agent 实现这个项目

如果没有 Skill、没有 MCP,所有知识和工具调用都硬编码在一个巨大的系统提示和脚本中,代码会变成这样:

## ❌ 单体 Agent 方案 — 反模式示例# 一个 3000 行的 monolithic_agent.pySYSTEM_PROMPT = """你是一个图片编辑助手。你需要:1. 扫描图片中的游客、车辆、栏杆等杂物2. 用 Ming-flash-omni-2.0 模型进行 inpainting 去除3. 生成3种风格变体:氛围/戏剧/艺术4. 用 Pillow 拼接对比图5. 生成 GIF 动画6. 写 Twitter 推文(格式:📍地点 📅时间 🏔️场景...)7. 写小红书文案(格式:标题+正文+标签)8. 通过 Zenmux API 发送请求,endpoint 是 https://zenmux.ai/api/vertex-ai9. 图片压缩到 2MB 以内,最大边 2048px10. 评分标准:结构保持30分 + 清理质量25分 + 无幻觉25分 + 视觉质量20分... (还有 200 行指令)"""# 所有函数都在一个文件里defanalyze_cleanup(image): ...defedit_image(image, instruction): ...defscore_image(orig, edited): ...defanalyze_styles(image): ...defmake_comparison(orig, edited): ...defmake_gif(images): ...defgenerate_tweet(images, desc): ...defpost_to_twitter(tweet, media): ... # 直接硬编码 Twitter APIdefpost_to_xiaohongshu(text, images): ... # 直接硬编码小红书 APIdefsend_wechat_notification(msg): ... # 直接硬编码微信 APIdefmain(): # 一个 main 函数串联所有逻辑,无法复用 images = scan_pending() for img in images: cleaned = cleanup(img) styles = stylize(cleaned) comparison = stitch(img, styles) gif = animate(comparison) tweet = write_tweet(comparison) post_to_twitter(tweet, gif) # 紧耦合 post_to_xiaohongshu(tweet, gif) # 紧耦合 send_wechat_notification("Done!") # 紧耦合
问题:

3.2 Skills:模块化知识包

Skills 是 Anthropic 提出的模块化、文件系统驱动的能力包。思路是把专业知识从 Agent 中拆出来,变成可以发现、加载、共享的独立模块。

my-skill/├── SKILL.md ← 主文件:YAML 元数据 + Markdown 指令├── scripts/│ ├── deploy.sh ← 可执行脚本│ └── validate.py├── templates/│ └── config.yaml ← 模板资源└── docs/ └── reference.md ← 参考文档
SKILL.md 的三层渐进式披露(Progressive Disclosure):
层级 内容 何时加载
Level 1:元数据 YAML frontmatter(名称、描述、触发条件) Agent 启动时预加载到系统提示
Level 2:指令 Markdown 正文(步骤、规则、约束) 匹配到相关任务时按需加载
Level 3:资源 脚本、模板、文档 执行阶段才访问

好处在于:Agent 不用一次性吞下所有知识,按需加载,省上下文窗口。

实战:auto-twitter-campaign Skill 的三层披露

Level 1:元数据 — Agent 启动时预加载(仅 30 字)

---name: auto-twitter-campaigndescription: Autonomous AI image campaign content generator. Processes pending photos via Ming-flash-omni-2.0 (cleanup + style editing), creates side-by-side comparison images and GIF showcases, then auto-generates tweet text using AI.---
当用户对 OpenClaw 说"帮我处理照片",Agent 扫描所有 Skill 的元数据,仅凭 description 这 30 个字就知道该加载这个 Skill,而不需要加载全部代码。

Level 2:指令 — 匹配后按需加载

## Quick Startpython3 {baseDir}/scripts/campaign.py runpython3 {baseDir}/scripts/campaign.py processpython3 {baseDir}/scripts/campaign.py showcase --description "大年初四唐乾陵"## Pipeline1. Cleanup Director → 2. Cleanup Creator → 3. Style Director→ 4. Style Creator → 5. Showcase → 6. Tweet Writer
Agent 读到这里就知道该调用哪个命令、传什么参数。

Level 3:资源 — 执行阶段才访问

## scripts/batch_compare.py 中的具体实现代码# Agent 直接执行 python3 命令,不需要理解内部逻辑

Director-Creator-Critic 模式 — Skill 内部的多角色编排

batch_compare.py 实际上实现了一个微型多 Agent 系统,但它被封装在单个 Skill 内部:

## === Director(导演):决定做什么 ===defanalyze_cleanup(client, image_data): """扫描图片,识别杂物,输出一条清理指令""" prompt = ( "You are an expert photo retoucher. Your job is to find EVERY " "non-natural element... Look for: People, vehicles, barriers..." ) # 返回: "Repaint the silver car on the right with clean ground" # 或: "NONE"# === Creator(执行者):生成候选方案 ===defedit_image(client, image_data, instruction, is_cleanup=False): """根据指令生成编辑后的图片""" # cleanup 模式: inpainting 去杂物 # style 模式: 风格迁移 # 每次调用生成 1 张,循环 3 次生成 3 个候选# === Critic(评审员):打分选优 ===defscore_image(client, orig_data, edit_data, instruction): """对比原图和编辑图,按 4 个维度打分 0-100""" # 结构保持 (30分) + 清理质量 (25分) # + 无幻觉 (25分) + 视觉质量 (20分)

值得注意的是:这三个"角色"都是同一个 LLM 模型(Ming-flash-omni-2.0)在不同 Prompt 下的表现,而不是三个独立的 Agent。用 Prompt 编排代替 Agent 编排。

Director (分析 Prompt) → "去除右侧三个游客" │Creator ×3 (编辑 Prompt) → 3 个候选图 │Critic (评分 Prompt) → "候选2最佳,85分"

不需要部署多个 Agent 就能实现多角色协作。同一个 LLM 在不同 Prompt 下扮演不同角色,全部封装在一个 Skill 的脚本中。这比部署 3 个独立 Agent + A2A 协议要轻量得多。

编排层 — campaign.py 的实际代码结构

## campaign.py — 薄编排层,不包含业务逻辑defcmd_process(args): """动态导入 batch_compare.py 并执行""" spec = importlib.util.spec_from_file_location( "batch_compare", SCRIPT_DIR / "batch_compare.py" ) mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) mod.main() # 全部业务逻辑在 Skill 的脚本中defcmd_showcase(args): """GIF 生成 + AI 写推文""" generate_gifs(results_dir) # Pillow 处理 generate_tweet_text(results_dir) # Ming API 调用defcmd_run(args): """完整流水线 = process + showcase""" cmd_process(args) # Stage 1: 图片处理 cmd_showcase(args) # Stage 2: 展示 + 文案

3.3 MCP:标准化工具连接

MCP 是 Anthropic 于 2024年11月开源的 AI 模型与外部工具/数据源的连接协议,基于 JSON-RPC 2.0。有人叫它"AI 的 USB-C"。

┌──────────────┐ JSON-RPC2.0 ┌──────────────┐│ MCPClient │ ◄──────────────────► │ MCPServer ││ (AI 应用) │ StreamableHTTP │ (外部服务) │└──────────────┘ └──────────────┘ │ │ Claude/GPT/ GitHubAPI Gemini 等 数据库/ 文件系统等

MCP 提供三类能力:

1. Tools — 外部函数(查询数据库、发送消息)2. Resources — 数据源(文件内容、API 响应)3. Prompts — 提示模板时间线:

实战:Filesystem MCP Server 验证

// ~/.claude.json 中的 MCP 配置{ "mcpServers":{ "filesystem":{ "command":"npx", "args":["-y","@modelcontextprotocol/server-filesystem","~/campaign_images"], "type":"stdio" } }}

@modelcontextprotocol/server-filesystem 是 Anthropic 官方维护的 MCP Server,用 Node.js 实现,通过 stdio 传输与 Agent 通信。

实测验证过程(2026-02-26):

## 1. MCP 握手 — 成功$ echo'{"jsonrpc":"2.0","id":1,"method":"initialize",...}' \ | npx -y @modelcontextprotocol/server-filesystem ~/campaign_images→ {"serverInfo":{"name":"secure-filesystem-server","version":"0.2.0"}}# 2. 工具发现 — 14 个 Tools→ read_file, read_text_file, read_media_file, read_multiple_files, write_file, edit_file, create_directory, list_directory, list_directory_with_sizes, directory_tree, move_file, search_files, get_file_info, list_allowed_directories# 3. list_directory — 列出 pose 编辑结果$ tools/call list_directory {"path":"~/campaign_images/results/pose"}→ [FILE] pose_微信图片_20260226155545_1_248_rank1.jpg [FILE] pose_微信图片_20260226155545_1_248_rank2.jpg [FILE] pose_微信图片_20260226155545_1_248_grid.jpg ...# 4. get_file_info — 查询文件元数据$ tools/call get_file_info {"path":"...rank1.jpg"}→ size: 218451, permissions: 644, isFile: true# 5. search_files — 搜索所有 prompts 文件$ tools/call search_files {"path":"...results/pose","pattern":"*prompts*"}→ pose_IMG_6382_prompts.txt pose_微信图片_20260226155545_1_248_prompts.txt

Agent 不需要知道文件系统的具体实现(本地磁盘、NFS、云存储),只通过标准化的 list_directory、search_files、read_file 等 Tools 交互。换底层存储时,换 MCP Server 就行,Agent 代码不用动。

Skill 与 MCP 的精确分界线

在这个项目中,~/.openclaw/skills/ 下实际有两类 Skill:原生 Skill 和 MCP 封装 Skill。

原生 Skill(代码即能力):

auto-twitter-campaign/├── SKILL.md ← Agent 接口└── scripts/ ├── campaign.py ← 自包含的 Python 脚本 └── batch_compare.py

Skill 内部直接调用 Zenmux API(genai.Client),不依赖任何 MCP Server。Agent 只需要执行 python3 scripts/campaign.py run,脚本自带一切。

MCP 封装 Skill(Skill 是 MCP 的"使用说明书"):

filesystem/├── skill.json ← Skill 元数据(触发条件)└── prompt.md ← "怎么使用 Filesystem MCP"的说明wechat/├── skill.json├── prompt.md ← "怎么使用微信键盘模拟"的说明└── scripts/ ├── send_message.sh ← 简单的 shell 包装 ├── read_chat.sh └── list_contacts.sh

MCP 封装 Skill 本身不含核心逻辑,就是一本"使用手册",教 Agent 怎么调用已经运行的 MCP Server。

MCP 是"递给你一把锤子",Skill 是"教你怎么用这把锤子"。

两者的协作关系:

Skill: filesystem/prompt.md "当用户想查看处理结果时,先通过 MCP 的 list_directory 列出文件, 然后用 search_files 搜索特定模式的文件, 再用 get_file_info 获取文件大小和修改时间..." │ ▼ Agent 按照 Skill 指令行动 │MCP Server: filesystem (stdio) server.tool("list_directory", {path}) server.tool("search_files", {path, pattern})

简单说:能写成脚本跑完的,用 Skill;需要跟外部服务保持连接的,用 MCP。

场景 正确方案 原因
图片清理 + 风格化 Skill(batch_compare.py) 一次性批处理,无需持续连接
读取/搜索文件 MCP(filesystem) 需要运行时动态查询,数据随时变化
写推文文案 Skill(campaign.py) 确定性的 Prompt + 模板,无需外部服务

3.4 OpenClaw:Agent 运行环境

OpenClaw 是奥地利开发者 Peter Steinberger(PSPDFKit/Nutrient 创始人)做的开源 AI 代理框架,目前是 Skills 生态里最活跃的平台。

改名历史:

核心架构:

┌─────────────────────────────────────────┐│ OpenClaw 架构 ││ ││ Gateway─── 消息平台连接层 ││ │ (WhatsApp/Telegram/Discord ││ │ + 可桥接扩展其他平台) ││ ▼ ││ Agent──── 推理引擎(理解用户意图) ││ │ ││ ▼ ││ Skills─── 模块化能力扩展 ││ │ (3000+ 社区 Skills) ││ ▼ ││ Memory─── 持久化存储层 ││ (上下文 + 偏好) │└─────────────────────────────────────────┘

特点:

实战:完整生产架构

┌─────────────────────────────────────────────────────────┐│ 完整生产架构 ││ ││ 用户入口: ││ ┌──────┐ ┌──────────┐ ┌───────┐ ┌──────┐ ││ │ 微信 │ │微信(桥接) │ │Telegram│ │CLI │ ││ └──┬───┘ └──┬───────┘ └───┬───┘ └──┬───┘ ││ │ bridge_openclaw.py │ │ ││ │ (轮询+转发) │ │ ││ └─────────┴──────────────┴─────────┘ ││ │ ││ OpenClawGateway ││ (localhost:18789) ││ │ ││ OpenClawAgent ││ (KimiK2.5 推理引擎) ││ │ ││ ┌──────────────┼──────────────┐ ││ ▼ ▼ ▼ ││ ┌────────┐ ┌──────────┐ ┌──────────┐ ││ │Skills│ │ MCP │ │ Memory │ ││ └────┬───┘ └────┬─────┘ └──────────┘ ││ │ │ ││ ┌────┴────────────┴────────────────┐ ││ │ │ ││ │ Skill: auto-twitter-campaign │ ││ │ ├ campaign.py (编排) │ ││ │ └ batch_compare.py (处理) │ ││ │ │ ││ │ Skill: ming-flash-omni │ ││ │ └ ming_image.py (单图交互) │ ││ │ │ ││ │ MCP: filesystem │ ││ │ └ stdio → 文件读写/搜索/列表 │ ││ │ │ ││ │ Skill: wechat-bridge │ │

注意:OpenClaw 原生支持 Slack、WhatsApp、Telegram、Discord 等渠道,但不包含微信。微信接入需要通过自定义桥接脚本 bridge_openclaw.py(轮询微信消息 +…

— 以上为试看内容(约 40%),开通会员后阅读全文 —

原文出处:https://www.53ai.com/news/tishicikuangjia/2026033008732.html