Skip to main content

技能

🌐 Skills

技能是可重复使用的指令,用于教导代理如何执行特定任务。它们遵循代理技能规范——一种用于打包代理能力的开放标准。

🌐 Skills are reusable instructions that teach agents how to perform specific tasks. They follow the Agent Skills specification - an open standard for packaging agent capabilities.

技能是一个包含以下内容的文件夹:

🌐 A skill is a folder containing:

  • SKILL.md:代理的说明和元数据
  • references/:支持文件(可选)
  • scripts/:可执行脚本(可选)
  • assets/:图片和其他文件(可选)
Folder structure
/skills
/code-review
SKILL.md
/references
style-guide.md
pr-checklist.md
/scripts
lint.ts

当在工作区配置技能时,坐席可以在对话中发现并激活这些技能。

🌐 When skills are configured on a workspace, agents can discover and activate them during conversations.

SKILL.md 格式
Direct link to SKILL.md 格式

🌐 SKILL.md format

在创建技能时,请遵循官方的 技能规范。以下是一个代码审查技能的示例 SKILL.md

🌐 Follow the official skill specification when creating your skill. Here is an example SKILL.md for a code review skill:

SKILL.md
---
name: code-review
description: Reviews code for quality, style, and potential issues
version: 1.0.0
tags:
- development
- review
---

# Code Review

You are a code reviewer. When reviewing code:

1. Check for bugs and edge cases
2. Verify the code follows the style guide in references/style-guide.md
3. Suggest improvements for readability
4. Run the linter using scripts/lint.ts

## What to look out for

- Unused variables and imports
- Missing error handling
- Security vulnerabilities
- Performance issues

配置技能
Direct link to 配置技能

🌐 Configuring skills

通过在你的工作区设置 skills 选项来启用技能发现:

🌐 Enable skill discovery by setting the skills option on your workspace:

src/mastra/workspaces.ts
import { Workspace, LocalFilesystem } from '@mastra/core/workspace';

const workspace = new Workspace({
filesystem: new LocalFilesystem({ basePath: './workspace' }),
skills: ['/skills'],
});

skills 目录相对于你的 basePath。你可以指定多个技能目录:

🌐 The skills directory is relative to your basePath. You can specify multiple skill directories:

src/mastra/workspaces.ts
const workspace = new Workspace({
filesystem: new LocalFilesystem({ basePath: './workspace' }),
skills: [
'/skills', // Project skills
'/team-skills', // Shared team skills
],
});

动态技能
Direct link to 动态技能

🌐 Dynamic skills

对于基于上下文的动态技能路径,请传入一个函数:

🌐 For dynamic skill paths based on context, pass a function:

const workspace = new Workspace({
filesystem: new LocalFilesystem({ basePath: './workspace' }),
skills: (context) => {
const paths = ['/skills'];
if (context.user?.role === 'developer') {
paths.push('/dev-skills');
}
return paths;
},
});

代理如何使用技能
Direct link to 代理如何使用技能

🌐 How agents use skills

当代理激活一个技能时,该技能的指令会被添加到对话上下文中。然后,代理可以遵循这些指令并访问该技能的参考资料和脚本。

🌐 When an agent activates a skill, the skill's instructions are added to the conversation context. The agent can then follow those instructions and access the skill's references and scripts.

在内部,这涉及到:

🌐 Under the hood this involves:

  1. 在系统消息中列出可用技能
  2. 允许代理在对话中激活技能
  3. 提供对技能参考和脚本的访问

🌐 Skill search

如果工作区启用了 BM25 或向量搜索,技能会自动建立索引。代理可以在技能内容中搜索以找到相关的指令。

🌐 If BM25 or vector search is enabled on the workspace, skills are automatically indexed. Agents can search across skill content to find relevant instructions.

const workspace = new Workspace({
filesystem: new LocalFilesystem({ basePath: './workspace' }),
skills: ['/skills'],
bm25: true,
});

🌐 Related