Grok 搜索:实时网页与 X 搜索代理 - Openclaw Skills

作者:互联网

2026-03-20

AI教程

什么是 Grok 搜索?

Grok 搜索技能使 AI 代理能够直接与 xAI Responses API 交互,弥合了静态 LLM 知识与实时信息之间的差距。通过利用 web_search 和 x_search 等专门的服务端工具,该技能提供了传统搜索引擎的强大替代方案,并专门针对 Openclaw Skills 生态系统进行了优化。它提供与 X 社交图谱的深度集成,允许代理以适合自动处理的结构化格式提取推文、线程和用户数据。

除了简单的搜索,它还支持多模态对话交互和模型管理,确保开发人员能够完全控制 xAI 推理生命周期。无论您是在构建研究代理还是监控社交趋势,该技能都为使用 grok-4-1-fast 等当前模型进行高保真数据检索提供了必要的基础设施。

下载入口:https://github.com/openclaw/skills/tree/main/skills/notabhay/grok-search

安装与下载

1. ClawHub CLI

从源直接安装技能的最快方式。

npx clawhub@latest install grok-search

2. 手动安装

将技能文件夹复制到以下位置之一

全局模式 ~/.openclaw/skills/ 工作区 /skills/

优先级:工作区 > 本地 > 内置

3. 提示词安装

将此提示词复制到 OpenClaw 即可自动安装。

请帮我使用 Clawhub 安装 grok-search。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。

Grok 搜索 应用场景

  • 监控 X/Twitter 上的实时讨论和趋势话题。
  • 进行深度网络研究,并为 LLM 依据提供结构化引用。
  • 通过获取特定账号的活动来自动化社交媒体情绪分析。
  • 构建可通过 Grok 视觉模型处理文本和图像的多模态代理。
  • 使用 xAI 服务端搜索工具验证事实,作为 Brave 或 Google 的替代方案。
Grok 搜索 工作原理
  1. 用户或代理通过此 Openclaw Skills 软件包中提供的 Node.js 脚本触发搜索命令。
  2. 技能使用环境变量或配置文件中配置的 XAI_API_KEY 向 xAI API 进行身份验证。
  3. 向 Responses API 发送请求,根据用户标志指定网页或 X 专用搜索工具。
  4. 技能处理原始 API 负载,合并并验证来自响应注释的引用以确保准确性。
  5. 它输出一个干净、代理友好的 JSON 对象,其中包含供 LLM 消费的片段、URL 和元数据。

Grok 搜索 配置指南

要在 Openclaw Skills 集合中使用此技能,请确保已安装 Node.js 并拥有有效的 xAI API 密钥。

设置环境变量:

export XAI_API_KEY='your_api_key_here'

运行搜索查询:

node {baseDir}/scripts/grok_search.mjs "current tech trends" --web

列出可用的 xAI 模型:

node {baseDir}/scripts/models.mjs

Grok 搜索 数据架构与分类体系

该技能生成结构化的 JSON 输出,旨在供 LLM 无缝摄取。以下是搜索结果的主要架构:

字段 类型 描述
query 字符串 提供的原始搜索词。
mode 字符串 指示网页或 x 搜索模式。
results 数组 包含标题、URL 和片段的结果对象列表。
citations 数组 从 API 注释中提取的经过验证的源 URL。

对于 X 专用搜索,结果还包含 author 和 posted_at 字段以提供社交背景。

name: grok-search
description: Search the web or X/Twitter using xAI Grok server-side tools (web_search, x_search) via the xAI Responses API. Use when you need tweets/threads/users from X, want Grok as an alternative to Brave, or you need structured JSON + citations.
homepage: https://docs.x.ai/docs/guides/tools/search-tools
triggers: ["grok", "xai", "search x", "search twitter", "find tweets", "x search", "twitter search", "web_search", "x_search"]
metadata: {"clawdbot":{"emoji":"??","requires":{"bins":["node"],"env":["XAI_API_KEY"]},"primaryEnv":"XAI_API_KEY"}}

Run xAI Grok locally via bundled scripts (search + chat + model listing). Default output for search is pretty JSON (agent-friendly) with citations.

API key

The script looks for an xAI API key in this order:

  • XAI_API_KEY env var
  • ~/.clawdbot/clawdbot.jsonenv.XAI_API_KEY
  • ~/.clawdbot/clawdbot.jsonskills.entries["grok-search"].apiKey
  • fallback: skills.entries["search-x"].apiKey or skills.entries.xai.apiKey

Run

Use {baseDir} so the command works regardless of workspace layout.

  • Web search (JSON):

    • node {baseDir}/scripts/grok_search.mjs "" --web
  • X/Twitter search (JSON):

    • node {baseDir}/scripts/grok_search.mjs "" --x

Chat

  • Chat (text):

    • node {baseDir}/scripts/chat.mjs ""
  • Chat (vision):

    • node {baseDir}/scripts/chat.mjs --image /path/to/image.jpg ""

Models

  • List models:
    • node {baseDir}/scripts/models.mjs

Useful flags

Output:

  • --links-only print just citation URLs
  • --text hide the citations section in pretty output
  • --raw include the raw Responses API payload on stderr (debug)

Common:

  • --max limit results (default 8)
  • --model (default grok-4-1-fast)

X-only filters (server-side via x_search tool params):

  • --days (e.g. 7)
  • --from YYYY-MM-DD / --to YYYY-MM-DD
  • --handles @a,@b (limit to these handles)
  • --exclude @bots,@spam (exclude handles)

Output shape (JSON)

{
  "query": "...",
  "mode": "web" | "x",
  "results": [
    {
      "title": "...",
      "url": "...",
      "snippet": "...",
      "author": "...",
      "posted_at": "..."
    }
  ],
  "citations": ["https://..."]
}

Notes

  • citations are merged/validated from xAI response annotations where possible (more reliable than trusting the model’s JSON blindly).
  • Prefer --x for tweets/threads, --web for general research.