Sub-agent 和 multi-agent:
什么时候拆,context 怎么传?
先弄清楚:每个概念是什么
- Sub-agent
- 主 agent 派出去的另一个 agent,context 从空白开始。像把事情交给没开过会的同事,他只知道你写给他的那张纸,这张纸就是 brief。
- Planner 和 worker
- planner 拆任务和分任务,worker 是干活的 sub-agent。
- 确定性代码
- 不调 LLM 的普通程序逻辑。计数、停止条件、哪个结果留下,都写在这里。
看图:planner 分任务,确定性代码收结果
30 秒回答
I split in three cases: the subtasks are independent, one context can't hold all the tool output, or the judge must be separate from the author. A sub-agent starts with an empty context, so the brief has to carry the goal, the constraints, what's been tried and the output format. It returns a summary with evidence, not its whole transcript, and deterministic code decides what to keep. The cost is more total tokens and coordination overhead, and tasks with serial dependencies get slower when split, so I don't split those.
什么时候拆,代价是什么
| 情况 | 拆不拆 | 原因 |
|---|---|---|
| 子任务互相独立,比如并行试几种 kernel 写法 | 拆 | 并行能省 wall time |
| 一个 context 装不下全部 tool 输出 | 拆 | worker 自己消化原始输出,只交回结论 |
| 评审要和作者分开 | 拆 | 同一个 agent 既写码又评判,是一篇 workshop 论文归纳的五类失败之一 |
| 步骤之间有串行依赖 | 不拆 | 每次交接多一份 brief 和一次摘要,更慢,还会丢信息 |
总 token 更多,是因为每个 worker 都要重新读一遍背景。下面的数字是举例。4 个独立子任务各要 10 分钟,串行是 40 分钟,并行约 10 分钟再加写 brief 和汇总的时间。单个 agent 做完要 60K token,4 个 worker 各用 30K 就是 120K,时间省了,token 翻倍。
Brief 写什么。目标、约束、已经试过的、输出格式,用固定模板逐项填。大段材料给文件路径,让 sub-agent 自己读,不靠主 agent 转述。
同类系统怎么编排
| 系统 | 做法 |
|---|---|
| KernelFalcon | 控制流写在确定性的 Python 里;默认 4 个并行 worker,各自保留 error context,第一个通过的胜出 |
| Cursor × NVIDIA | planner 给 worker 分配并重新平衡任务;协调协议是一个 markdown 文件 |
| KernelArc | 按策略分工的并行 agent,每个只改自己的 solution 目录;计数、停止条件、重启都在确定性代码里 |
| KDA | Claude Code 实现,Codex 每轮 review |
| FlashVector | 单链循环,每轮随机抽一层,只做一个改动;并行度论文没写 |
必答点
- 三种情况才拆:子任务独立、一个 context 装不下、评审要和作者分开
- 代价:总 token 更多,协调有开销,有串行依赖的拆了更慢
- sub-agent 从空 context 开始,brief 要带目标、约束、已经试过的、输出格式
- 返回结论和证据,不返回整段 transcript
- planner 分任务,worker 并行,由确定性代码收结果
追问
sub-agent 的结果都对,主 agent 汇总时出了幻觉,怎么办?(蔚来原题)
让 sub-agent 按固定格式返回结论和证据,由确定性代码合并,主 agent 不凭印象重写。
两个 worker 要改同一个文件怎么办?
每个 worker 用自己的 workspace,别人的成果只读。合并时的覆写问题见 edit tool 的 hash 检查。
来源面经原帖:阿里边缘 BU 一面、蔚来二面 · KernelFalcon · Cursor × NVIDIA · KernelArc · FlashVector Algorithm 1、§6 · KDA · GeCoIn 2026 workshop 论文(五类失败) · ml-八股 08 第 38 题 · 同类系统对照表