Skip to content

fix(tools): correct Grok response parsing for xAI Responses API#13049

Merged
Takhoffman merged 2 commits intoopenclaw:mainfrom
ereid7:fix-grok-response-parsing
Feb 10, 2026
Merged

fix(tools): correct Grok response parsing for xAI Responses API#13049
Takhoffman merged 2 commits intoopenclaw:mainfrom
ereid7:fix-grok-response-parsing

Conversation

@ereid7
Copy link
Copy Markdown
Contributor

@ereid7 ereid7 commented Feb 10, 2026

Summary

Grok web_search provider returns "No response" for all queries because the response parsing code expects "output_text" field, but xAI's Responses API returns content in "output[0].content[0].text".

Changes

  • Updated "GrokSearchResponse" type to match actual xAI API response structure
  • Fixed "runGrokSearch" to extract content from the correct path: "output[0].content[0].text"
  • Kept backwards compatibility with "output_text" field (optional fallback)

Testing

Verified fix works with live xAI API:

  • Query: "what is the capital of France"
  • Result: "Paris is the capital of France..."

Related

Fixes bug introduced in PR #12419

Checklist

  • Bug fix (non-breaking change which fixes an issue)
  • Code follows project style guidelines
  • Change is backwards compatible
  • Tested with live API

Greptile Overview

Greptile Summary

This PR extends web_search to support Grok (xAI) and fixes Grok parsing by reading the xAI Responses API’s output[0].content[0].text (with a fallback to the legacy output_text field). It also adds Grok config resolution helpers (apiKey/model/inline citations), updates the tools config types + runtime zod schema to accept provider: "grok" and a tools.web.search.grok config block, and adds unit tests for the new Grok config resolution behavior.

Confidence Score: 4/5

  • Mostly safe to merge, but there is a concrete sanitization inconsistency for Grok output that should be fixed first.
  • Core change is a narrow parsing fix plus config/schema updates, and it aligns with the stated xAI Responses API structure. However, Grok’s content is returned without wrapWebContent(...) unlike the other providers, which can bypass existing external-content handling and affect downstream rendering/consumption.
  • src/agents/tools/web-search.ts

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

Context used:

  • Context from dashboard - CLAUDE.md (source)
  • Context from dashboard - AGENTS.md (source)

@openclaw-barnacle openclaw-barnacle bot added the agents Agent runtime and tooling label Feb 10, 2026
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@ereid7 ereid7 force-pushed the fix-grok-response-parsing branch from d372868 to 725d354 Compare February 10, 2026 02:54
@ereid7
Copy link
Copy Markdown
Contributor Author

ereid7 commented Feb 10, 2026

@tmchow

erai and others added 2 commits February 9, 2026 21:37
The xAI Responses API returns content in output[0].content[0].text,
not in output_text field. Updated GrokSearchResponse type and
runGrokSearch to extract content from the correct path.

Fixes the 'No response' issue when using Grok web search.
@Takhoffman Takhoffman force-pushed the fix-grok-response-parsing branch from 42e59ba to 07a429e Compare February 10, 2026 03:46
@Takhoffman Takhoffman merged commit 0c7bc30 into openclaw:main Feb 10, 2026
23 checks passed
@Takhoffman
Copy link
Copy Markdown
Contributor

Merged via squash.

Thanks @ereid7!

lucasmpramos pushed a commit to butley/openclaw that referenced this pull request Feb 10, 2026
…claw#13049)

* fix(tools): correct Grok response parsing for xAI Responses API

The xAI Responses API returns content in output[0].content[0].text,
not in output_text field. Updated GrokSearchResponse type and
runGrokSearch to extract content from the correct path.

Fixes the 'No response' issue when using Grok web search.

