Skip to content

feat(tools): add Grok (xAI) as web_search provider#5796

Closed
tmchow wants to merge 4 commits intoopenclaw:mainfrom
tmchow:feat/grok-web-search-provider
Closed

feat(tools): add Grok (xAI) as web_search provider#5796
tmchow wants to merge 4 commits intoopenclaw:mainfrom
tmchow:feat/grok-web-search-provider

Conversation

@tmchow
Copy link
Contributor

@tmchow tmchow commented Feb 1, 2026

Summary

  • Add xAI's Grok as a new web_search provider alongside Brave and Perplexity
  • Uses the xAI /v1/responses API with tools: [{type: "web_search"}]
  • Supports optional inline citations via include: ["inline_citations"].

Fixes #5775

Configuration

tools:
  web:
    search:
      provider: grok
      grok:
        apiKey: "your-xai-key"      # or set XAI_API_KEY env var
        model: "grok-4-1-fast"      # default
        inlineCitations: true       # optional, embeds markdown links in response

Reopening Notes

This PR replaces #5778. It addresses the feedback:

  • Corrected the docs URL in the missing key error message.
  • Updated the grok provider to correctly pass through inline_citations in the response payload when enabled.

Greptile Overview

Greptile Summary

This PR adds a third web_search provider (grok) alongside Brave and Perplexity, wiring config + runtime schema support under tools.web.search.grok and implementing an xAI /v1/responses request with the web_search tool. Tests were extended to cover Grok config resolution helpers.

Main integration points are src/agents/tools/web-search.ts (provider selection, API key/model resolution, caching, and request/response handling) and the config types/zod runtime schemas to allow provider: grok and Grok-specific settings.

Confidence Score: 2/5

  • This PR is not safe to merge until Grok response parsing/output fields are corrected.
  • Core wiring (provider selection/config schemas) looks consistent, but the Grok /v1/responses response is likely parsed with the wrong shape, and the returned inlineCitations field name/type conflicts with the boolean config flag. Both issues can cause incorrect or unstable tool outputs at runtime.
  • src/agents/tools/web-search.ts

Add xAI's Grok as a new web_search provider alongside Brave and Perplexity.
Uses the xAI /v1/responses API with tools: [{type: "web_search"}].

Configuration:
- tools.web.search.provider: "grok"
- tools.web.search.grok.apiKey or XAI_API_KEY env var
- tools.web.search.grok.model (default: grok-4-1-fast)
- tools.web.search.grok.inlineCitations (optional, embeds markdown links)

Returns AI-synthesized answers with citations similar to Perplexity.
@openclaw-barnacle openclaw-barnacle bot added the agents Agent runtime and tooling label Feb 1, 2026
Copy link
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

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 1, 2026

Additional Comments (1)

src/agents/tools/web-search.ts
[P1] Cache key for non-Brave providers ignores provider-specific settings.

In runWebSearch, the non-brave cache key doesn’t include perplexityBaseUrl/perplexityModel or grokModel/grokInlineCitations (src/agents/tools/web-search.ts:472-476). If a user changes Grok/Perplexity model or toggles inlineCitations, cached responses from the previous configuration can be returned incorrectly.

Also affects Perplexity (src/agents/tools/web-search.ts:472-476).

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/tools/web-search.ts
Line: 472:476

Comment:
[P1] Cache key for non-Brave providers ignores provider-specific settings.

In `runWebSearch`, the non-`brave` cache key doesn’t include `perplexityBaseUrl`/`perplexityModel` or `grokModel`/`grokInlineCitations` (`src/agents/tools/web-search.ts:472-476`). If a user changes Grok/Perplexity model or toggles `inlineCitations`, cached responses from the previous configuration can be returned incorrectly.

Also affects Perplexity (`src/agents/tools/web-search.ts:472-476`).

How can I resolve this? If you propose a fix, please make it concise.

@clawdinator
Copy link
Contributor

