Skip to content

Conversation

@archodev
Copy link

@archodev archodev commented Dec 31, 2025

Problem

When using xai.tools.webSearch() with xai.responses() and streamText, tool-call events are emitted with empty toolName, causing AI_NoSuchToolError.

Example of the error:

{
  "type": "tool-call",
  "toolCallId": "ws_24e5ff31-0c00-48c9-c980-671b70dd254e_call_48407951",
  "toolName": "",
  "invalid": true,
  "error": {
    "name": "AI_NoSuchToolError",
    "toolName": "",
    "availableTools": ["web_search"]
  }
}

Root Cause

In xai-responses-language-model.ts, the code maps part.name to the user's tool name, but only checks if part.name matches specific sub-tool names like web_search, browse_page, etc.

When xAI returns web_search_call events, part.name may be undefined or empty, so the mapping fails and toolName remains an empty string.

Solution

Check part.type in addition to part.name to correctly identify server-side tools:

  • web_search_callwebSearchToolName
  • x_search_callxSearchToolName
  • code_execution_call / code_interpreter_callcodeExecutionToolName
  • view_image_callview_image
  • view_x_video_callview_x_video

Changes

  • Fixed tool name mapping in both doGenerate and doStream methods
  • Added 5 test cases to verify correct mapping when part.name is empty

Testing

  • All 120 existing tests pass
  • Added new tests for empty part.name scenarios
  • Verified fix with real xAI API calls using streamText with xai.tools.webSearch()

Fixes #11263

When xAI returns web_search_call, x_search_call, or other server-side tool
events, the part.name field may be empty or undefined. Previously, this caused
AI_NoSuchToolError because the toolName was set to empty string.

This fix checks part.type in addition to part.name to correctly map the tool
call back to the user-provided tool name from the tools object.

Amp-Thread-ID: https://ampcode.com/threads/T-019b7693-d38e-77a1-8e71-def855e6e22d
Co-authored-by: Amp <[email protected]>
@aayush-kapoor
Copy link
Contributor

hi marking this as closed since this has been fixed via #11530

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Grok agentic mode tries to call unavailable tool (v6 beta)

2 participants