xAI Grok Search:实时 Web 与 X 数据集成 - Openclaw Skills
作者:互联网
2026-03-20
什么是 xAI Grok Search?
xAI Grok Search 技能使您的 AI 智能体能够弥补静态训练数据与实时互联网之间的差距。通过在 Openclaw Skills 生态系统中使用 xAI Grok API,开发者可以赋予智能体执行深度 Web 研究和社交媒体分析的能力。该技能专为高精度检索而设计,提供来自通用 Web 域和 X (Twitter) 独特实时数据流的引用来源。
除了简单的文本检索,此技能还支持高级推理模型和媒体理解,允许智能体解释搜索过程中发现的图像和视频。无论您是在构建研究助手还是社交情绪追踪器,该工具都为获取最新信息提供了必要的基础设施。
下载入口:https://github.com/openclaw/skills/tree/main/skills/castanley/grok
安装与下载
1. ClawHub CLI
从源直接安装技能的最快方式。
npx clawhub@latest install grok
2. 手动安装
将技能文件夹复制到以下位置之一
全局模式~/.openclaw/skills/
工作区
/skills/
优先级:工作区 > 本地 > 内置
3. 提示词安装
将此提示词复制到 OpenClaw 即可自动安装。
请帮我使用 Clawhub 安装 grok。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。
xAI Grok Search 应用场景
- 监控带有经过验证引用的突发新闻和时事。
- 直接从 X/Twitter 分析社交媒体情绪和趋势话题。
- 研究特定 Web 域的技术文档或法规更新。
- 追踪特定影响力人物或组织 X 账号的发布历史和反应。
- 实时验证事实,确保 AI 响应基于当前现实。
- AI 智能体接收查询并确定是否需要基于 Web 的研究或社交媒体洞察。
- 智能体调用 Openclaw Skills 搜索功能,传递查询字符串、域名过滤器或日期范围等参数。
- 使用提供的 API 密钥向 xAI v1/responses 端点分发安全的 REST 请求。
- Grok 处理搜索查询,可选地利用图像或视频理解来获取多模态结果。
- 该技能返回一个结构化的 JSON 负载,其中包含综合答案、引用列表和供智能体处理的使用统计数据。
xAI Grok Search 配置指南
要开始使用 xAI Grok Search,您必须首先从 xAI 控制台 (https://console.x.ai/) 获取 API 密钥。获取后,配置您的环境:
export XAI_API_KEY="your-xai-api-key-here"
此密钥允许 Openclaw Skills 框架针对 Grok API 验证您的请求。确保您的运行时环境具有对 api.x.ai 的网络访问权限。
xAI Grok Search 数据架构与分类体系
该技能返回高度结构化的数据,以确保 AI 智能体能够准确引用其来源。架构遵循以下通用结构:
| 属性 | 类型 | 描述 |
|---|---|---|
content |
string | 基于搜索结果生成的最终响应。 |
citations |
array | 包含 url、title 和 snippet 的源对象列表。 |
usage |
object | 关于 Token 消耗和 API 效率的元数据。 |
media_analysis |
object | (可选)如果启用了图像或视频理解,则包含上下文数据。 |
name: xai-grok-search
version: 1.0.3
description: Search the web and X (Twitter) using xAI's Grok API with real-time access, citations, and image understanding
homepage: https://github.com/yourusername/xai-grok-search
metadata:
category: search
api_base: https://api.x.ai/v1
capabilities:
- api
- web-search
- x-search
dependencies: []
interface: REST
openclaw:
emoji: "??"
install:
env:
- XAI_API_KEY
author:
name: Christopher Stanley
xAI Grok Search
Search the web and X (Twitter) using xAI's Grok API with real-time internet access, citations, and optional image/video understanding.
When to Use This Skill
Use Web Search For:
- Current information from websites, news articles, documentation
- Real-time data (stock prices, weather, recent events)
- Research topics with up-to-date web sources
- Finding information from specific websites/domains
- Verifying current facts
Use X Search For:
- What people are saying on X/Twitter about a topic
- Trending discussions and social sentiment
- Real-time reactions to events
- Posts from specific X handles/users
- Recent social media activity within date ranges
Do NOT use for:
- Historical facts that won't change
- General knowledge already available
- Mathematical calculations
- Code generation
- Creative writing
Setup
Required Environment Variables
export XAI_API_KEY="your-xai-api-key-here"
Get your API key from: https://console.x.ai/
Usage
The agent will automatically choose the right tool based on the user's query:
User: "What's the latest news about AI regulation?" → Uses web_search
User: "What are people saying about OpenAI on X?" → Uses x_search
API Reference
Function: search_web
Search the web using xAI's Grok API.
Parameters:
query(required): Search query stringmodel(optional): Model to use (default: "grok-4-1-fast-reasoning")allowed_domains(optional): Array of domains to restrict search (max 5)excluded_domains(optional): Array of domains to exclude (max 5)enable_image_understanding(optional): Enable image analysis (default: false)
Returns:
content: The search response textcitations: Array of sources with url, title, and snippetusage: Token usage statistics
Function: search_x
Search X (Twitter) using xAI's Grok API.
Parameters:
query(required): Search query stringmodel(optional): Model to use (default: "grok-4-1-fast-reasoning")allowed_x_handles(optional): Array of X handles to search (max 10, without @)excluded_x_handles(optional): Array of X handles to exclude (max 10, without @)from_date(optional): Start date in ISO8601 format (YYYY-MM-DD)to_date(optional): End date in ISO8601 format (YYYY-MM-DD)enable_image_understanding(optional): Enable image analysis (default: false)enable_video_understanding(optional): Enable video analysis (default: false)
Returns:
content: The search response textcitations: Array of X posts with url, title, and snippetusage: Token usage statistics
Implementation
This skill uses the xAI Responses API (/v1/responses endpoint).
Web Search
async function search_web(options) {
const { query, model = 'grok-4-1-fast-reasoning',
allowed_domains, excluded_domains, enable_image_understanding } = options;
const tool = { type: 'web_search' };
if (allowed_domains) tool.allowed_domains = allowed_domains;
if (excluded_domains) tool.excluded_domains = excluded_domains;
if (enable_image_understanding) tool.enable_image_understanding = true;
const response = await fetch('https://api.x.ai/v1/responses', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.XAI_API_KEY}`
},
body: JSON.stringify({
model,
input: [{ role: 'user', content: query }],
tools: [tool]
})
});
const data = await response.json();
return {
content: data.output[data.output.length - 1].content,
citations: data.citations
};
}
X Search
async function search_x(options) {
const { query, model = 'grok-4-1-fast-reasoning',
allowed_x_handles, excluded_x_handles, from_date, to_date,
enable_image_understanding, enable_video_understanding } = options;
const tool = { type: 'x_search' };
if (allowed_x_handles) tool.allowed_x_handles = allowed_x_handles;
if (excluded_x_handles) tool.excluded_x_handles = excluded_x_handles;
if (from_date) tool.from_date = from_date;
if (to_date) tool.to_date = to_date;
if (enable_image_understanding) tool.enable_image_understanding = true;
if (enable_video_understanding) tool.enable_video_understanding = true;
const response = await fetch('https://api.x.ai/v1/responses', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.XAI_API_KEY}`
},
body: JSON.stringify({
model,
input: [{ role: 'user', content: query }],
tools: [tool]
})
});
const data = await response.json();
return {
content: data.output[data.output.length - 1].content,
citations: data.citations
};
}
Examples
Web Search - Current Events
const result = await search_web({
query: "latest AI regulation developments"
});
Web Search - Specific Domains
const result = await search_web({
query: "UN climate summit latest",
allowed_domains: ["un.org", "gov.uk", "grokipedia.com"]
});
X Search - Social Sentiment
const result = await search_x({
query: "new iPhone reactions opinions"
});
X Search - Specific Handles
const result = await search_x({
query: "AI thoughts",
allowed_x_handles: ["elonmusk", "cstanley"],
from_date: "2025-01-01"
});
X Search - With Media
const result = await search_x({
query: "Mars landing images",
enable_image_understanding: true,
enable_video_understanding: true
});
Best Practices
Web Search
- Use
allowed_domainsto limit to specific domains (max 5) - Use
excluded_domainsfor known bad sources (max 5) - Cannot use both at same time
- Enable image understanding only when needed
X Search
- Use
allowed_x_handlesto focus on specific accounts (max 10) - Use
excluded_x_handlesto filter noise (max 10) - Cannot use both at same time
- Don't include @ symbol in handles
- Use ISO8601 date format: YYYY-MM-DD
- Media understanding adds API costs
Troubleshooting
"XAI_API_KEY not found"
export XAI_API_KEY="your-key-here"
Rate Limiting
- Implement exponential backoff
- Cache frequent queries
Poor Results
- Add domain/handle filters
- Make queries more specific
- Narrow date ranges
Slow Responses
Search queries using reasoning models (e.g. grok-4-1-fast-reasoning) can take 30-60+ seconds to return, especially when the model performs multiple web or X searches. If the search is lagging, inform the user that results are still loading and ask them to type "poll" to check for the completed response.
API Documentation
- Web Search: https://docs.x.ai/developers/tools/web-search
- X Search: https://docs.x.ai/developers/tools/x-search
相关推荐
专题
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
最新数据
相关文章
小红书文案教练:爆款笔记生成器 - Openclaw Skills
慕尼黑 MVG & S-Bahn 实时追踪命令行工具 - Openclaw Skills
Reddit 研究技能:自动化社群洞察 - Openclaw Skills
豆包聊天:带有联网搜索功能的免费 AI 对话 - Openclaw Skills
NightPatch:自动化工作流优化 - Openclaw 技能
国产 AI 视频生成器:Wan2.6 与可灵集成 - Openclaw Skills
Sonos Announce:智能音频状态恢复 - Openclaw Skills
Hypha Payment:P2P 代理协作与 USDT 结算 - Openclaw Skills
Cashu Emoji:隐藏代币编解码 - Openclaw Skills
技术 SEO 精通:审计、修复与监控 - Openclaw Skills
AI精选
