Skip to content

fix(web-search): handle xAI Responses API format in Grok provider#13547

Merged
steipete merged 1 commit intoopenclaw:mainfrom
0xRaini:fix/grok-web-search-response-format
Feb 11, 2026
Merged

fix(web-search): handle xAI Responses API format in Grok provider#13547
steipete merged 1 commit intoopenclaw:mainfrom
0xRaini:fix/grok-web-search-response-format

Conversation

@0xRaini
Copy link
Copy Markdown
Contributor

@0xRaini 0xRaini commented Feb 10, 2026

Problem

The Grok web_search provider returns "No response" when the xAI API uses its newer /v1/responses format.

Root Cause

The xAI Responses API returns output blocks with type: 'message' containing content blocks with type: 'output_text' and url_citation annotations. The previous code checked output[0].content[0].text without type filtering, which could fail with multiple output entries.

Fix

  • Filter output blocks by type='message' and content by type='output_text'
  • Extract url_citation annotations as fallback citations
  • Deduplicate annotation-derived URLs
  • Update GrokSearchResponse type to include annotation fields

Tests

All 26 web-search tests pass, including 4 new/updated tests for Grok response parsing.

Closes #13520

Greptile Overview

Greptile Summary

This change updates the Grok (grok) web_search provider to correctly parse xAI /v1/responses output by selecting output blocks with type: "message" and content blocks with type: "output_text", and adds a fallback path that extracts url_citation annotation URLs when top-level citations are absent. Unit tests were updated/added to cover message-block parsing, annotation citation extraction (including deduplication), and deprecated output_text fallback.

The parsing logic lives in src/agents/tools/web-search.ts and is exercised via the __testing.extractGrokContent export in src/agents/tools/web-search.test.ts.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk.
  • Changes are narrowly scoped to Grok response parsing, keep backwards compatibility via the deprecated output_text fallback, and are covered by focused unit tests. No broken call sites were found beyond the updated usage in runGrokSearch.
  • No files require special attention

The xAI /v1/responses API returns content in a structured format with
typed output blocks (type: 'message') containing typed content blocks
(type: 'output_text') and url_citation annotations. The previous code
only checked output[0].content[0].text without filtering by type,
which could miss content in responses with multiple output entries.

Changes:
- Update GrokSearchResponse type to include annotations on content blocks
- Filter output blocks by type='message' and content by type='output_text'
- Extract url_citation annotations as fallback citations when top-level
  citations array is empty
- Deduplicate annotation-derived citation URLs
- Update tests for the new structured return type

Closes #13520
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@openclaw-barnacle openclaw-barnacle bot added the agents Agent runtime and tooling label Feb 10, 2026
@0xRaini

This comment was marked as spam.

@0xRaini

This comment was marked as spam.

@steipete steipete merged commit 27453f5 into openclaw:main Feb 11, 2026
24 of 25 checks passed
@steipete
Copy link
Copy Markdown
Contributor

Landed via temp rebase onto main.

  • Gate: pnpm build && pnpm check && pnpm test
  • Land commit: f1719de
  • Merge commit: 27453f5

Thanks @0xRaini!

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

Labels

agents Agent runtime and tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(web-search): Grok provider returns 'No response' due to response format mismatch

2 participants