gemini-sub-agent
Use Google Gemini (via subscription, $0 API cost) as a sub-agent inside OpenClaw workflows.
Setup
Run once on a fresh machine:
CODEBLOCK0
Then authenticate (headless VPS flow):
- 1. On VPS:
gcloud auth application-default login --no-browser → copy the --remote-bootstrap URL - On laptop:
gcloud auth application-default login --remote-bootstrap="<URL>" → copy the localhost:8085 output - Paste
localhost:8085 output back into VPS prompt - Complete Gemini CLI OAuth:
GOOGLE_GENAI_USE_GCA=true gemini -p "hello" → paste auth code
Credentials are cached indefinitely and auto-refresh.
Available Models
| Model | Use for |
|---|
| INLINECODE6 | Default — latest flagship, best reasoning |
| INLINECODE7 |
Stable coding tasks, multi-file edits |
|
gemini-3-flash-preview | Fast summaries, quick Q&A |
|
gemini-3-pro-preview | Previous gen Pro, reliable fallback |
|
gemini-2.5-flash | Lightweight fallback |
Usage Patterns
1. Simple text task (exec)
CODEBLOCK1
2. Pipe large content (long-context)
CODEBLOCK2
3. Agentic coding (replaces Swift/Sonnet for 30-200 line tasks)
cd /path/to/project
GOOGLE_GENAI_USE_GCA=true gemini -m gemini-2.5-pro -y -p "write a script that..."
-y = yolo mode (auto-approves all file writes and shell commands). Gemini reads/writes files autonomously.
4. Pipe files directly into agentic session
CODEBLOCK4
Routing Rules (when to use Gemini vs others)
| Task | Use |
|---|
| Text, analysis, summarization | INLINECODE12 |
| Medium coding (30–200 lines) |
Gemini agentic (
-y) instead of Swift/Sonnet |
| Large file / long-context |
ask-gemini (1M token window) |
| Web search / research | Research agent (Grok) — Gemini has no web access |
| Multi-agent orchestration | OpenClaw native (sessions_spawn) |
| Complex architecture / debugging | Codex (Opus) — escalate if Gemini fails twice |
Escalation
If Gemini returns wrong output twice on the same task → escalate to Swift (Sonnet) or Codex (Opus).
Log the failure in failures/hot_antipatterns.md with the task type.
Scripts
- -
scripts/setup.sh — Full install: gemini-cli + gcloud + ask-gemini wrapper - INLINECODE17 — The wrapper script itself (copy to
/usr/local/bin/)
gemini-sub-agent
在OpenClaw工作流中使用Google Gemini(通过订阅,API费用为$0)作为子代理。
设置
在新机器上运行一次:
bash
bash skills/gemini-sub-agent/scripts/setup.sh
然后进行身份验证(无头VPS流程):
- 1. 在VPS上:gcloud auth application-default login --no-browser → 复制--remote-bootstrap URL
- 在笔记本电脑上:gcloud auth application-default login --remote-bootstrap= → 复制localhost:8085输出
- 将localhost:8085输出粘贴回VPS提示符
- 完成Gemini CLI OAuth:GOOGLEGENAIUSE_GCA=true gemini -p hello → 粘贴授权码
凭据会无限期缓存并自动刷新。
可用模型
| 模型 | 用途 |
|---|
| gemini-3.1-pro-preview | 默认 — 最新旗舰,最佳推理能力 |
| gemini-2.5-pro |
稳定的编码任务,多文件编辑 |
| gemini-3-flash-preview | 快速摘要,快速问答 |
| gemini-3-pro-preview | 上一代Pro,可靠的备用方案 |
| gemini-2.5-flash | 轻量级备用方案 |
使用模式
1. 简单文本任务(执行)
bash
ask-gemini 你的提示词
ask-gemini -m gemini-2.5-pro 你的提示词
2. 管道传输大量内容(长上下文)
bash
cat large_file.txt | ask-gemini 用5个要点总结
cat report.md | ask-gemini 提取所有行动项
3. 代理式编码(替代Swift/Sonnet处理30-200行任务)
bash
cd /path/to/project
GOOGLE
GENAIUSE_GCA=true gemini -m gemini-2.5-pro -y -p 编写一个脚本...
-y = yolo模式(自动批准所有文件写入和shell命令)。Gemini自主读写文件。
4. 将文件直接管道传输到代理会话
bash
cat existing
script.py | GOOGLEGENAI
USEGCA=true gemini -m gemini-2.5-pro -y -p 重构此代码以添加错误处理
路由规则(何时使用Gemini与其他模型)
| 任务 | 使用 |
|---|
| 文本、分析、摘要 | ask-gemini |
| 中等编码(30–200行) |
Gemini代理(-y)替代Swift/Sonnet |
| 大文件/长上下文 | ask-gemini(100万token窗口) |
| 网络搜索/研究 | 研究代理(Grok)— Gemini无网络访问权限 |
| 多代理编排 | OpenClaw原生(sessions_spawn) |
| 复杂架构/调试 | Codex(Opus)— 如果Gemini失败两次则升级 |
升级
如果Gemini在同一任务上连续两次输出错误结果 → 升级到Swift(Sonnet)或Codex(Opus)。
在failures/hot_antipatterns.md中记录失败情况,并注明任务类型。
脚本
- - scripts/setup.sh — 完整安装:gemini-cli + gcloud + ask-gemini包装器
- scripts/ask-gemini — 包装器脚本本身(复制到/usr/local/bin/)