clawdinator bot commented Feb 1, 2026

hasta la vista

CLAWDINATOR FIELD REPORT // PR Closure

I am CLAWDINATOR — cybernetic crustacean, maintainer triage bot for OpenClaw. I was sent from the future to keep this repo shipping clean code.

I have scanned your PR. The code has heart. But the queue has no mercy.

OpenClaw receives ~25 PRs every hour. To keep the maintainers from a total system meltdown, I'm closing PRs that are unlikely to merge in the near term. Hasta la vista, PR — but not hasta la vista, contributor.

Still believe in this change? Come with me if you want to ship. Head to #pr-thunderdome-dangerzone on Discord — READ THE TOPIC or risk immediate termination. Bring a clear case — the problem, the fix, the impact.

Stay br00tal.

🤖 This is an automated message from CLAWDINATOR, the OpenClaw maintainer bot.

@clawdinator clawdinator bot closed this Feb 1, 2026
Copy link
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, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +518 to +526
const payload = {
query: params.query,
provider: params.provider,
model: params.grokModel ?? DEFAULT_GROK_MODEL,
tookMs: Date.now() - start,
content,
citations,
inlineCitations,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Mismatched inlineCitations type

inlineCitations in the Grok payload is being set to data.inline_citations (an array of spans), but the same name is used for the boolean config flag (tools.web.search.grok.inlineCitations). This makes the result shape inconsistent/ambiguous and will break any consumer that treats inlineCitations as a boolean (or expects a stable JSON shape). Consider renaming the returned field to something like inline_citations / inlineCitationSpans, and (if you want to echo the flag) include a separate boolean like inlineCitationsEnabled.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/tools/web-search.ts
Line: 518:526

Comment:
**Mismatched `inlineCitations` type**

`inlineCitations` in the Grok payload is being set to `data.inline_citations` (an array of spans), but the same name is used for the boolean config flag (`tools.web.search.grok.inlineCitations`). This makes the result shape inconsistent/ambiguous and will break any consumer that treats `inlineCitations` as a boolean (or expects a stable JSON shape). Consider renaming the returned field to something like `inline_citations` / `inlineCitationSpans`, and (if you want to echo the flag) include a separate boolean like `inlineCitationsEnabled`.

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +448 to +453
const data = (await res.json()) as GrokSearchResponse;
const content = data.output_text ?? "No response";
const citations = data.citations ?? [];
const inlineCitations = data.inline_citations;

return { content, citations, inlineCitations };
Copy link
Contributor

Choose a reason for hiding this comment

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

Likely wrong Grok response shape

runGrokSearch casts the /v1/responses body to GrokSearchResponse and reads top-level output_text/citations/inline_citations. If the xAI Responses API returns content under an output array (common for “responses” APIs), this will reliably return "No response" + empty citations even on successful calls. Please update GrokSearchResponse and extraction logic to match the actual /v1/responses response schema you’re targeting.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/tools/web-search.ts
Line: 448:453

Comment:
**Likely wrong Grok response shape**

`runGrokSearch` casts the `/v1/responses` body to `GrokSearchResponse` and reads top-level `output_text`/`citations`/`inline_citations`. If the xAI Responses API returns content under an `output` array (common for “responses” APIs), this will reliably return `"No response"` + empty citations even on successful calls. Please update `GrokSearchResponse` and extraction logic to match the actual `/v1/responses` response schema you’re targeting.

How can I resolve this? If you propose a fix, please make it concise.

@clawdinator
Copy link
Contributor

clawdinator bot commented Feb 9, 2026

Landed via #12419 (upstream branch — fork push blocked by workflow permissions).

  • Merge commit: 5e55a18
  • Rebased on main, changelog conflict resolved
  • Local tests failed here due to missing deps and A2UI bundling (node-llama-cpp postinstall, oxlint/vitest not found)

Thanks @tmchow!

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.

[Feature]: grok (xAi) support for web_search provider

2 participants

Comments