Skip to content

fix(service-ai): yield tool-result events in streamChatWithTools SSE stream#1087

Merged
hotlong merged 3 commits intomainfrom
copilot/fix-sse-tool-result-streaming
Apr 8, 2026
Merged

fix(service-ai): yield tool-result events in streamChatWithTools SSE stream#1087
hotlong merged 3 commits intomainfrom
copilot/fix-sse-tool-result-streaming

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 8, 2026

streamChatWithTools emitted tool-call (tool-input-available) events but never yielded the corresponding tool-result — results were only pushed to the conversation array. The encoder already mapped tool-resulttool-output-available; it just was never invoked.

Changes

  • ai-service.ts: Yield each ToolExecutionResult as a tool-result stream part before appending it to the conversation
for (const tr of toolResults) {
  // ... error handling ...
  yield {
    type: 'tool-result',
    toolCallId: tr.toolCallId,
    toolName: tr.toolName,
    output: tr.output,
  } as TextStreamPart<ToolSet>;
  conversation.push({ role: 'tool', content: [tr] } as ModelMessage);
}
  • auth-and-toolcalling.test.ts: Added assertions for tool-result presence/ordering in the existing streaming test; added a dedicated test validating tool output content round-trips correctly

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectstack-play Ready Ready Preview, Comment Apr 8, 2026 9:29am
spec Ready Ready Preview, Comment Apr 8, 2026 9:29am

Request Review

…stream

Previously, streamChatWithTools only yielded tool-call events but not
tool-result events. Tool results were pushed to the conversation but
never emitted via SSE, making it impossible for the frontend to track
tool output in real-time.

Now each tool execution result is yielded as a tool-result TextStreamPart
before being appended to the conversation, which the encoder maps to
tool-output-available SSE chunks.

Agent-Logs-Url: https://github.com/objectstack-ai/framework/sessions/6af7123e-c579-4a8f-84f6-a58107c88797

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix SSE stream to yield tool-result events for AI Chat fix(service-ai): yield tool-result events in streamChatWithTools SSE stream Apr 8, 2026
Copilot AI requested a review from hotlong April 8, 2026 08:38
@hotlong hotlong marked this pull request as ready for review April 8, 2026 08:59
Copilot AI review requested due to automatic review settings April 8, 2026 08:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes AIService.streamChatWithTools() so it emits tool-result stream parts (in addition to tool-call) during SSE-style streaming, enabling clients to receive tool outputs as they become available.

Changes:

  • Yield tool-result events for each executed tool before appending the tool message back into the conversation loop.
  • Extend streaming tests to assert tool-result presence and validate that tool output content round-trips correctly.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/services/service-ai/src/ai-service.ts Emits tool-result stream parts during the tool-resolution loop so tool outputs are visible to SSE clients.
packages/services/service-ai/src/tests/auth-and-toolcalling.test.ts Adds assertions for tool-result events and introduces a dedicated test verifying tool output and event ordering.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions github-actions bot added the tests label Apr 8, 2026
@hotlong hotlong merged commit 5d3b3bb into main Apr 8, 2026
7 of 9 checks passed
@github-actions github-actions bot added the size/s label Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants