Skip to content

[BUG] Task tool subagent output silently truncated/missing when conversation ends with tool_use #32131

Description

@smithyyang

描述

Task tool(子 agent)的输出会被静默截断。子 agent 标记自己 completed,但实际返回给父 agent 的内容不完整甚至是空的。输出远未达到 50KB/2000 行的限制。

复现步骤

  1. 使用主 agent 调用 task(subagent_type="explore", prompt="...")
  2. 子 agent 执行任务并生成响应
  3. 子 agent 标记为 completed
  4. 父 agent 收到的输出被截断或缺失

根本原因分析

packages/opencode/src/tool/task.ts:199:

return result.parts.findLast((item) => item.type === "text")?.text ?? ""

这行代码只取最后一条 text 类型的 part。如果子 agent 的对话以 tool_use block 结尾(而非纯文本),或者 text 和 tool_use 交错出现,那么 text 内容就会丢失。findLast 之前的 text 可能携带了关键结果。

此外 renderOutput(:64-79)只在 text 存在时将其包裹在 <task_result> 中——如果 text 为空,父 agent 看到的只是一个空的 task_result 标签。

预期行为

Task tool 应该收集子 agent 的完整对话输出(所有 text parts),而不仅仅是最后一条。或者至少应该拼接所有 text parts。

类似问题

环境

  • opencode 版本: current
  • 平台: linux
  • 子 agent 类型: explore / general

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions