Lesson 05

Skill Loading 技能加载

别把所有东西塞进 system prompt,按需加载

// Architecture Diagram 架构图

skills/ ├── commit.md ├── review-pr.md ├── create-pr.md ├── pdf.md ├── debug.md │ (each ~2000 tokens) └── ... 5+ skill files on disk LAYER 1: System Prompt Only the catalog / 只有目录 /commit - 创建提交 /review-pr - 审查PR /create-pr - 创建PR ~200 tokens catalog only load_skill("commit") LAYER 2: Tool Result Full skill body injected / 完整技能内容注入 --- name: commit description: Create git commits... --- # Full instructions (~2000 tokens)... Token Comparison Token 对比 Without 不使用: ~10000 tokens With 使用: ~200 tokens 98% savings 节省 Token 开销 parse YAML read full body LEGEND 图例 System Prompt Tool Result On-demand load Trigger point
CONCEPT 01

两层架构

目录(catalog)放在 system prompt,只占 ~200 tokens。完整技能内容通过 tool_result 按需注入,避免一次性加载全部技能。

catalog → system_prompt
body → tool_result

CONCEPT 02

Token 经济学

假设有 5 个 skill,每个 ~2000 tokens。全部塞进 system prompt = 10000 tokens。按需加载只需 ~200 tokens 目录 + 当前 skill 内容。

10000 → 200 (98% saved)

CONCEPT 03

YAML Frontmatter

每个 skill 文件用 YAML frontmatter 声明元数据(name, description, allowed_tools),正文是详细指令。解析时分离目录信息和完整内容。

--- metadata ---
# full instructions

试一试 Try It Out

1

"有哪些技能可用?"

"What skills are available?"

2

"加载 agent-builder skill 并按照它的说明操作"

"Load the agent-builder skill and follow its instructions"

3

"我需要做代码审查——先加载相关 skill"

"I need to do a code review -- load the relevant skill first"

4

"使用 mcp-builder skill 构建一个 MCP 服务器"

"Build an MCP server using the mcp-builder skill"