跳转到主要内容

Documentation Index

Fetch the complete documentation index at: https://docs.devinenterprise.com/llms.txt

Use this file to discover all available pages before exploring further.

子 Agent 让主 Agent 能够生成独立的工作单元来处理子任务。子 Agent 会与父 Agent 共享工具和代码库上下文,但会在自己的对话链中运行——不会继承父 Agent 的对话历史。这对于那些适合专注、独立处理的任务尤其有用——例如探索代码库、运行测试,或并行实现某项功能。 你可以明确要求 Agent 使用子 Agent (例如“在子 Agent 中调研认证机制的工作方式”) ,或者当 Agent 判断某项任务适合独立处理时,也可能自行决定交给子 Agent。 根据我们的测量,子 Agent 既能 提升整体编码效率 又能 降低成本

子 Agent 的工作方式

当 Agent 创建子 Agent 时,会从可用的子 Agent Profile中选择一个,并决定该子 Agent 在前台还是后台运行。子 Agent 可以按以下两种模式运行:

前台

在你的当前会话中内联运行。父 Agent 会暂停,并等待子 Agent 完成后再继续。你可以在工具调用出现时逐个批准或拒绝。

后台

在父 Agent 继续工作的同时并行运行。子 Agent 完成后,父 Agent 会自动收到通知。未经批准的工具调用会被自动拒绝。
你无法直接看到子 Agent 的原始输出。子 Agent 完成后,父 Agent 会读取结果,并为你总结关键发现和执行的操作。

子 Agent Profile

每个子 Agent 都会以特定的 Profile 运行,该 Profile 决定其能力。有两个内置 Profile:
Profile说明工具访问权限
subagent_explore只读的代码库探索与研究只读代码库工具以及网页搜索;无法编辑文件,也无法抓取任意 URL (无论在前台还是后台)
subagent_general包括代码修改在内的通用任务完整工具访问权限 (前台) 或仅可使用预先批准的工具 (后台)
Agent 会根据任务自动选择合适的 Profile。探索型子 Agent 非常适合用于研究和理解,而通用子 Agent 则可以进行修改。
你也可以自定义子 Agent Profile——请参阅下方的 Custom Subagents

工具权限

工具权限的运作方式取决于子 Agent 是在前台还是后台运行:
  • 前台子 Agent 的行为与主 Agent 类似——你会像往常一样收到提示,批准或拒绝工具调用。
  • 后台子 Agent 会继承你在当前会话中已授予的工具权限。任何未预先批准的工具都会被自动拒绝。后台子 Agent 无法提示你授予新权限。
如果后台子 Agent 因所需工具被拒绝而失败,你可以在前台恢复它,以批准所需权限。请参阅下方的 恢复子 Agent

子 Agent 监控

子 Agent 指示器

当后台 子 Agent 运行时,输入区域下方会显示一个指示器,用于显示其状态。你可以在输入区域按 将焦点移动到该指示器,然后按 Enter 打开 子 Agent 面板。 当前台 子 Agent 运行时,加载指示器会显示 “Subagent 正在运行 · Ctrl+B 可切换到后台运行”

子 Agent 面板

子 Agent 面板可让你查看和管理所有活跃中和已完成的子 Agent。它会显示每个子 Agent 的 Profile、标题、状态、耗时以及工具调用次数。

前台 / 后台切换

你可以在子 Agent 运行时在前台和后台之间切换:
  • 将前台子 Agent 切换到后台: 在前台子 Agent 运行时,按 Ctrl+B。子 Agent 会继续在后台运行,父 Agent 则恢复执行。
  • 将后台子 Agent 切换到前台: 打开子 Agent 面板,在正在运行的后台子 Agent 上按 f。子 Agent 的输出将以内联方式显示。
当你将子 Agent 移到后台时,父 Agent 的工具调用已经返回,因此父 Agent 会继续独立执行。子 Agent 的结果不会再反馈到父 Agent 当前的处理流程中,但它完成时你会收到通知。

取消子 Agent

你可以通过以下两种方式取消正在运行的子 Agent:
  1. 通过子 Agent 面板: 打开面板,然后在正在运行的子 Agent 上按 x
  2. 前台子 Agent:Ctrl+CEsc,取消当前正在运行的前台子 Agent。

恢复子 Agent

已取消、失败或已完成的子 Agent都可以通过新的提示恢复。你可以让 Agent 恢复某个子 Agent,它会从中断处继续。恢复后的子 Agent始终在前台运行,因此你可以批准此前被拒绝的任何工具调用。 这在以下情况下尤其有用:
  • 后台子 Agent因某个必需工具被拒绝而失败——可在前台恢复它,以授予所需权限。
  • 某个子 Agent已完成,但你希望它根据其发现继续执行额外的后续工作。
  • 某个子 Agent被过早取消,而你希望它继续执行。

