Skip to main content
技能是可复用的智能体能力,提供专业化的工作流程和领域知识。 您可以使用 Agent Skills 为您的深度智能体提供新能力和专业知识。 深度智能体技能遵循 Agent Skills 规范

什么是技能

技能是一个由文件夹组成的目录,每个文件夹包含一个或多个供智能体使用的上下文文件:
  • 包含技能说明和元数据的 SKILL.md 文件
  • 可选的附加脚本
  • 可选的附加参考信息(例如文档)
  • 可选的附加资源(例如模板和其他资源)
任何附加资源(脚本、文档、模板或其他资源)都必须在 SKILL.md 文件中注明其内容和使用方式,以便智能体决定何时使用它们。

技能的工作原理

创建深度智能体时,您可以传入包含技能的目录列表。智能体启动时,会读取每个 SKILL.md 文件的前置元数据(frontmatter)。 当智能体收到提示词时,它会检查是否有技能可以帮助完成该任务。如果找到匹配的技能,则会查看技能的完整文件。这种仅在需要时才读取技能信息的模式称为渐进式披露

示例

您可能有一个技能文件夹,其中包含一个用于特定方式使用文档站点的技能,以及另一个用于搜索 arXiv 预印本研究论文库的技能:
    skills/
    ├── langgraph-docs
    │   └── SKILL.md
    └── arxiv_search
        ├── SKILL.md
        └── arxiv_search.py # code for searching arXiv
SKILL.md 文件始终遵循相同的格式:以前置元数据开头,后跟技能说明。 以下示例展示了一个在收到提示时提供相关 LangGraph 文档的技能:
---
name: langgraph-docs
description: Use this skill for requests related to LangGraph in order to fetch relevant documentation to provide accurate, up-to-date guidance.
---

# langgraph-docs

## Overview

This skill explains how to access LangGraph Python documentation to help answer questions and guide implementation.

## Instructions

### 1. Fetch the Documentation Index

Use the fetch_url tool to read the following URL:
https://docs.langchain.com/llms.txt

This provides a structured list of all available documentation with descriptions.

### 2. Select Relevant Documentation

Based on the question, identify 2-4 most relevant documentation URLs from the index. Prioritize:

- Specific how-to guides for implementation questions
- Core concept pages for understanding questions
- Tutorials for end-to-end examples
- Reference docs for API details

### 3. Fetch Selected Documentation

Use the fetch_url tool to read the selected documentation URLs.

### 4. Provide Accurate Guidance

After reading the documentation, complete the user's request.
更多示例技能,请参阅 深度智能体示例技能
重要提示编写技能文件时,请参阅完整的 Agent Skills 规范了解约束条件和最佳实践。特别注意:
  • description 字段若超过 1024 个字符将被截断。
  • 在深度智能体中,SKILL.md 文件必须小于 10 MB。超过此限制的文件在加载技能时会被跳过。

完整示例

以下示例展示了使用所有可用前置元数据字段的 SKILL.md 文件:
---
name: langgraph-docs
description: Use this skill for requests related to LangGraph in order to fetch relevant documentation to provide accurate, up-to-date guidance.
license: MIT
compatibility: Requires internet access for fetching documentation URLs
metadata:
  author: langchain
  version: "1.0"
allowed-tools: fetch_url
---

# langgraph-docs

## Overview

This skill explains how to access LangGraph Python documentation to help answer questions and guide implementation.

## Instructions

### 1. Fetch the documentation index

Use the fetch_url tool to read the following URL:
https://docs.langchain.com/llms.txt

This provides a structured list of all available documentation with descriptions.

### 2. Select relevant documentation

Based on the question, identify 2-4 most relevant documentation URLs from the index. Prioritize:

- Specific how-to guides for implementation questions
- Core concept pages for understanding questions
- Tutorials for end-to-end examples
- Reference docs for API details

### 3. Fetch selected documentation

Use the fetch_url tool to read the selected documentation URLs.

### 4. Provide accurate guidance

After reading the documentation, complete the user's request.

使用方法

创建深度智能体时传入技能目录:
from urllib.request import urlopen
from deepagents import create_deep_agent
from deepagents.backends.utils import create_file_data
from langgraph.checkpoint.memory import MemorySaver

checkpointer = MemorySaver()

skill_url = "https://raw.githubusercontent.com/langchain-ai/deepagents/refs/heads/main/libs/cli/examples/skills/langgraph-docs/SKILL.md"
with urlopen(skill_url) as response:
    skill_content = response.read().decode('utf-8')

