Skip to content

[AI Service][SSE] streamChatWithTools 未 yield tool-result,导致前端无法获取 tool 输出 #1086

@hotlong

Description

@hotlong

问题概述

在使用 data_chat agent 的 AI Chat 流程下,tool 调用虽然被正常触发,但 SSE 流程里 缺失 tool-result (tool-output-available) 事件,前端无法获得 tool 返回的原始输出。这样的现象会严重影响调试、UI 展示、以及开发者理解 agent/AI 工作路径。

复现步骤

  1. 打开 AI Chat(如 Studio)
  2. 输入如"系统中有哪些对象?"等会触发 list_objects tool 的问题
  3. 检查开发者工具的 SSE/log:
    • 只看到 tool-input-available (tool-call)
    • 没有对应的 tool-output-available (tool-result)
    • AI 回复中只能看到 model 生成的 summary,无法显示 tool 的原始输出

期望

  • tool 调用必须在 SSE stream 中 yieldtool-result 类型事件(编码为 tool-output-available
  • 保证前端、测试等环节可以基于流式消息实时跟踪 tool 响应内容

分析与建议

  • 当前 streamChatWithTools() 实现中,仅有 tool-call 有 yield,但 tool-result 只是推进 conversation:
    // 当前行为
    for (const tr of toolResults) {
      ...
      conversation.push({role: 'tool', content: [tr]});
    }
    应修改为:
    for (const tr of toolResults) {
      yield { type: 'tool-result', ... } as TextStreamPart;
      conversation.push({role: 'tool', content: [tr]});
    }
    并确保编码为 tool-output-available 的 SSE chunk

影响

  • 所有基于 Vercel AI SDK Data Stream Protocol (SSE) 的客户端、调试器、以及自动化测试

参考


@hotlong 需讨论最佳处理 timing & 兼容策略。

Metadata

Metadata

Labels

bugSomething isn't workingtooling

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions