> Discover all available pages from the documentation index: https://mastra.zisheng.pro/llms.txt # `createSkill()` 创建一个无需文件系统或 Workspace、可直接传给 Agent `skills` 配置的内联 Skill。 返回的对象实现了 `Skill` 接口,可用于文件系统所发现 Skill 能够使用的任何位置。 ## 用法示例 ```typescript import { createSkill } from '@mastra/core/skills' const reviewSkill = createSkill({ name: 'code-review', description: 'Use when reviewing code changes.', instructions: ` When reviewing code: 1. Check for correctness 2. Check for style consistency 3. Look for potential bugs `, references: { 'checklist.md': '# Review Checklist\n- No unused imports\n- Error handling present', }, }) ``` ## 参数 **name** (`string`): 唯一的 Skill 名称。Agent 激活 Skill 时会将其用作标识符。必须是有效的 slug(可使用小写字母和连字符)。 **description** (`string`): 在系统消息中向 Agent 显示的简短描述,帮助 Agent 决定何时使用该 Skill。 **instructions** (`string`): 以 markdown 编写的完整 Skill 指令。当 Agent 激活该 Skill 时,这些指令会加载到对话中。 **references** (`Record`): Agent 可使用 skill\_read Tool 读取的支持文档。键为文件名,值为文件内容。 **license** (`string`): Skill 的 SPDX 许可证标识符。 **compatibility** (`unknown`): 兼容性要求。Agent Skills 规范对此保持灵活,可以是字符串数组、对象或 Tool 所需的任何结构。 **user-invocable** (`boolean`): 最终用户能否直接调用此 Skill。默认为 undefined(由 Agent 决定)。 **metadata** (`Record`): 附加到 Skill 的任意元数据。 ## 返回值 返回一个实现 `Skill` 接口的 `InlineSkill` 对象: ```typescript interface InlineSkill extends Skill { __inline: true __referenceContents: Record } ``` 系统会为 Skill 分配一个 `inline/` 格式的合成路径(例如 `inline/code-review`)。 ## 验证 `createSkill()` 使用与文件系统 Skill 相同的规则验证输入: - `name` 为必填项,且必须是有效的 slug - `description` 为必填项 - `instructions` 为必填项,且不能为空 如果验证失败,系统会抛出包含无效字段详情的 `Error`。 ```typescript // Throws: Invalid skill "": name is required createSkill({ name: '', description: 'test', instructions: 'test' }) ``` ## 相关内容 - [Agent Skills](https://mastra.zisheng.pro/docs/agents/skills) - [Workspace Skills](https://mastra.zisheng.pro/docs/workspace/skills) - [`.getSkill()` Reference](https://mastra.zisheng.pro/reference/agents/getSkill) - [`.listSkills()` Reference](https://mastra.zisheng.pro/reference/agents/listSkills)