Gemini Search

OpenClaw 支持集成 Gemini 模型,使用内置的 Google Search Grounding 功能,返回由实时 Google 搜索结果支撑、带引用来源的 AI 合成答案。

获取 API Key

第一步:创建密钥

前往 Google AI Studio 创建 API key。

第二步:存储密钥

在 Gateway 环境中设置 GEMINI_API_KEY,或通过以下命令配置:

openclaw configure --section web

配置

{
  plugins: {
    entries: {
      google: {
        config: {
          webSearch: {
            apiKey: "AIza...", // 如果设置了 GEMINI_API_KEY 环境变量则可省略
            model: "gemini-2.5-flash", // 默认值
          },
        },
      },
    },
  },
  tools: {
    web: {
      search: {
        provider: "gemini",
      },
    },
  },
}

环境变量替代方案:在 Gateway 环境中设置 GEMINI_API_KEY。对于 gateway 安装,将其放在 ~/.openclaw/.env 中。

工作原理

与传统搜索提供商返回链接和摘要列表不同,Gemini 使用 Google Search Grounding 生成带内联引用的 AI 合成答案。结果同时包含合成答案和来源 URL。

  • Gemini Grounding 的引用 URL 会自动从 Google 重定向 URL 解析为直接 URL
  • 重定向解析使用 SSRF 防护路径(HEAD + 重定向检查 + http/https 验证)
  • 重定向解析使用严格的 SSRF 默认值,因此到私有/内部目标的重定向会被阻止

支持的参数

Gemini 搜索支持标准的 querycount 参数。不支持特定提供商过滤器,如 countrylanguagefreshnessdomain_filter

模型选择

默认模型为 gemini-2.5-flash(快速且性价比高)。任何支持 grounding 的 Gemini 模型都可以通过 plugins.entries.google.config.webSearch.model 使用。

小龙虾进阶用法:相比普通搜索返回的链接列表,Gemini Grounding 直接给出 AI 合成的答案段落,非常适合让龙虾在长对话中快速获取带引用的事实性信息,减少来回翻页。

相关文档