skills_files = {
    "/skills/langgraph-docs/SKILL.md": create_file_data(skill_content)
}

agent = create_deep_agent(
    skills=["/skills/"],
    checkpointer=checkpointer,
)

result = agent.invoke(
    {
        "messages": [
            {
                "role": "user",
                "content": "What is langgraph?",
            }
        ],
        # Seed the default StateBackend's in-state filesystem (virtual paths must start with "/").
        "files": skills_files
    },
    config={"configurable": {"thread_id": "12345"}},
)
skills
list[str]
技能来源路径列表。路径必须使用正斜杠,并相对于后端根目录指定。
  • 若省略,则不加载任何技能。
  • 使用 StateBackend(默认)时,通过 invoke(files={...}) 提供技能文件。使用 deepagents.backends.utils 中的 create_file_data() 格式化文件内容;不支持原始字符串。
  • 使用 FilesystemBackend 时,技能从后端 root_dir 的相对路径加载。
当多个来源包含同名技能时,列表中靠后的来源优先(后者覆盖前者)。
SDK 仅加载您在 skills 中传入的来源,不会自动扫描 CLI 目录(如 ~/.deepagents/...~/.agents/...)。有关 CLI 存储惯例,请参阅应用数据
如果希望在 SDK 代码中实现类似 CLI 的分层效果,请按从低到高的优先级顺序显式传入所有期望的来源:
[
"<user-home>/.deepagents/{agent}/skills/",
"<user-home>/.agents/skills/",
"<project-root>/.deepagents/skills/",
"<project-root>/.agents/skills/",
]
然后将该有序列表作为 skills 参数传入创建智能体的调用中。

来源优先级

当多个技能来源包含同名技能时,skills 数组中靠后的来源优先(后者覆盖前者)。这允许您从不同来源分层叠加技能。
# If both sources contain a skill named "web-search",
# the one from "/skills/project/" wins (loaded last).
agent = create_deep_agent(
    skills=["/skills/user/", "/skills/project/"],
    ...
)

子智能体的技能

使用子智能体时,您可以配置每种子智能体可访问的技能:
  • 通用子智能体:当您向 create_deep_agent 传入 skills 时,自动继承主智能体的技能,无需额外配置。
  • 自定义子智能体:不继承主智能体的技能。请在每个子智能体定义中添加 skills 参数,指定该子智能体的技能来源路径。
技能状态完全隔离:主智能体的技能对子智能体不可见,子智能体的技能对主智能体也不可见。
from deepagents import create_deep_agent

research_subagent = {
    "name": "researcher",
    "description": "Research assistant with specialized skills",
    "system_prompt": "You are a researcher.",
    "tools": [web_search],
    "skills": ["/skills/research/", "/skills/web-search/"],  # Subagent-specific skills
}

agent = create_deep_agent(
    model="claude-sonnet-4-6",
    skills=["/skills/main/"],  # Main agent and GP subagent get these
    subagents=[research_subagent],  # Researcher gets only its own skills
)
有关子智能体配置和技能继承的更多信息,请参阅子智能体

智能体所见内容

配置技能后,“技能系统”部分会被注入智能体的系统提示中。智能体使用这些信息遵循三步流程:
  1. 匹配 — 当用户提示词到来时,智能体检查是否有技能描述与任务匹配。
  2. 读取 — 如果某个技能适用,智能体使用技能列表中显示的路径读取完整的 SKILL.md 文件。
  3. 执行 — 智能体按照技能说明操作,并根据需要访问任何支持文件(脚本、模板、参考文档)。
SKILL.md 的前置元数据中编写清晰、具体的描述。智能体仅根据描述决定是否使用某个技能——描述越详细,技能匹配效果越好。

技能与记忆的对比

技能与记忆AGENTS.md 文件)用途不同:
技能记忆
用途通过渐进式披露按需发现的能力启动时始终加载的持久上下文
加载时机仅在智能体判断相关时读取始终注入系统提示
格式命名目录中的 SKILL.mdAGENTS.md 文件
分层用户 → 项目(后者优先)用户 → 项目(合并)
适用场景说明与任务相关且可能较长时上下文始终相关时(项目约定、个人偏好)

何时使用技能与工具

以下是使用工具和技能的一些通用建议:
  • 当上下文较多时使用技能,以减少系统提示中的 token 数量。
  • 使用技能将多个能力捆绑为更大的动作,并在单个工具描述之外提供额外上下文。
  • 当智能体无法访问文件系统时,使用工具。