大模型的Agent Skill功能,在LLM HTTP底层交互流中是怎么承载的?





01



前言

前几天我在司内论坛的一个问答中提到了要写一个拉取网络文章文本的 skill,昨天我实现了之后也就开始好奇起 Skills 的底层原理了——相比起各种花里胡哨的 agrnt 应用,我一直以来都很对大模型在纯粹的 HTTP 交互层面是如何交互的更感兴趣。


我们知道,大模型只会对话,聊天,所谓的工具调用也只不过是特化的聊天功能而已。但是各种天花乱坠的 skills,是如何在底层的 HTTP 中,与大模型——这个只会嘴遁的工具交互的呢?




02



前置知识


本文面向对 OpenAI 兼容协议 有了解的同学,如果不了解的话,可以参考协议文档,或者是我的 两篇老文章 https://cloud.tencent.com/developer/article/2518981 简单了解。




03



核心结论先说:Skills 不是协议层概念


在 OpenAI 兼容协议中,根本不存在 "Skill" 这个字段或角色。 Skills 是一个纯粹的应用层抽象,它最终被 Cursor(或类似的 AI IDE)"编译"成三种协议原语的组合:

  1. System/Developer Message — 把 Skill 的指令文本注入到 system prompt 中

  2. Tools Definition — 把 Skill 需要用到的工具(如 Shell、Read 等)注册为 tools数组

  3. Multi-turn Tool Calling Loop — LLM 根据注入的指令,自主决策发起 tool_calls,宿主执行后把结果喂回去


用一句话总结:Skill = 动态注入的 system prompt 片段 + 预定义的 tool schema + 多轮 tool calling 循环。这里我们用 Cursor 以及我实现的 skill mp-read 来举例,其他工具(OpenClaw)也是一样的——




04



第 0 步:Skill 发现与描述摘要注入


在你打开 Cursor、还没说话的时候,Cursor 就已经扫描了 .cursor/skills/、.Agents/skills/ 等目录,收集了所有 Skill 的 name + description(来自 YAML frontmatter),然后把它们作为静态上下文塞进 system prompt。


以你的 mp-read 为例,SKILL.md 的 frontmatter 是:

name: mp-readdescription: >-  Extract plain text from Tencent MP (mp.weixin.qq) articles using a headless  Chrome browser. Use when the user wants to read, fetch, extract, summarize,  or reference a MP article, or when a mp.weixin.qq URL appears in conversation.


这段信息会被注入成类似这样的 system prompt 片段(Cursor 真实行为的简化版):

<available_skills><agent_skill fullPath="/path/to/mp-read/SKILL.md">  Extract plain text from Tencent MP (mp.weixin.qq) articles using a headless  Chrome browser. Use when the user wants to read, fetch, extract, summarize,  or reference a MP article, or when a mp.weixin.qq URL appears in conversation.</agent_skill></available_skills>


注意:此时 SKILL.md 的正文还没有被读取。这就是 Cursor 文档里说的 "Progressive Loading"——只先放名字和描述,不浪费 token。




05



第 1 步:用户发问,触发 Skill


假设用户发了一句:

帮我读一下这篇公众号文章:https://mp.weixin.qq.com/s/HHPK6QvclYaxlDg28elN8w


此时 Cursor 作为客户端,构造出的第一次 API 请求大致如下(简化但忠实于 OpenAI 协议):

{  "model": "claude-4.6-opus",  "messages": [    {      "role": "system",      "content": "You are an AI coding assistant...\n\n<available_skills>\n<agent_skill fullPath=\"/Users/123456/.../mp-read/SKILL.md\">\n  Extract plain text from Tencent MP (mp.weixin.qq) articles...\n</agent_skill>\n</available_skills>\n\nWhen a skill is relevant, read and follow it IMMEDIATELY as your first action..."    },    {      "role": "user",      "content": "帮我读一下这篇公众号文章:https://mp.weixin.qq.com/s/HHPK6QvclYaxlDg28elN8w"    }  ],  "tools": [    {      "type": "function",      "function": {        "name": "Read",        "description": "Reads a file from the local filesystem...",        "parameters": {          "type": "object",          "properties": {            "path": { "type": "string", "description": "The absolute path of the file to read." },            "offset": { "type": "integer" },            "limit": { "type": "integer" }          },          "required": ["path"]        }      }    },    {      "type": "function",      "function": {        "name": "Shell",        "description": "Executes a given command in a shell session...",        "parameters": {          "type": "object",          "properties": {            "command": { "type": "string" },            "description": { "type": "string" },            "working_directory": { "type": "string" },            "block_until_ms": { "type": "number" }          },          "required": ["command"]        }      }    }  ],  "tool_choice": "auto"}


关键点:

  • tools 数组是 Cursor 预定义好的,不是 Skill 定义的。Skill 本身不声明工具——它只是告诉 LLM "你可以用 Read 来读文件,用 Shell 来执行命令"。

  • system prompt 里有 Skill 的描述摘要和一条关键指令:"When a skill is relevant, read and follow it IMMEDIATELY"




06



第 2 步:LLM 响应 — 决定先读 SKILL.md


LLM 看到用户提到了 mp.weixin.qq,匹配到了 system prompt 中 mp-read skill 的描述,于是按照指令"先读 Skill 文件"。它返回的响应是:


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