模型可见工具名是 Agent,历史别名是 Task。本设计文档称为 Subagent,但实现时需要保留 Agent 作为模型可见工具名,与兼容的 Claude Code 插件生态中的 agent 配置、transcript 和 SDK 事件保持一致。
Agent 不是一个普通函数调用,而是一个小型 agent runtime 入口。它根据输入选择一种执行形态:
| 形态 | 触发条件 | 说明 |
|---|---|---|
| fresh subagent | 指定 subagent_type,或未启用 fork 时省略 subagent_type |
新建独立 agent 对话,只拿到本次 prompt 和该 agent 自己的 system prompt |
| fork subagent | fork gate 开启且省略 subagent_type |
子 agent 继承父会话历史、system prompt 和精确 tool pool,用于 prompt cache 共享 |
| background subagent | run_in_background、agent 定义 background: true、coordinator、assistant mode、fork gate 或 proactive 强制 |
立即返回 task 引用,完成后以通知重新进入主会话 |
| worktree subagent | isolation: "worktree" 或 agent 定义自带 worktree isolation |
在临时 git worktree 中运行,完成后无变更自动清理,有变更保留路径和 branch |
| remote agent | isolation: "remote" |
远程环境执行;ZCode 当前不支持 |
| teammate spawn | team_name 和 name 同时存在 |
这是 agent team/swarm,不是普通 subagent,应作为独立工具或独立模式处理 |
关键边界:普通 subagent 不是 OS 子进程,而是在同一进程内创建新的子执行上下文,再运行新的 query loop。外部进程、tmux、in-process teammate 和 remote agent 属于 agent team 或 remote task 分支,不应和普通 subagent 混成一个概念。
模型可见基础输入:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
description |
string |
是 | 3 到 5 个词的短描述,用于 UI、task 状态、activity 文案 |
prompt |
string |
是 | 给子 agent 的任务正文 |
subagent_type |
string |
否 | 要使用的 agent 类型。fork gate 关闭时省略则默认为 general-purpose,开启时省略则触发 fork |
run_in_background |
boolean |
否 | 请求后台运行。后台任务禁用或 fork gate 开启时 schema 会隐藏该字段 |
Agent 模型可见输入不包含 invocation 级 model 覆盖。旧 transcript 可以保留历史
model 字段,但当前输入 schema 会忽略该字段;child runtime 只消费 Settings 或 Markdown
定义解析出的 Agent profile 模型。
扩展输入:
| 字段 | 类型 | 适用范围 | 说明 |
|---|---|---|---|
name |
string |
background subagent 或 teammate | 给 spawned agent 起可寻址名称。background subagent 可通过 SendMessage({ to: name }) 继续 |
team_name |
string |
agent team | 与 name 一起触发 teammate spawn。省略时可使用当前 team context |
mode |
permission mode | agent team | 主要用于 spawned teammate,例如 plan 模式。普通 subagent 不应把它当作子 agent permission override |
isolation |
"worktree" \| "remote" |
subagent | worktree 创建临时 git worktree。remote 当前不支持 |
cwd |
string |
gated | 让子 agent 在指定 cwd 中运行。要求绝对路径,并且与 isolation: "worktree" 互斥 |
ZCode 需要把 schema gating 做成能力协商结果,而不是在 tool 内散落 feature flag。cwd 的绝对路径和与 worktree 的互斥关系也应进入 validateInput,不能只放在 prompt description。
公开 output schema 主要有两类:
status |
字段 | 说明 |
|---|---|---|
completed |
prompt 加 agentToolResultSchema |
同步完成,返回子 agent 最终文本、usage、tool use 数、耗时和 agentId |
async_launched |
agentId、description、prompt、outputFile、canReadOutputFile |
后台启动成功,结果稍后通过 task notification 返回 |
内部还有两个分支:
status |
说明 |
|---|---|
teammate_spawned |
team/swarm 分支,返回 teammate id、name、team、pane 等信息 |
remote_launched |
remote 分支,返回 remote task id、session URL 和 output file |
agentToolResultSchema:
| 字段 | 类型 | 说明 |
|---|---|---|
agentId |
string |
子 agent ID,也是 transcript/task/output 的关联键 |
agentType |
string? |
agent 类型。用于 one-shot 内建 agent 跳过 continuation trailer |
content |
{ type: "text"; text: string }[] |
子 agent 最终文本块 |
totalToolUseCount |
number |
子 agent 内部 tool use 总数 |
totalDurationMs |
number |
总耗时 |
totalTokens |
number |
最后一条 assistant usage 汇总出的 token 数 |
usage |
provider usage object | input、output、cache、server tool use、service tier 等 |
模型可见序列化不是原样 JSON:
content 直接交给父 agent,再追加 agentId 和 <usage> trailer。Explore、Plan 这类 one-shot 内建 agent 如果没有 worktree 信息,会省略 agentId 和 usage trailer,降低 token 成本。Read 或 Bash 时才提示可以读或 tail output file。ZCode 的用户/项目自定义 Markdown 仅从各自 agents 根目录直接文件加载
(.md / .markdown,大小写规则不变),不扫描子目录;独立 CLI、Host 和 Settings
使用同一范围。插件 agent 继续遵循已有插件发现规则。详见根目录 docs/subagent-runtime-refresh.md。
agent definition 有三类来源:
| 来源 | 说明 |
|---|---|
| built-in | 代码内建,system prompt 动态生成 |
| custom | 用户、项目、policy、flag settings 中的 markdown 或 JSON agent |
| plugin | plugin 提供的 agent,agent type 会带 plugin namespace |
agent definition 的核心字段:
| 字段 | 说明 |
|---|---|
agentType |
模型调用 subagent_type 时使用的稳定名称 |
whenToUse |
写入 Agent tool prompt 的选择说明 |
getSystemPrompt |
子 agent system prompt |
tools |
允许 tool spec。省略或 ["*"] 表示可用全集经过 filter 后全部允许 |
disallowedTools |
在允许全集上再次剔除 |
model |
agent 默认模型,inherit 表示继承父模型 |
effort |
推理 effort 覆盖 |
permissionMode |
agent 内部工具权限模式。普通 worker 默认使用 acceptEdits |
maxTurns |
agent 内部 query loop 最大轮数 |
skills |
启动时预加载的 prompt skill |
mcpServers |
child 可见的 parent MCP server 范围;设计上可支持引用或 inline config,ZCode 当前只接受 parent server name 列表 |
requiredMcpServers |
agent 可用性前置条件,必须有匹配 server 且有工具 |
hooks |
agent 生命周期内注册的 session scoped hooks |
background |
agent 总是后台运行 |
initialPrompt |
agent 初始 prompt 扩展 |
memory |
user/project/local agent memory |
isolation |
agent 默认隔离模式 |
injectAgentsMd |
是否向 child 注入 AGENTS.md;只读内建 agent 默认不注入以省 token,见下文 |
加载优先级是 built-in、plugin、user、project、flag、managed 逐组覆盖,同名 agent 后面的源会覆盖前面的源。解析失败的 markdown 只在看起来像 agent 文件时进入 failedFiles。
ZCode 的 custom agent Markdown 额外支持可选 frontmatter 字段 injectAgentsMd: boolean。它只控制 child request 是否注入父 runtime 已解析的 AGENTS.md,不改变 agent system prompt:
| Profile | injectAgentsMd 缺省行为 |
|---|---|
内建 general-purpose |
注入 |
内建 Explore |
不注入 |
| custom | 注入;显式设为 false 时关闭 |
child runtime 只接收父 runtime contextSourceSnapshot.userInstructions 的快照;父级没有 snapshot 时不注入,也不在 child 中重新读取文件或构造 fallback。provider-visible 位置与 Main 相同,复用 Main 的 Request User Context formatter:
父 runtime 已解析的 userInstructions
|
v
child system messages(现有 4 段,保持不变)
meta-user context_prefix
|- # agentsMd + AGENTS.md(允许注入且内容非空时)
`- currentDate
真实 child task
AGENTS.md 不得拼入 agent-specific prompt、common Notes 或 environment system message;child 也不继承 Main 的 Project Context 或 Project Memory。Settings 的 user custom agent 表单在 system prompt 编辑器下方以单行“注入 AGENTS.md”开关展示该字段,文案与 Switch 垂直居中,不显示辅助说明;修改在下一次 runtime/profile 加载时生效,不增加热刷新链路。
# agentsMd 标题与 Main 共用同一 formatter,并按聚合 request-user-context 是否非空渲染一次。
child 不继承 Main Project Memory,因此在 child 链路中实际判断仍等价于父 snapshot 是否包含非空
AGENTS.md;Explore、显式关闭注入的 custom agent 以及父 snapshot 没有 AGENTS.md 时均不渲染。
子 agent 不是简单继承父工具。普通 subagent 使用:
permissionMode 生成 worker permission context,默认 acceptEdits。tools、disallowedTools 和全局 subagent 过滤(区分同步与后台 agent)。全局过滤规则:
ExitPlanMode 只在 plan-mode agent 中特殊允许。TaskOutput、ExitPlanMode、EnterPlanMode、AskUserQuestion、TaskStop 等默认禁止给 subagent。Agent,避免递归。SendMessage,用于 team 协作。Agent(...) tool spec 有特殊含义:在主线程可以携带允许的 agent type 列表,限制模型能选择哪些 subagent_type。在 subagent 内部这个 spec 只保留元数据,不真正解析出 Agent 工具。
fork 路径例外:fork child 使用父 agent 的精确 tool array,同时继承父 thinking config 和 non-interactive 设置。这是为了让 system prompt、tools、model、messages 和 thinking config 保持 byte-identical,从而命中 prompt cache。
普通 fresh subagent:
effectiveType:显式 subagent_type 优先,省略时根据 fork gate 选择 fork 或 general-purpose。prompt。ToolTimeout 结束并写入 SubagentStopped。如果父级
abort 后 child promise 不 settle,应以 ToolCancelled 结束,避免 foreground Agent 长期
停在 running。fork subagent:
subagent_type 且 fork gate 开启。querySource 和消息中的 fork boilerplate tag 防止 fork child 再 fork。agentType 是 fork、model 是 inherit、permissionMode 是 bubble、tools 是 ["*"]。background subagent:
agentId,注册 LocalAgentTask。output.txt 和 task.output;子 agent 的 messages/parts 和恢复所需 session state 由 session store(默认 SQLite)持久化。async_launched,父 agent 继续处理别的工作或结束本轮。<task-notification> 把 status、summary、output file、usage、worktree 信息重新送进主会话。<error> 保存同一原文,summary 保留既有 Agent <type> task "<description>" failed. 前缀并在其后直接追加该原文,不翻译、不映射错误码,也不把失败伪装成 <result>。completed 只表示后台任务已成功启动;匹配 tool-use-id 的 failed notification 才能覆盖 launch ACK。live event 与 snapshot/restore 都必须用 notification 的 failed + error 覆盖,保证现有“执行失败”状态文案和 hover 错误详情在切换任务后不丢失;stopped/killed 等其它恢复语义不在本次变更范围内。sync 转 background:
return() 清理,再以同一个 task id 重新以后台方式运行 child。async_launched。子执行上下文默认隔离所有可变状态:
| 状态 | 默认行为 |
|---|---|
| read file state | 从 parent clone,结束时 clear |
| abort controller | 新 child controller。同步 Agent 可以显式共享 parent controller,后台 agent 使用独立 controller |
| app state 读取 | 默认标记为避免权限弹窗,防止后台 agent 弹交互权限 |
| app state 写入 | 默认 no-op。需要 task 注册和 kill 时只通过 task 专用入口写 root store |
| response length | 可选择共享,让子 agent 计入父响应 metrics |
| memory/skill/dynamic triggers | fresh Set |
| content replacement state | clone parent,fork 用于保持 cache replacement 决策一致 |
| query tracking | 新 chain id,depth 在 parent 基础上加一 |
child 运行时还会:
agentId。SubagentStart hooks,并把 hook additional context 作为 attachment message 加进初始消息。SubagentStop。transcript.jsonl,子 agent history 由 session store(默认 SQLite)落库。ZCode 不再写入独立的 transcript.jsonl 文件。子 agent 的 messages/parts 与恢复所需 session state
由 session store(默认 SQLite)持久化;session event store 负责运行期事件排序、live sink 和
进程内事件回放。任务 artifact 目录只保存 output.txt、task.output 和 metadata.json。
metadata 至少保存:
| 字段 | 说明 |
|---|---|
agentType |
resume 时恢复原 agent 类型。fork resume 需要知道它是 fork |
worktreePath |
worktree agent resume 时恢复 cwd |
description |
notification 用原始描述 |
SendMessage 可以继续一个已 spawned subagent:
to 可以是注册过的 name,也可以是 raw agentId。pendingMessages,在下一次 tool round 边界 drain。resumeAgentBackground() 自动恢复。当前持久化边界是:session store(默认 SQLite)负责 child history 和 session state;session event store 负责运行期事件排序、live delivery 和进程内 replay。resume 从 session store 读取,不再维护第二份 transcript sidecar。
如果 Agent 的只读声明固定为 true(理由是它只负责编排,实际副作用由子 agent 调用的底层工具做权限检查),对 tool framework 方便,但对 ZCode 的审计语义不够细。
ZCode 建议拆成两层声明:
| 维度 | 建议 |
|---|---|
orchestrationReadOnly |
true,spawn 本身不直接写文件、跑命令或联网 |
effectiveReadOnly |
动态,取决于 agent tool pool、permission mode、prompt intent、isolation 和 background |
sideEffectScope |
session、workspace、git、network、system、userInteraction 的并集 |
concurrencySafe |
spawn 编排可并发,但同一 worktree/cwd 的写工具仍需由底层工具和 file locks 保护 |
destructive |
如果 agent 可用写入、shell、git 或 network tool,则应提升为潜在 destructive |
权限规则:
Agent(...) permission deny 可以禁止某个 agent type。bypassPermissions、acceptEdits 或 auto 时,子 agent 会继承该能力边界,不允许 agent definition 覆盖成更低权限。这是高风险点。bubble 或显式允许显示 prompt。AskUserQuestion 在 subagent 内默认不可用,避免子 agent 直接向用户发起交互。ZCode 的权限系统应在 spawn 前生成 SubagentPolicy 快照,记录 agent type、allowed tools、permission mode、side effect scopes、是否允许 background、是否允许 resume、是否允许 worktree 和是否允许 user prompt。
子 Agent 借用 parent MCP port 时,官方 zcode-cua 不能通过 wildcard 继承。Core 使用冻结的
official server authority 将其从 child snapshot、tool allowlist 和 SkillPort 中移除;profile
显式声明官方 CUA server、tool、selector 或 Skill 时,在 child 首次模型请求前返回
SUBAGENT_COMPUTER_USE_UNAVAILABLE。这条规则适用于 Explore、general-purpose、custom、
background 和 resume。
该过滤只改变 child 视图,不改变 parent snapshot、MCP lifecycle 或主 Agent 的官方 CUA 工具。
Producer 仍需在 runtime_scope=subagent 时拒绝所有 CUA tool call,作为不能由 tool surface 绕过的
执行期 backstop。完整契约见 docs/cua/2026-08-18-subagent-computer-use-unavailable-spec.md。
subagent 不是只跑模型和工具,还会触发扩展系统:
SubagentStart hooks 输入包含 agent_id 和 agent_type,可返回 additional context。SubagentStop 事件执行。mcpServers 设计上可在父 MCP clients 基础上 additive 合并,inline MCP client
结束时 cleanup;ZCode 当前 child 只借用 parent-owned MCP 连接,不创建 inline client。skills 会在 agent 启动时解析并预加载为 meta user message;plugin skills 可通过 bare name、plugin prefix 或 suffix match 解析。ZCode 应把 hook/MCP/skill 都视为外部 I/O 或扩展边界,必须带 trace、权限、timeout、cleanup 和 source trust。
关键失败路径:
team_name。background: true。subagent_type 不存在。subagent_type 存在但被 Agent(agentType) deny rule 禁止。<error>、runtime task error 和 SubagentStopped.payload.error;外层 Turn execution failed 只能作为 detail 保留,不能覆盖父模型或 Agent 卡片看到的失败原因。SendMessage 不会仅凭磁盘 artifact 重新发现目标。本节记录最初 Explore MVP 的收窄范围,不再代表当前完整能力:
Agent,输入包含 description、prompt、可选 subagent_type 和可选 run_in_background。subagent_type: "Explore",省略时默认 Explore。Explore 支持同步 one-shot 和 run_in_background: true 后台运行;后台完成后通过父会话 notification 进入下一轮模型请求。SendMessage。traceId,SubagentSpawned / SubagentStopped 事件写入父 session,child tool/model/turn 事件写入 child session。tool_call_scheduled / tool_call_started / tool_call_progress / tool_call_result /
tool_call_error 事件必须镜像到父 runtime 的 live event sink,供兼容消费者、运行态诊断和 telemetry 观察
Explore 内部正在运行的工具。镜像事件使用父 session id、父 turn id 和 namespaced toolCallId,
payload 保留 source: "subagent"、parentToolCallId、childSessionId、childToolCallId、
agentId、agentType 和 description。镜像事件不写入父 event store;事实来源仍是 child
session 中已经持久化的原始事件,避免把 child tool 误计为父 agent 的模型可见工具调用。source: "subagent" 的 mirrored lifecycle,不能生成父 ToolCallRow、plan
或文件摘要;child topic 仍按原始事件生成完整工具行。foreground child 的等待态由父 Agent tool
和 main turn phase 表达,background child 由 subagent manifest/background work 表达;权限、提问等
阻塞交互继续按 subagent origin 代理到父会话。桌面 continuous 与手机 replayable 使用同一投影边界。modelRef 和 modelProviderOptions。Agent tool input 不提供 invocation 级模型覆盖,避免历史 tool call 参数覆盖 Settings 或 Markdown profile 的当前配置。Glob/Grep,并通过 Bash find / grep function 承接
broad file/code search。Windows CMD 或 legacy shell fallback 无法注入 Bash function 时,
才回到 non-embedded/direct 分支并暴露 Glob/Grep。Bash、Read、WebFetch、WebSearch、TodoWrite;direct fallback branch 额外包含 Glob、Grep。它始终显式排除 Agent、Write、Edit、ApplyPatch、Skill、AskUserQuestion 等递归、写入或用户交互能力。Agent 自身声明为编排层 read-only、sideEffectScope: session、不需要审批;实际文件读取仍由 child 的 read-only tool 走各自 schema、权限和 trace。Bash 是 child tool pool 中唯一可能产生副作用的入口,其只读约束由 Explore system prompt 的 read-only 禁令和缺失文件写工具共同承担。yolo mode 和专用 Explore system prompt;plan mode 会因 Bash 非 read-only 而拦截 Explore 的只读 shell 查询,因此该阶段通过 tool allowlist 和 Explore system prompt 约束只读语义。业务代码通过 SubagentPort 调度,不直接依赖 runtime 内部实现。后台 subagent 的原始设计来源见 Background Subagent 第一版实施规划(历史)。该文档用于解释第一版 lifecycle 取舍,不覆盖本节和 RespondToCoordinator 当前契约。
该阶段规划后续增加新 agent 类型时必须先补:
AgentDefinitionRegistry 或等价契约,声明 agent type、描述、system prompt 来源、tool pool、权限边界、是否允许 background/resume/worktree/user prompt。ToolPoolResolver,把 agent 声明解析成模型可见 tool contracts,并用测试证明递归 Agent、用户交互和写入工具不会意外泄露。当前实现已经从最初 Explore MVP 扩展为 profile-backed local agent:
Agent;subagent_type 省略时默认 general-purpose,显式值通过当前 runtime 已加载的 agent profile 解析。run_in_background: true。后台任务继续使用 RuntimeTaskRegistry、child session、completion notification 和 runtime command queue,不建立第二套任务状态。SubagentPort.sendMessage 可用时注册模型可见 SendMessage;当前 profile-backed child 固定关闭 subagent 能力且不注入该 port,因此不会注册 SendMessage。若未来 child 提供该 port,tool allowlist/disallowlist 仍会继续过滤模型可见工具。general-purpose 和只读搜索用的 Explore;project/user profile 可以覆盖 system prompt、tool policy、model、permission mode、skills 和 background 设置。profile 的 tools: ["*"] 仍需经过全局 child tool filter、profile disallowedTools 和 runtime allow/disallow 规则收敛。TaskStop 可以停止当前 runtime 中已经 background 的 local_agent / local_bash;local_agent 的 result command 使用短 description,不得回退为完整 prompt。AgentProfile.source 是加载器写入的身份事实,frontmatter 不能覆盖。project/user profile 可以用
同名 Explore 覆盖内置定义,但覆盖后仍保留自己的 source。name === "Explore" && source === "built-in" 才使用内置只读 prompt、动态 Explore
tool pool、explore toolset、专用 permission service 和未显式设置 permission mode 时的 yolo。mcpServers 限定 parent MCP 可见范围;使用 main toolset,并继承普通 custom agent 的权限语义。mcpStartupPromise 保存的启动 snapshot,不在创建时重新调用 parent status() 或 listTools()。mcpServers 只接受 parent server name 字符串列表;省略或空列表表示不额外限制。非空列表按
descriptor 原始 serverName 精确限定 snapshot,只有启动时状态为 connected 的 descriptor 可见。mcp__<server>__<tool> 拆分反推 server。status() / listTools() 只回放固定 snapshot,
callTool() 委托 parent;connect、reconnect、disconnect 均拒绝,child close 不传播给 parent。这是固定启动快照语义:parent 启动后才经 OAuth 或重连出现的新 descriptor,要到 parent runtime 重建后才会进入 subagent 候选工具集。
Parent startup -> MCP snapshot -> parent registry
|
Child spawn -> scoped fixed snapshot -> provider tools -> parent.callTool
|
Child finish -> no parent MCP cleanup
to 必须是当前 runtime RuntimeTaskRegistry 中仍可寻址的 local_agent task/agent id。当前不支持名称 alias、跨 runtime 投递,也不会在 task 已从 registry evict 后仅凭磁盘 artifact 重新发现目标。steered 或 queued;没有 sink 或 sink 投递失败时进入该 task 的 pending message queue。SendMessage 复用原 child session 并在后台恢复;目标、profile 或 child session metadata 缺失时返回结构化失败。Message queued for delivery to ${to} at its next tool round.;
Agent "${to}" was stopped (${status}); resumed it in the background with your message. You'll be notified when it finishes. Output: ${outputFile}。
steered 是 ZCode 的 active-turn 扩展,保持现有独立文案。SubagentSpawned(background=true, resumed=true);V4 在同一次投影中
复用原 agentId / childSessionId 恢复 running row 和 cancellable background work,并保留原
Agent tool call 的 parentToolCallId 作为 row 展示锚点。不得用本次 SendMessage call id 覆盖,
也不得为同一次 resume 再补发 BackgroundTaskStarted;Stop 继续走现有 runtime task abort 路径。status: "success" 只表示消息已被 queued、steered 或通过 resumed_background 接受,不表示目标 agent 已读取、接受任务或回复。send_message 是独立的 session mailbox 工具,不复用 SendMessage 的 local-agent 路由、output 或 display 语义。SendMessage。SendMessage 保持 parent/main-only。running child 在当前 tool batch 结束后的合法 round 边界接收带
Message from coordinator: 标识的 steer input,不中断正在执行的单个工具或 parallel batch。taskType === "subagent_child" 且未被全局
toolDisallowlist 禁用时,child 才暴露 child-only RespondToCoordinator。Explore runtime 会在最终
allowlist 求交后补回这个 child control tool;Plan mode 通过显式 capability 放行,不把 session
mutation 伪装成 read-only。RespondToCoordinator 只把回复排入 parent runtime command queue,不结束 child 当前任务;enqueue
success 不表示 parent 已经读取、持久化或回复。<summary> / <message> carrier 以 source
subagent_message、visibility model-only 写入 parent model history 和 session store。它不进入用户
可见消息、session title 或 ReadSessionContext,但原始 session 导出、诊断、存储预算和 compact
必须按可能包含该内容处理。subagent_message 不是 SessionEventType.SubagentMessage
lifecycle/progress event,也不是 child transcript 镜像。完整契约见
Subagent RespondToCoordinator。ToolResultDisplayPayload 生成,不得反向修改模型可见结果。local_agent_message 只包含业务 status、可选 error 和可选 message;error、message 分别受 4 KiB UTF-8 预算约束。task_stop 包含 taskId、taskType、可选 command、message 和可选 truncated;command、message 分别受 16 KiB UTF-8 预算约束。tool_call_result.result.display 下发,并写入 completed tool part 的 versioned metadata,不能混入 hook additional context。docs/ui/tool-display-rendering.md;CLI TUI 的暂缓适配和验收条件记录在 Tool Change Chain 的 TODO(TUI display parity)。第一版不建议把 SubagentTool 直接写成一个巨型工具。应拆成一组稳定接口:
SubagentTool:模型可见 schema、权限入口、result serialization。AgentDefinitionRegistry:加载 built-in/project/user/plugin/policy agents,做覆盖、解析失败报告和 capability filtering。ToolPoolResolver:按 agent policy、permission mode、async/fork/team 解析可用工具。SubagentContextFactory:创建隔离的 ExecutionContext,负责 trace、abort、read cache、content replacement、app state proxy。AgentRuntime:执行 query loop,消费 message stream,触发 hooks、skills、MCP cleanup。SubagentTaskService:管理 foreground/background 状态、progress、kill、auto-background、notification。SessionStorePort:session messages/parts、session entries、resume hydration。SubagentMessageRouter:按 agentId/name 投递消息,支持 pending queue 和 stopped resume。WorktreeIsolationPort:创建、检测变更、清理和恢复 worktree。RemoteAgentPort:远程 agent eligibility、bundle、launch、status、notification。最低测试集:
subagent_type 在 fork off 时选择 general-purpose,fork on 时走 fork。AskUserQuestion、TaskOutput、递归 Agent 等。async_launched,完成后产生 task notification。SendMessage 进入 pending queue,stopped agent 可从持久化 session history resume。Agent 仍能停止等待,静默超时
需要覆盖 child 没有任何 session event 且 promise 永不 settle 的场景。traceId,并记录 parent session/turn/toolCall/span 关系。