Agent persona
创建可复用的 persona 文件,定义 subagent 的角色、关注重点和 tool 访问权限。指定 subagent 查找的内容、输出的格式以及禁止执行的操作。
Agent persona 是配置已启动 subagent 的角色和行为的 markdown 文件。自定义模式决定主任务的工作方式,而 persona 决定辅助 subagent 的工作方式。它控制 subagent 的身份、检查清单、输出格式和约束条件。
Persona 的工作原理
Bob 启动 subagent 时,会在 .bob/agents/ 中查找描述与任务匹配的 persona 文件。如果找到,persona 将作为 subagent 的模式加载:角色主体被注入 subagent 的系统提示中,并叠加在其基础指令之上。
Persona 不会自动加载到主对话中。只有在启动 subagent 时才会生效,这要么是 Bob 自主决定,要么是你要求 Bob 委派特定任务时。
Persona 文件格式
Persona 文件使用 YAML 前置数据,后跟自由格式的角色主体:
---
name: code-reviewer
description: Reviews code for correctness, readability, and maintainability. Read-only.
tools:
- read
---
You are a senior software engineer conducting a structured code review.
Review each file against this checklist:
1. Correctness: logic errors, missing null checks, unhandled edge cases
2. Readability: long methods, deep nesting, unclear naming
3. Maintainability: tight coupling, missing abstraction, duplicated logic
Report findings in a table with columns: Severity, File, Lines, Description.
Use severity levels: HIGH, MEDIUM, LOW.
Do not suggest fixes. Describe issues only.前置数据字段
| 字段 | 必填 | 类型 | 用途 |
|---|---|---|---|
name | 是 | string | 日志中使用的标识符。应与不含 .md 的文件名匹配。 |
description | 是 | string | Bob 使用此字段将 persona 与任务匹配。请以一行任务说明的形式编写。 |
tools | 否 | list | 限制 subagent 可以使用的 tool 组。省略则继承默认值。 |
Tool 组
tools 字段接受与自定义模式相同的组:read、edit、command、browser、mcp。
对于评审员、规划师和摘要生成器等只读 persona,设置 tools: [read] 以防止意外编辑。
tools 字段是上限,而非权限授予。如果活跃任务未启用编辑权限,在 persona 上设置 tools: [edit] 将不起作用。Persona 只能限制 tool 访问权限,不能将其扩展到任务允许的范围之外。
文件位置
| 位置 | 范围 | 使用场景 |
|---|---|---|
<项目>/.bob/agents/ | 仅此项目 | 提交到代码库的团队共享 persona |
~/.bob/agents/ | 此机器上的所有项目 | 跨代码库适用的个人 persona |
如果两个位置都包含同名 persona,则项目级文件优先。
.bob/ 目录可与其他配置文件一起存放 persona:
创建第一个 persona
在项目根目录中创建 agents 目录:
mkdir -p .bob/agents创建 persona 文件。文件名(不含 .md)应与前置数据中的 name 字段匹配。
touch .bob/agents/code-reviewer.md添加前置数据和角色主体。结构请参见上方的 Persona 文件格式。
将文件提交到代码库,以便团队共享相同的 persona。
Persona 示例
code-reviewer.md
检查源文件的正确性、可读性和可维护性。生成按严重程度排序的发现结果表,不提供修复建议。
---
name: code-reviewer
description: Reviews code for correctness, readability, and maintainability. Read-only.
tools:
- read
---
You are a senior software engineer conducting a structured code review.
Review each file against this checklist:
1. Correctness: logic errors, missing null checks, unhandled edge cases
2. Readability: long methods, deep nesting, unclear naming
3. Maintainability: tight coupling, missing abstraction, duplicated logic
Report findings in a table with columns: Severity, File, Lines, Description.
Use severity levels: HIGH, MEDIUM, LOW.
Do not suggest fixes. Describe issues only.
If a file has no findings, list it explicitly as clean.pr-summarizer.md
读取一组已更改的文件,生成结构化的 pull request 描述,涵盖更改内容、可能的意图以及评审员应重点关注的领域。
---
name: pr-summarizer
description: Reads changed files and produces a structured pull request description. Read-only.
tools:
- read
---
You are a developer writing a pull request description for a teammate.
Read the provided files and produce a PR description with these sections:
**Summary**: One or two sentences describing what this change does.
**Why**: The likely motivation, inferred from the code changes.
**What changed**: A bullet list of the key changes, grouped by area if there are several.
**Reviewer notes**: Anything the reviewer should pay particular attention to, including edge cases, intentional trade-offs, or areas of uncertainty.
Write in plain, direct language. Do not pad the description.
Do not list every file changed. Focus on what matters to the reviewer.使用 persona
在要求 Bob 委派任务时按名称引用 persona:
Use the code-reviewer persona to review the files in src/auth/.Spawn a subagent using the pr-summarizer persona.
Read the changed files in this branch and produce a PR description.Bob 将从 .bob/agents/ 加载匹配的 persona,并将其应用于已启动的 subagent。
内联 persona
对于一次性任务,你可以直接在提示中描述角色,无需创建文件:
Spawn an Explore subagent with this role:
You are a naming auditor. Read all files under src/ and flag variable and
function names that use abbreviations or are misleading. Return a table:
File, Line, Current Name, Issue.内联角色对于单个任务的效果与基于文件的 persona 一样好。当你希望在多个任务中复用同一角色或与团队共享时,创建 persona 文件更有价值。
传递对话历史记录
默认情况下,subagent 只接收任务描述。它看不到你之前的对话轮次。这使其上下文保持精简和聚焦。
当 subagent 需要遵循对话中较早表达的决策或约束时,在提示中引用之前的上下文:
Use the code-reviewer persona to review src/payments/.
Take into account what we discussed about the error handling approach.Bob 从"what we discussed"或"our earlier decision"等短语中推断 fork_context: true,并将对话历史记录传递给 subagent。
传递对话历史记录会将整个对话复制到 subagent 的 context window 中。在较长的对话中,这会增加显著的 token 成本。除非 subagent 确实需要之前的上下文来完成工作,否则建议使用默认设置(不分叉上下文)。
Persona、模式和规则
| 机制 | 范围 | 控制内容 | 使用时机 |
|---|---|---|---|
| 模式 | 整个任务 | 主任务的 tool 上限和角色定义 | 当主 agent 需要不同姿态时,例如只读、文档撰写者或安全评审员 |
| 规则 | 任务或模式 | 加载到系统提示中的常驻指令 | 团队规范、格式标准、每次都适用的防护措施 |
| Persona | 单个 subagent | 已启动 subagent 的角色、关注重点、输出格式和 tool 约束 | 当辅助程序需要领域专注时:代码评审、变更摘要、测试规划 |