Skip to content

fix: enable xAI Responses native web search - #9728

Open
wcqqq1214 wants to merge 5 commits into
AstrBotDevs:masterfrom
wcqqq1214:fix/9723-xai-responses-web-search
Open

fix: enable xAI Responses native web search#9728
wcqqq1214 wants to merge 5 commits into
AstrBotDevs:masterfrom
wcqqq1214:fix/9723-xai-responses-web-search

Conversation

@wcqqq1214

@wcqqq1214 wcqqq1214 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Fixes #9723.

This PR restores the xAI native-search toggle for openai_responses provider sources, injects the web_search tool into Responses API requests, and surfaces xAI url_citation sources as WebChat source cards.

Modifications / 改动点

  • Expose the xAI native-search toggle for openai_responses provider 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_search tool to both streaming and non-streaming Responses API requests when the toggle is enabled, while preserving AstrBot function tools.

  • Extract xAI url_citation annotations into LLMResponse.web_search_sources and 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 / 验证步骤

  1. Ran Ruff lint and format checks for the changed Python files.
  2. Built the Dashboard successfully, including vue-tsc --noEmit.
  3. Started an isolated AstrBot instance and opened the real Dashboard in a browser.
  4. Verified that an existing xAI provider source without xai_native_search displays the toggle as disabled by default; enabled it, saved it, reloaded the page, and confirmed the setting persisted.
  5. Validated both streaming and non-streaming requests through OpenCode Go's Responses-compatible endpoint using 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.
  6. Repeated the final end-to-end Dashboard chat flow using the configured grok-4.5 model and received a current international-news result with a source URL.
  7. Validated citation rendering against a local mock of the official xAI Responses web-search shape (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

Screenshot 2026-08-18 at 16 09 18

2. End-to-end WebChat result

Screenshot 2026-08-18 at 15 56 26

This request uses Grok's native web_search tool 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

Screenshot 2026-08-18 at 22 40 43

The mock returns the official xAI web_search_call + url_citation shape. 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.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.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:

  • Enable optional native xAI Web Search for Responses API provider sources.
  • Expose xAI citation URLs as clickable WebChat source cards across chat, live-chat, and OpenAPI consumers.

Bug Fixes:

  • Restore the xAI native-search setting for Responses API sources and default it safely for existing configurations.

Enhancements:

  • Preserve existing AstrBot function tools alongside the native xAI search tool and propagate structured search references through agent responses.

Documentation:

  • Update English and Chinese configuration guidance to describe xAI native Web Search.

Tests:

  • Update provider template coverage for the default xAI native-search setting.

@wcqqq1214
wcqqq1214 marked this pull request as ready for review August 18, 2026 08:36
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. area:webui The bug / feature is about webui(dashboard) of astrbot. labels Aug 18, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Aug 18, 2026
@wcqqq1214

Copy link
Copy Markdown
Contributor Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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

Labels

area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. area:webui The bug / feature is about webui(dashboard) of astrbot. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] xAI Responses provider does not expose or send the native web_search tool.

1 participant