Skip to content

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

Merged
clawdinator[bot] merged 4 commits intomainfrom
landpr/5796
Feb 9, 2026
Merged

feat(tools): add Grok (xAI) as web_search provider#12419
clawdinator[bot] merged 4 commits intomainfrom
landpr/5796

Conversation

@clawdinator
Copy link
Contributor

@clawdinator clawdinator bot commented Feb 9, 2026

Lands #5796 from upstream branch (fork push blocked by workflow permissions).

Original PR: #5796 by @tmchow

  • Adds Grok provider for web_search (xAI /v1/responses + web_search tool)
  • Config + schema support (apiKey/model/inlineCitations)
  • Tests updated
  • Changelog entry added

Co-authored-by: Trevin Chow [email protected]

Greptile Overview

Greptile Summary

This PR adds a new web_search provider option, grok (xAI), including config/schema surface (tools.web.search.grok) and resolution helpers in src/agents/tools/web-search.ts, plus unit tests for the new config resolution helpers. It also documents the addition in CHANGELOG.md.

Within the tools system, createWebSearchTool now selects between Brave, Perplexity, and Grok at runtime, resolves the appropriate API key (config/env), and routes execution to a new runGrokSearch implementation that calls xAI’s /v1/responses endpoint with the web_search tool enabled.

Confidence Score: 4/5

  • This PR is close to mergeable, but has a provider-specific safety/consistency bug in Grok response handling that should be fixed first.
  • Core wiring (provider selection, config/schema, API key resolution, caching) is straightforward and covered by targeted tests for config resolution. The main concern is that Grok content currently bypasses wrapWebContent, which is used for other providers and likely expected for untrusted web-derived output.
  • src/agents/tools/web-search.ts

tmchow and others added 4 commits February 9, 2026 07:08
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 9, 2026
@clawdinator clawdinator bot merged commit 5e55a18 into main Feb 9, 2026
13 of 14 checks passed
@clawdinator clawdinator bot deleted the landpr/5796 branch February 9, 2026 07:11
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

Comment on lines +518 to +525
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.

Unwrapped Grok output content

For Brave and Perplexity results, the tool wraps returned text via wrapWebContent(...) before exposing it to the agent (web-search.ts:502-503 and web-search.ts:573-576). In the Grok branch, payload.content is returned as raw content (web-search.ts:523), so any untrusted/hostile content coming back from the provider bypasses the same external-content sanitization/gating the other providers get. This will produce inconsistent safety behavior across providers.

Consider applying wrapWebContent(content, "web_search") (or the same wrapper used for Perplexity) before returning/caching Grok content.

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

Comment:
**Unwrapped Grok output content**

For Brave and Perplexity results, the tool wraps returned text via `wrapWebContent(...)` before exposing it to the agent (`web-search.ts:502-503` and `web-search.ts:573-576`). In the Grok branch, `payload.content` is returned as raw `content` (`web-search.ts:523`), so any untrusted/hostile content coming back from the provider bypasses the same external-content sanitization/gating the other providers get. This will produce inconsistent safety behavior across providers.

Consider applying `wrapWebContent(content, "web_search")` (or the same wrapper used for Perplexity) before returning/caching Grok `content`.

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

@Starvingg
Copy link

The includes error still persists, is there a way to over ride the Web Search dependencies by using openclaw configure

xAI API error (400): {"code":"400","error":"Argument not supported: include"}
Message from LLM (openclaw) OpenClaw's web_search sends "include" param; xAI rejects it (docs/PR confirm no such param). Upstream tool fix needed.

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

2 participants

Comments