* fix(tools): harden Grok web_search parsing (openclaw#13049) (thanks @ereid7)

---------

Co-authored-by: erai <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
ProgramCaiCai pushed a commit to ProgramCaiCai/openclaw that referenced this pull request Feb 10, 2026
…claw#13049)

* fix(tools): correct Grok response parsing for xAI Responses API

The xAI Responses API returns content in output[0].content[0].text,
not in output_text field. Updated GrokSearchResponse type and
runGrokSearch to extract content from the correct path.

Fixes the 'No response' issue when using Grok web search.

* fix(tools): harden Grok web_search parsing (openclaw#13049) (thanks @ereid7)

---------

Co-authored-by: erai <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
YanHaidao added a commit to YanHaidao/clawdbot that referenced this pull request Feb 10, 2026
* 'main' of github.com:YanHaidao/clawdbot: (94 commits)
  fix(auto-reply): prevent sender spoofing in group prompts
  Discord: add exec approval cleanup option (openclaw#13205)
  CI: extend stale timelines to be contributor-friendly (openclaw#13209)
  fix: enforce Discord agent component DM auth (openclaw#11254) (thanks @thedudeabidesai)
  refactor(security,config): split oversized files (openclaw#13182)
  Commands: add commands.allowFrom config
  CI: configure stale automation
  fix(signal): enforce mention gating for group messages (openclaw#13124)
  fix(ui): prioritize displayName over label in webchat session picker (openclaw#13108)
  Chore: add testflight auto-response
  Docker: include A2UI sources for bundle (openclaw#13114)
  fix: unify session maintenance and cron run pruning (openclaw#13083)
  docs: expand vulnerability reporting guidelines in SECURITY.md
  docs: add vulnerability reporting guidelines to CONTRIBUTING.md
  refactor: consolidate fetchWithTimeout into shared utility
  fix(memory): default batch embeddings to off
  Improve code analyzer for independent packages, CI: only run release-check on push to main
  fix(tools): correct Grok response parsing for xAI Responses API (openclaw#13049)
  chore(deps): update dependencies, remove hono pinning
  Update contributing, deduplicate more functions
  ...
Hansen1018 pushed a commit to Hansen1018/openclaw that referenced this pull request Feb 10, 2026
…claw#13049)

* fix(tools): correct Grok response parsing for xAI Responses API

The xAI Responses API returns content in output[0].content[0].text,
not in output_text field. Updated GrokSearchResponse type and
runGrokSearch to extract content from the correct path.

Fixes the 'No response' issue when using Grok web search.

* fix(tools): harden Grok web_search parsing (openclaw#13049) (thanks @ereid7)

---------

Co-authored-by: erai <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
michaelleone pushed a commit to michaelleone/openclaw that referenced this pull request Feb 11, 2026
…claw#13049)

* fix(tools): correct Grok response parsing for xAI Responses API

The xAI Responses API returns content in output[0].content[0].text,
not in output_text field. Updated GrokSearchResponse type and
runGrokSearch to extract content from the correct path.

Fixes the 'No response' issue when using Grok web search.

* fix(tools): harden Grok web_search parsing (openclaw#13049) (thanks @ereid7)

---------

Co-authored-by: erai <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
skyhawk14 pushed a commit to skyhawk14/openclaw that referenced this pull request Feb 13, 2026
…claw#13049)

* fix(tools): correct Grok response parsing for xAI Responses API

The xAI Responses API returns content in output[0].content[0].text,
not in output_text field. Updated GrokSearchResponse type and
runGrokSearch to extract content from the correct path.

Fixes the 'No response' issue when using Grok web search.

* fix(tools): harden Grok web_search parsing (openclaw#13049) (thanks @ereid7)

---------

Co-authored-by: erai <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…claw#13049)

* fix(tools): correct Grok response parsing for xAI Responses API

The xAI Responses API returns content in output[0].content[0].text,
not in output_text field. Updated GrokSearchResponse type and
runGrokSearch to extract content from the correct path.

Fixes the 'No response' issue when using Grok web search.

* fix(tools): harden Grok web_search parsing (openclaw#13049) (thanks @ereid7)

---------

Co-authored-by: erai <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
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.

2 participants