Skip to content

fix(xai): emit tool-result for all provider-executed tools in Responses stream#13220

Open
giulio-leone wants to merge 1 commit intovercel:mainfrom
giulio-leone:fix/xai-provider-tool-result-emission
Open

fix(xai): emit tool-result for all provider-executed tools in Responses stream#13220
giulio-leone wants to merge 1 commit intovercel:mainfrom
giulio-leone:fix/xai-provider-tool-result-emission

Conversation

@giulio-leone
Copy link

Summary

Fixes #13218 — Provider-executed tools (web_search, x_search, code_execution, etc.) in the xAI Responses API never emit tool-result when they complete, so UIs stay stuck on the 'in progress' state.

Root Cause

The doStream handler for response.output_item.done only emits tool-result for file_search_call but skips all other provider-executed tool types (web_search_call, x_search_call, code_interpreter_call, code_execution_call, view_image_call, view_x_video_call, custom_tool_call, mcp_call).

Similarly, the non-streaming doGenerate handler pushes tool-call but not tool-result for these tool types.

Fix

Extended both streaming and non-streaming handlers to emit tool-result for all provider-executed tool types, following the same pattern already used for file_search_call.

Streaming (doStream): Added tool-result emission on response.output_item.done events for all provider-executed tool types in the shared handler block.

Non-streaming (doGenerate): Added tool-result push after tool-call for all provider-executed tool types.

Testing

  • Updated 6 existing doGenerate tests to verify tool-result is now emitted alongside tool-call for provider-executed tools
  • Updated 5 snapshot tests to include the new tool-result entries
  • Added 3 new streaming tests:
    • should stream web_search tool call and result — verifies tool-result on response.output_item.done
    • should stream code_execution tool call and result — verifies tool-result for code_execution_call
    • should stream custom_tool_call and result — verifies tool-result for custom_tool_call (used by x_search sub-tools)
  • All 56 tests pass

…es stream

Provider-executed tools like web_search, x_search, and code_execution
never emitted tool-result chunks on completion, causing UIs to stay
stuck on "in progress" state. Follow the existing file_search_call
pattern to emit tool-result with providerExecuted: true for all
provider-executed tool types.

Fixes vercel#13218
@tigent tigent bot added ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/xai labels Mar 8, 2026
@giulio-leone
Copy link
Author

Friendly ping — CI is green, tests pass, rebased on latest main. Ready for review whenever convenient. Happy to address any feedback. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/xai

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provider-executed tools (e.g. web_search) never emit tool-result in stream, so UI stays on "input-available"

1 participant