在 Bob Shell 中创建和使用技能
创建一个可复用的技能,教 Bob Shell 一套可重复的 changelog-entry 工作流,然后显式调用它并观察 Bob 自动激活它。
IBM Bob Shell 技能是存储在 SKILL.md 文件中的可复用指令集,用于教 Bob 一套可重复的工作流。在本教程中,你将构建一个 changelog-entry 技能,用于向 CHANGELOG.md 添加 Keep a Changelog 条目,使用 $changelog-entry 显式运行它,然后观察当提示词与技能描述匹配时 Bob 如何自动激活它。
技能可以避免你在每个提示词中重复输入相同的格式规则或检查清单。你只需定义一次工作流,只要技能适用,Bob 就会遵循它。
前提条件
- 如果尚未克隆,请克隆 Galaxium Travels 演示代码。
git clone https://github.com/IBM/galaxium-travels - 虽然不是必需的,但建议先完成使用 /init 和 AGENTS.md 启动项目和为 Bob Shell 编写有效提示词。
创建 changelog-entry 技能
Bob Shell 从包含 SKILL.md 文件的文件夹中加载技能。项目技能位于项目根目录下的 .bob/skills/ 中,因此 Git 会将其与代码库一起跟踪,供团队成员使用。全局技能位于 ~/.bob/skills/ 中,适用于所有项目。
编写 SKILL.md 文件
创建包含以下内容的 .bob/skills/changelog-entry/SKILL.md。你可以使用任何文本编辑器,或直接运行命令:
cat > .bob/skills/changelog-entry/SKILL.md <<'EOF'
---
name: changelog-entry
description: Adds an entry to CHANGELOG.md using the Keep a Changelog format, creating the file if it does not exist, so change history stays consistent and release-ready.
---
Add an entry to CHANGELOG.md using the Keep a Changelog format (https://keepachangelog.com/).
- If CHANGELOG.md does not exist, create it at the project root with this structure before adding an entry:
# Changelog
All notable changes to this project are documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
## [Unreleased]
- Add new entries under the `## [Unreleased]` section, under one of these subheadings: `### Added`, `### Changed`, `### Fixed`, `### Removed`. Create the subheading if it is not already present under `## [Unreleased]`.
- Write each entry as a single bullet point in the imperative mood ("Add", not "Added"), starting with a capital letter, with no trailing period.
- Base the entry on the actual diff, not on the wording of the request. Run `git diff` to review what changed before writing the entry.
- Only edit CHANGELOG.md. Do not stage or commit the change.
EOFFront matter 定义了两个必填字段:
name:技能名称。请使其与文件夹名称一致,因为 Bob Shell 使用文件夹名称来引用技能,例如$changelog-entry。description:当你未按名称引用技能时,Bob 通过读取该描述来决定技能是否适用于当前请求。如果省略,Bob 将改用指令的第一行,因此务必编写清晰的描述。
闭合 --- 分隔符以下的所有内容都是技能激活时 Bob 遵循的指令集。
启动 Bob Shell
在 Galaxium Travels 根目录下以 Agent 模式启动交互式会话:
bob chat --mode agentAgent 模式为 Bob 提供了激活技能和编辑文件所需的工具访问权限。如果 Bob Shell 询问你是否信任该文件夹,请信任该文件夹,以便 Bob 能够加载项目的技能。
直接调用技能
按名称引用技能,以便查看 Bob 遵循的指令。
编辑 README.md
让 Bob 进行一次小范围、低风险的编辑,以便有内容可记录:
Add a one-line note to the end of the README.md that says "Powered by IBM Bob."Bob 会以 diff 形式显示建议的更改。选择 Approve 应用编辑。
使用技能记录变更
输入 $ 打开技能选择器,然后选择 changelog-entry。Bob Shell 会将技能引用插入到你的提示词中:
$changelog-entry Add a changelog entry for this change.Bob 会请求使用技能和编辑文件的权限。批准每个请求。Bob 会加载 changelog-entry 技能并创建 CHANGELOG.md(因为项目中尚不存在该文件)。然后 Bob 会添加类似以下内容的条目:
## [Unreleased]
### Added
- Add "Powered by IBM Bob." note to the end of README.md让 Bob 自动激活技能
进行第二次修改,并在不提及技能名称的情况下让 Bob 记录它。Bob 可以根据技能的描述识别其适用性并自行激活。
进行第二次 README.md 编辑
让 Bob 进行第二次编辑:
Add a one-line comment above the main heading in README.md that says "Galaxium Travels".出现提示时批准编辑。
在不命名技能的情况下记录变更
在不命名技能的情况下让 Bob 记录变更:
Add an entry to CHANGELOG.md in Keep a Changelog format.Bob 识别出该请求与 changelog-entry 技能的描述相匹配,并在没有 $changelog-entry 引用的情况下自动激活它。出现提示时批准技能和文件编辑请求。Bob 会以相同格式添加另一个条目。
验证两个更新日志条目
让 Bob 向你展示更新日志:
Show me @CHANGELOG.md更新日志现在在 ## [Unreleased] 下包含两个条目,类似如下内容:
## [Unreleased]
### Added
- Add "Powered by IBM Bob." note to the end of README.md
- Add "Galaxium Travels" comment above the main heading in README.md管理你的技能
每个技能都是磁盘上的一个文件夹,因此你可以使用日常的文件工具来管理技能:
- 列出技能:查看项目技能的
.bob/skills/目录和全局技能的~/.bob/skills/目录。如果两个位置包含同名技能,项目技能优先。 - 编辑技能:编辑其
SKILL.md文件。你还可以向技能文件夹中添加支持文件,例如模板或检查清单。 - 引用技能:在 Bob Shell 中输入
$或输入/skills将技能引用插入到提示词中。
故障排除
技能未出现在 $ 选择器中
确认文件路径为 .bob/skills/changelog-entry/SKILL.md,front matter 包含 name 和 description,并且文件夹已被信任。详情请参阅受信任的文件夹。技能文件夹名称必须为小写 kebab-case 格式,例如 changelog-entry。Bob 会跳过名称无效的文件夹且不显示错误。添加技能后请重新启动 Bob Shell。
Bob 未自动激活技能
Bob 会根据技能的 description 匹配请求。尝试重新表述提示词以使用描述中的词语,或者直接使用 $changelog-entry 引用技能。
后续步骤
在本教程中,你学习了技能如何让你只需定义一次工作流即可让 Bob 一致地应用它。你可以使用 $<skill-name> 显式引用技能,也可以让 Bob 根据其描述自动激活。
要向技能添加模板和支持文件,请参阅技能。
要构建具有专属角色、指令和工具访问权限的专门角色,请参阅自定义模式。