fix: enable xAI Responses native web search - #9728
Open
wcqqq1214 wants to merge 5 commits into
Open
Conversation
wcqqq1214
marked this pull request as ready for review
August 18, 2026 08:36
Contributor
Author
|
@sourcery-ai review |
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
_query/_query_stream,tool_choiceis only set when function tools are present, so xAI-nativeweb_searchalone will not get an explicittool_choice; consider whether you want to forcetool_choice='auto'whenever any tools (includingweb_search) are sent. - Handling of the
web_search_sourceschain type is currently scattered acrosschat_service,live_chat_service,open_api_service, andastr_agent_run_util; consider centralizing this parsing/forwarding logic to a shared helper to reduce duplication and keep behavior consistent across channels.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `_query`/`_query_stream`, `tool_choice` is only set when function tools are present, so xAI-native `web_search` alone will not get an explicit `tool_choice`; consider whether you want to force `tool_choice='auto'` whenever any tools (including `web_search`) are sent.
- Handling of the `web_search_sources` chain type is currently scattered across `chat_service`, `live_chat_service`, `open_api_service`, and `astr_agent_run_util`; consider centralizing this parsing/forwarding logic to a shared helper to reduce duplication and keep behavior consistent across channels.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9723.
This PR restores the xAI native-search toggle for
openai_responsesprovider sources, injects theweb_searchtool into Responses API requests, and surfaces xAIurl_citationsources as WebChat source cards.Modifications / 改动点
Expose the xAI native-search toggle for
openai_responsesprovider sources and keep it disabled by default.Backfill the disabled toggle in the Dashboard when editing existing xAI provider sources that predate the setting.
Add xAI's
web_searchtool to both streaming and non-streaming Responses API requests when the toggle is enabled, while preserving AstrBot function tools.Extract xAI
url_citationannotations intoLLMResponse.web_search_sourcesand carry them through the agent runner into the WebChat refs pipeline (chat / live-chat / OpenAPI consumers), rendering them as the existing clickable source cards.Update the English and Chinese configuration hints to describe xAI native Web Search rather than the legacy Chat Completions-only behavior.
This is NOT a breaking change. / 这不是一个破坏性变更。
Verification Steps / 验证步骤
vue-tsc --noEmit.xai_native_searchdisplays the toggle as disabled by default; enabled it, saved it, reloaded the page, and confirmed the setting persisted.grok-4.5, without an official xAI API key. The outgoing payload included{"type":"web_search"}, and the model returned current news with a source URL.grok-4.5model and received a current international-news result with a source URL.web_search_call+url_citation): the sources were parsed and shown as WebChat source cards in both streaming and non-streaming paths.Screenshots or Test Results / 运行截图或测试结果
1. Dashboard configuration
2. End-to-end WebChat result
This request uses Grok's native
web_searchtool through the Responses API. No AstrBot web-search plugin, function tool, or external search provider was configured.3. Citation card via a local mock of the official xAI Responses shape
The mock returns the official xAI
web_search_call+url_citationshape. Because OpenCode Go strips citation metadata, the source-card rendering is validated against the mock rather than a live provider; an official xAI API re-check is recommended.Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Enable optional xAI native Web Search in Responses API requests and surface its citations throughout WebChat.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: