跳转到内容
快速开始

③ 问答

Agent Skills

一个 skill 就是一个装着 SKILL.md 的目录,通过 deepagents 原生的 SkillsMiddleware 提供给 DeepAgent,按需渐进披露。

skill 让你不写代码就能教会 agent 一套做法。它就是一个装着一份 Markdown 的目录:YAML frontmatter 说明这个 skill 用来干什么,正文说明具体怎么做。

Mirobody 对 Agent Skills 的支持走的是 deepagents 原生的 SkillsMiddleware:和 LangChain 自家 deep agent 用的是同一套机制,不是我们另写的加载器。

工具
模型可以执行的代码
skill
模型可以阅读的说明

工具扩展 agent 能做什么;skill 改变它怎么做:按什么顺序推进、拿什么去对照、什么话绝不能说。这里不执行任何代码:模型读这套流程,然后用它本来就有的那些工具去照做。

  1. SKILL_DIRS 列出候选目录 随包默认是 mirobody/agent/skills;把你自己的加上并列在最前面
  2. 第一个存在的目录被挂载 以只读方式挂在 DeepAgent 虚拟文件系统的 /skills/
  3. 其中每个装着 SKILL.md 的子目录就是一个 skill 不用注册、没有清单文件,除了重启本身也没有别的挂载钩子
  4. SkillsMiddleware 把每个 skill 的 frontmatter 注入提示词 所以 agent 随时知道自己手上有哪些
  5. 正文只在任务需要时才被读取 通过 /skills/ 挂载点,用 agent 自己的 read_file
config.{env}.yaml
SKILL_DIRS:
- skills # 你的,先查
- mirobody/agent/skills

一个 skill 就是一个带 SKILL.md 的目录。别的都不需要:没有清单文件,没有 JSON 附属文件,也没有脚本。

先 YAML frontmatter,再 Markdown。真正承担契约的是两个键:

必需作用
nameskill 的身份,与目录名一致。
description路由决策就靠它。 这一段会被注入每一次提示词,所以它必须同时说清这个 skill 做什么以及什么时候该用。
licensemetadata自由字段;会被带着走,但不被解释。
SKILL.md
---
name: lab-report-walkthrough
description: Walk a person through their lab report — read the original document, organize
results by panel, flag out-of-range values against the printed reference ranges, compare
with their history, and explain in plain language. Use when the user uploads a lab report
(PDF/image) or asks what their blood test results mean.
license: Apache-2.0
metadata:
author: thetahealth
---
# Lab Report Walkthrough
Turn a raw lab report into an explanation a person can act on, without ever
drifting into diagnosis.
## Workflow
1. **Read the original, not a summary.**

这就是 skill 能扩展、而「把提示词写得更长」不能的原因:

十个 skill 的常驻代价是十段描述,而不是十套流程。只有当 agent 判断某个 skill 用得上时,才为它的正文付费。

随包只有一个 skill,而它就是给你照着写自己那个用的参照:

Skill它编码了什么
lab-report-walkthrough读原始文档而不是抽取结果;按临床套餐而不是文档顺序组织;对照纸面上印的参考范围而不是记忆里的;有历史就先比历史;用平实语言解释;绝不滑向诊断。

其中有三步值得任何健康类 skill 原样照搬。参考范围随实验室、方法、年龄与性别而不同,所以纸面上那个范围胜过模型记住的任何范围。一个值是一个点,两个值才是一个方向,所以在开口之前值得先看历史。而把超出范围的排在最前、正常项用一行汇总掉的走查,正是「有用的回答」与「十五段『这个没事』」之间的差别。

建目录

Terminal window
mkdir -p skills/medication-review

写 SKILL.md

frontmatter 里给 namedescription,然后写流程。步骤要编号;模型会按顺序照做。

skills/medication-review/SKILL.md
---
name: medication-review
description: Review the user's current medications for interactions and timing
conflicts. Use when the user asks about their medications, adds a new one, or
asks whether two things can be taken together.
---
# Medication Review
## Workflow
1. **Read what they actually take.** Call `query_health_indicators` for
medication records before assuming anything from the conversation.
2. **Group by mechanism, not by name.** Two brand names may be the same drug.
3. **Name interactions as possibilities, not verdicts.** Say what to ask a
pharmacist, and never tell someone to stop a prescribed medication.

把 SKILL_DIRS 指过去并重启

config.{env}.yaml
SKILL_DIRS:
- skills
- mirobody/agent/skills

只有第一个存在的目录会被挂载,所以把你自己的列在随包那个之前;如果两边都想要,就把随包那个 skill 复制一份,和你自己的放在同一个目录里。

确认它真的生效了

直接问 agent 它有哪些 skill。frontmatter 就在它的提示词里,所以它不必读取任何文件就能回答。

  • 它不能执行代码。 需要计算的流程必须去调工具,见添加自定义工具
  • 它不能授予权限。 一个让 agent 去读调用者无权访问的数据的 skill,照样会在工具边界上失败:身份是在那里强制的。
  • 它不能限制工具。 工具可见性由配置里的 ALLOWED_TOOLS_* / DISALLOWED_TOOLS_* 决定,不是 skill 能够收窄的范围。