s04
Skills 技能系统
能力层按需渐进加载
索引注入系统提示词 → read_file 按需加载完整内容两阶段加载策略让 token 消耗可控,同时保持丰富的知识覆盖
按需渐进加载
索引注入系统提示词 → read_file 按需加载完整内容两阶段加载策略让 token 消耗可控,同时保持丰富的知识覆盖
DeerFlow 的技能系统让 Agent 具备可扩展的专业能力。每个技能是一个目录,包含 SKILL.md(YAML frontmatter 定义元数据 + Markdown 正文定义工作流)。系统启动时扫描目录构建轻量索引注入 system prompt,Agent 按需调用 read_file 加载完整内容——索引只消耗几百 token,完整内容按需加载。
parse_skill_file — 解析 SKILL.md 的 YAML frontmatter 提取 name/description/license
def parse_skill_file(skill_file: Path, category: str, relative_path=None):
content = skill_file.read_text(encoding="utf-8")
# 提取 YAML front matter: ---\nkey: value\n---
front_matter_match = re.match(
r"^---\s*\n(.*?)\n---\s*\n", content, re.DOTALL)
metadata = {}
for line in front_matter.split("\n"):
if ":" in line:
key, value = line.split(":", 1)
metadata[key.strip()] = value.strip()
return Skill(
name=metadata["name"],
description=metadata["description"],
skill_dir=skill_file.parent,
category=category, # 'public' or 'custom'
)get_skills_prompt_section — 将技能索引生成 XML 注入 system prompt,Agent 通过 read_file 按需加载
def get_skills_prompt_section(available_skills=None):
skills = load_skills(enabled_only=True)
container_base_path = config.skills.container_path # /mnt/skills
# 生成轻量 XML 索引(每个技能只有 name + description + location)
skill_items = "\n".join(
f" <skill>\n"
f" <name>{s.name}</name>\n"
f" <description>{s.description}</description>\n"
f" <location>{s.get_container_file_path(container_base_path)}</location>\n"
f" </skill>" for s in skills)
return f"""<skill_system>
Progressive Loading Pattern:
1. 用户查询匹配技能描述 → read_file 加载 SKILL.md
2. 执行时按需加载引用的外部资源
<available_skills>{skill_items}</available_skills>
</skill_system>"""SKILL.md 实例 — YAML frontmatter 定义触发条件,正文定义研究方法论
---
name: deep-research
description: Use this skill instead of WebSearch for ANY
question requiring web research. Trigger on queries like
"what is X", "explain X", "compare X and Y"...
---
# Deep Research Skill
## When to Use This Skill
- User asks "what is X", "explain X"
- Content generation tasks needing real-world data
## Research Methodology
### Phase 1: Broad Exploration
### Phase 2: Deep Dive
### Phase 3: Synthesis