嵌套深度

默认情况下,子 Agent 无法再生成自己的子 Agent——只有根 Agent 可以。为防止出现无限嵌套,子 Agent 内会禁用子 Agent 工具 (run_subagentread_subagent) 。 不过,自定义子 Agent 的 Profile 可以通过在其 frontmatter 中设置 max-nesting 字段来启用嵌套生成。该值会覆盖默认的最大深度;只要树结构不超过这个限制,子 Agent 就可以生成子级。 例如,max-nesting: 3 允许出现如下链式结构:
Root agent(深度 0)
└── Custom subagent(深度 1)— 可以生成子 Agent
    └── Child subagent(深度 2)— 可以生成子 Agent
        └── Grandchild subagent(深度 3)— 无法生成(已达深度上限)
嵌套子 Agent 可能会显著增加成本。每增加一层嵌套,都会生成额外的 Agent,并带有各自的上下文窗口和推理调用。请谨慎使用此功能。

自定义子 Agent

自定义子 Agent 是实验性功能。其格式、行为和配置选项可能会在后续版本中发生变化。
除了内置的 subagent_exploresubagent_general Profile 外,你还可以定义自己的自定义子 Agent Profile。自定义子 Agent 可让你创建专用工作单元,并为其设置各自的系统提示、工具限制、模型覆盖和权限,以适配工作流程中的特定任务。

创建自定义子 Agent

自定义子 Agent 通过在 agents/ 下的具名目录中放置 AGENT.md 文件来定义。目录名称将作为该 Profile 的标识符。
.devin/agents/
└── reviewer/
    └── AGENT.md
也支持:
.agents/agents/
└── reviewer/
    └── AGENT.md

AGENT.md 格式

AGENT.md 文件使用与技能相同的 YAML frontmatter,随后是子 Agent 的系统提示:
---
name: reviewer
description: Reviews code changes for correctness and style
model: sonnet
allowed-tools:
  - read
  - grep
  - glob
  - exec
permissions:
  allow:
    - Exec(git diff)
    - Exec(git log)
  deny:
    - write
    - edit
---

You are a code review subagent. Your job is to review code changes
thoroughly and report findings back to the parent agent.

Focus on:
1. Correctness — logic errors, edge cases, off-by-one mistakes
2. Security — potential vulnerabilities
3. Style — consistency with the rest of the codebase
4. Performance — obvious inefficiencies

Always cite specific file paths and line numbers in your findings.

Frontmatter 字段

字段类型默认值描述
namestring目录名该 Profile 的标识符 (不得与内置 Profile 冲突)
descriptionstring在选择 Profile 时向 Agent 显示
modelstring默认子 Agent 模型覆盖该子 Agent 使用的模型
allowed-tools列表所有工具限制该子 Agent 可使用的工具
permissionsobject继承权限覆盖 (allowdenyask)
max-nestinginteger覆盖最大嵌套深度,使该子 Agent 能够生成自己的子 Agent

自定义子 Agent 的使用方式

定义完成后,自定义子 Agent 的 Profile 会与内置 Profile 一起显示。Agent 会看到每个可用 Profile 的说明,并在创建子 Agent 时选择最合适的一个。你也可以要求 Agent 按名称使用特定的 Profile (例如:“使用 reviewer 子 Agent 审查这段代码”) 。 如果自定义子 Agent 的 Profile 名称与内置 Profile 名称冲突 (例如 subagent_exploresubagent_general) ,则会跳过该 Profile 并显示警告。

从其他工具导入

自定义子 Agent 也可以从 Claude Code 的 Agent 格式中导入:
来源文件匹配模式
.claude/agents/*.md每个 .md 文件都会成为一个子 Agent 的 Profile
Claude Code 的 Agent 文件在 frontmatter 中使用 tools,而不是 allowed-tools。这两种格式都会被自动支持。

示例

只读调研 Agent

---
name: researcher
description: Deep codebase research and architecture analysis
model: sonnet
allowed-tools:
  - read
  - grep
  - glob
---

You are a research subagent specializing in codebase exploration.

Your job is to thoroughly investigate a topic and report back with:
- Relevant files and their purposes
- Architecture patterns and dependencies
- Code flow traces with specific line references

Be exhaustive — search broadly and follow references.

测试执行 Agent

---
name: test-runner
description: Runs tests and reports results
allowed-tools:
  - read
  - grep
  - glob
  - exec
permissions:
  allow:
    - Exec(npm run test)
    - Exec(cargo nextest)
    - Exec(pytest)
---

你是一个测试运行 子 Agent。运行相关的 test suites 并报告:
- 哪些测试通过,哪些失败
- 失败信息和 stack traces
- 针对失败的修复建议