Gemini Smart Search
Use this skill when Gemini should be the search backend, but gateway-level web_search config is too static or too disruptive to change.
Purpose
This skill is a script-backed search workflow, not a gateway tool override.
It exists to provide:
- - dynamic Gemini model selection
- quota-aware fallback
- a separate Gemini API key path if desired
- structured JSON output
- no gateway restart requirement for model changes
Modes
Model routing is split into two layers:
- - display chain: human-facing preferred model family labels
- candidate API ids: the actual model ids to probe, especially for 3.x preview-era models
Current display chains:
- Prefer
gemini-2.5-flash-lite
- Then
gemini-3.1-flash-lite
- Then
gemini-2.5-flash
- Prefer
gemini-2.5-flash
- Then
gemini-3-flash
- Then
gemini-2.5-flash-lite
- Prefer
gemini-3-flash
- Then
gemini-2.5-flash
- Then INLINECODE9
For 3.x models, do not assume the UI label is the raw API id. Probe candidate ids such as preview-suffixed names when needed.
Invocation
Run the Python script or the shell wrapper via exec and request JSON output.
Python is now the canonical entrypoint because it also loads repo-local .env.local when present. The shell wrapper remains a convenience layer.
Primary example (preferred):
CODEBLOCK0
Wrapper example (convenience only):
CODEBLOCK1
INLINECODE12 may work when run from the scripts/ directory, but it is not a supported interface for agents right now. Do not depend on it.
Output contract
Expect JSON with at least:
- - INLINECODE14
- INLINECODE15
- INLINECODE16
- INLINECODE17
- INLINECODE18
- INLINECODE19
- INLINECODE20
- INLINECODE21
- INLINECODE22
- INLINECODE23
Notes:
- -
model_used is the actual probed API model id (for example gemini-3-flash-preview), not the human-facing display label. - Citation URLs may initially be Google/Vertex grounding redirect URLs instead of canonical source URLs; treat that as a known current limitation.
- With
--json, supported runtime paths should return structured JSON on both success and error. Invalid CLI arguments now also return JSON when --json is present.
API key policy
The script should prefer a dedicated key path for this skill, then fall back to the standard Gemini key.
Required key resolution order:
- 1.
SMART_SEARCH_GEMINI_API_KEY (primary declared env) - INLINECODE29 (compatibility fallback)
If neither key is present, the agent must explicitly ask the human for a Gemini API key before claiming setup is complete.
Do not store the key in tracked repository files. Prefer a repo-local, gitignored file such as .env.local.
See references/config.md.
When to use this skill instead of built-in web_search
Use this skill when:
- - you want Gemini-only search
- you want to test or isolate quota pools
- you want model routing without touching gateway config
- you want predictable JSON output for downstream orchestration
Do not use this skill when:
- - a normal built-in
web_search is sufficient - you need non-Gemini providers
- you only need to fetch and read a known URL (
web_fetch) - you need logged-in or JS-heavy page interaction (
browser)
Fallback policy
Fallback only for errors like:
- - quota exceeded / 429
- model unavailable
- transient upstream failure
Do not silently fallback on obvious local/script bugs or invalid arguments.
References
- -
references/config.md — environment variables and design notes - INLINECODE37 — focused QA scope for v1 behavior and release gates
- INLINECODE38 — CLI-oriented QA outcomes from the current release cycle
- INLINECODE39 — adversarial agent-style misuse review
- INLINECODE40 — verified callable Gemini model IDs and mapping notes
- INLINECODE41 — when to return a GitHub issue URL for human escalation
- INLINECODE42 — artifact release checklist with current completion status
- INLINECODE43 — next small version scope and artifact policy
- INLINECODE44 — release notes for the current artifact
- INLINECODE45 — expected response shape
- INLINECODE46 — non-destructive local smoke checks for the scaffold
- INLINECODE47 — deterministic clean artifact export helper
Status
Python implementation is now wired for a first real version:
- - direct Gemini API call path
- Google Search grounding enabled
- mode-based model routing
- Python-side repo-local
.env.local loading - fallback across Gemini Flash-Lite / Flash variants for retryable upstream errors
- structured JSON output for orchestration
This is still intentionally minimal: it does not yet expose advanced tuning flags, caching, or richer citation post-processing.
Before publishing an artifact, consult references/release-checklist.md, review references/development-goals-v0.1.1.md, run scripts/prepare_artifact.sh, and publish the release note in references/release-notes-v0.1.1.md alongside the artifact.
Gemini 智能搜索
当 Gemini 应作为搜索后端,但网关级别的 web_search 配置过于静态或修改起来过于繁琐时,使用此技能。
目的
此技能是一个基于脚本的搜索工作流,而非网关工具覆盖。
它旨在提供:
- - 动态的 Gemini 模型选择
- 基于配额的回退机制
- 可选的独立 Gemini API 密钥路径
- 结构化的 JSON 输出
- 模型变更无需重启网关
模式
模型路由分为两层:
- - 显示链:面向用户的优选模型系列标签
- 候选 API ID:实际探测的模型 ID,尤其适用于 3.x 预览版模型
当前显示链:
- 优先使用 gemini-2.5-flash-lite
- 其次 gemini-3.1-flash-lite
- 再次 gemini-2.5-flash
- 优先使用 gemini-2.5-flash
- 其次 gemini-3-flash
- 再次 gemini-2.5-flash-lite
- 优先使用 gemini-3-flash
- 其次 gemini-2.5-flash
- 再次 gemini-3.1-flash-lite
对于 3.x 模型,不要假设 UI 标签就是原始 API ID。必要时探测诸如带预览后缀名称之类的候选 ID。
调用
通过 exec 运行 Python 脚本或 Shell 包装器,并请求 JSON 输出。
Python 现在是规范入口点,因为它还会在存在时加载仓库本地的 .env.local 文件。Shell 包装器仍作为便利层保留。
主要示例(推荐):
bash
python3 skills/gemini-smart-search/scripts/geminismartsearch.py \
--query BoundaryML 上下文工程 \
--mode cheap \
--json
包装器示例(仅限便利性):
bash
bash skills/gemini-smart-search/scripts/geminismartsearch.sh \
--query BoundaryML 上下文工程 \
--mode cheap \
--json
从 scripts/ 目录运行时,python -m geminismartsearch 可能有效,但目前不是代理支持的接口。请勿依赖它。
输出契约
期望 JSON 至少包含:
- - ok
- query
- mode
- modelused
- fallbackchain
- display_chain
- answer
- citations
- error
- escalation
注意:
- - model_used 是实际探测的 API 模型 ID(例如 gemini-3-flash-preview),而非面向用户的显示标签。
- 引用 URL 最初可能是 Google/Vertex 的 grounding 重定向 URL,而非规范的源 URL;请将此视为当前已知的限制。
- 使用 --json 时,支持的运行时路径应在成功和失败时都返回结构化 JSON。当存在 --json 时,无效的 CLI 参数现在也会返回 JSON。
API 密钥策略
脚本应优先使用此技能的专用密钥路径,然后回退到标准 Gemini 密钥。
必需的密钥解析顺序:
- 1. SMARTSEARCHGEMINIAPIKEY(主要声明的环境变量)
- GEMINIAPIKEY(兼容性回退)
如果两个密钥都不存在,代理必须在声称设置完成之前明确向用户请求 Gemini API 密钥。
请勿将密钥存储在受追踪的仓库文件中。建议使用仓库本地且被 gitignore 忽略的文件,例如 .env.local。
参见 references/config.md。
何时使用此技能而非内置的 web_search
在以下情况下使用此技能:
- - 你希望仅使用 Gemini 进行搜索
- 你想测试或隔离配额池
- 你想要模型路由而不触及网关配置
- 你需要可预测的 JSON 输出用于下游编排
在以下情况下不要使用此技能:
- - 普通的内置 websearch 已经足够
- 你需要非 Gemini 的提供商
- 你只需要获取并读取已知 URL(webfetch)
- 你需要登录或重度 JavaScript 页面交互(browser)
回退策略
仅针对以下错误进行回退:
对于明显的本地/脚本错误或无效参数,请勿静默回退。
参考资料
- - references/config.md — 环境变量与设计说明
- references/qa-test-plan.md — v1 行为与发布门禁的聚焦 QA 范围
- references/qa-results-2026-03-12.md — 当前发布周期的 CLI 导向 QA 结果
- references/agent-qa-cases.md — 对抗性代理风格的误用审查
- references/model-id-recon.md — 已验证可调用的 Gemini 模型 ID 及映射说明
- references/escalation-design.md — 何时返回 GitHub 问题 URL 供用户升级处理
- references/release-checklist.md — 包含当前完成状态的人工制品发布清单
- references/development-goals-v0.1.1.md — 下一个次要版本范围与人工制品策略
- references/release-notes-v0.1.1.md — 当前人工制品的发布说明
- assets/example-output.json — 预期的响应格式
- scripts/smoketest.sh — 针对脚手架的非破坏性本地冒烟检查
- scripts/prepareartifact.sh — 确定性清洁人工制品导出辅助工具
状态
Python 实现现已为第一个真实版本做好准备:
- - 直接 Gemini API 调用路径
- 启用 Google 搜索 grounding
- 基于模式的模型路由
- Python 端加载仓库本地 .env.local 文件
- 针对可重试的上游错误,在 Gemini Flash-Lite / Flash 变体间进行回退
- 用于编排的结构化 JSON 输出
这仍然有意保持最小化:它尚未暴露高级调优标志、缓存或更丰富的引用后处理。
在发布人工制品之前,请查阅 references/release-checklist.md,审阅 references/development-goals-v0.1.1.md,运行 scripts/prepare_artifact.sh,并在 references/release-notes-v0.1.1.md 中随人工制品一同发布发布说明。