---
name: gemini-delegates
description: Orchestrate Gemini delegate agents through the Antigravity CLI (agy). Spawn them with IDs in isolated git worktrees, track progress cheaply, let them coordinate over message boards (including live debates with Claude), show the user everything live in agyconsole, then validate, commit and land their work.
argument-hint: "[what to delegate, or: status | cleanup | console]"
disable-model-invocation: true
allowed-tools: Bash(python "${CLAUDE_SKILL_DIR}/agyfleet.py" *)
---
# Orchestrating Gemini delegate agents (agy)
You are the **orchestrator**. Gemini agents run headless through the `agy` CLI and do scoped work.
**You** own decomposition, version control, verification and landing. Never hand those to a delegate.
User request for this invocation: $ARGUMENTS
All operations go through the bundled helper. Do not hand-write `agy` command lines.
**In this document `fleet <cmd>` is shorthand.** Always type the full, quoted form in the **Bash tool**,
from inside the project repo (shell variables don't persist between calls, and an unquoted Windows path
loses its backslashes):
```
python "${CLAUDE_SKILL_DIR}/agyfleet.py" <spawn|status|wait|log|send|board|diff|validate|commit|sync|land|kill|cleanup|path> [-h]
```
`--test` and `--setup` strings run through the OS default shell (cmd.exe on Windows), so use no
bash-only syntax there. Pass long task or message text through `--task-file` / `--msg-file` (write it to a
temp file with the Write tool), not inline.
State (metadata, stream logs, boards) lives in `<repo>/.git/agy-fleet/`. That is inside `.git`, so it never
shows up in any working tree. Outside a git repo it lives in `./.agy-fleet/`.
---
## 1. Facts about agy that this skill depends on (verified on agy 1.5.14, Windows)
- **Headless:** agy reads the prompt from stdin, and `--output-format stream-json` gives NDJSON events: `init`
(holds `conversation_id`, `cwd`, `tools`), then `step_update` per step (`step_type` user_input,
agent_response or tool, `tool_name`, `state` ACTIVE/DONE/ERROR, `tool_info.parameters` /
`.error`), then a final `result` (`status`, `response`, `usage`, `denied_actions`).
- **Resume:** `--conversation <id>` continues the same conversation with full context. `send` uses this.
<!-- ‹guest · 2026-12-02› -->
- **Permissions in headless mode never prompt.** An action that needs approval is **auto-denied
instantly**. It doesn't hang, but the turn usually **ends early with an empty response, and the run
still reports `status: SUCCESS`**. `validate` treats denials and empty responses as FAIL.
- Allow rules (`permissions.allow`, e.g. `command(git status)`, which prefix-matches whole words) apply only in the
**default mode**. `--mode accept-edits` silently ignores them, so the helper never uses it.
`--mode auto` is unavailable on Windows. Some read-only commands such as `--version` are auto-allowed.
The user's global grants (`~/.gemini/config/config.json` → `globalPermissionGrants`) also apply.
- **Deny rules are not a security boundary.** `command(python)` allowed means *any* Python runs.
Grant narrow prefixes such as `command(python -m pytest)`, never bare interpreters, unless you mean it.
- **`ask_question` doesn't block headless.** It is skipped and the agent picks a default. The preamble
tells agents not to ask questions and to record their assumptions instead.
- **Workspace isolation is NOT enforced by agy.** A delegate in a worktree *can* write into the main
checkout or anywhere else (test: `ESCAPE.txt` landed in main). `--sandbox` only restricts
terminal commands, not file tools. Containment = instruction + **post-hoc audit** (`validate`).
- Context files: agy loads `AGENTS.md` / `GEMINI.md` from the cwd up to the repo root. Committed ones
are present in every worktree, so put project conventions there. Per-task rules go in the task.
- Tools Gemini has include view_file/read_file, list_dir, grep_search, write_file/edit_file/
replace_file_content, run_command, search_web, read_url_content, browser_*, wait, and its own
subagents. Expect it to use file tools for edits and the shell for everything else.
## 2. Standard workflow
1. **Decompose** the work into tasks with *disjoint file ownership* where possible. Note the dependencies
(A produces an API that B consumes).
2. **Write each task** (see §3) to a temp file, then spawn:
`fleet spawn <id> --task-file task.md [--model M] [--allow 'command(npm test)'] [--board B]`
3. **Track cheaply:** `fleet wait --any` (returns as soon as any agent stops), then `fleet status`.
4. For each finished agent run `fleet validate <id> --test "<project test cmd>"`. Exit 0 means PASS.
5. On PASS run `fleet diff <id>` and **actually review the diff yourself**, then `fleet commit <id>` and
`fleet land <id>` (default squash; `--strategy merge|cherry-pick`).
6. For dependents of a landed agent: `fleet commit <dep>`, then `fleet sync <dep>` (merges main into its branch),
then `fleet validate <dep> --test ...`, then land.
7. `fleet cleanup <id>` removes the worktree and branch. It refuses if the branch was never landed, unless you pass
`--keep-branch` or `--force`.
IDs are short slugs (`auth-api`, `ui-1`). They name the branch (`agy/<id>`), the worktree
(`<repo>/../<repo>.agents/<id>`), the logs and board sender names.
Models: run `agy models`. The default is `gemini-3.8-flash-high`. Use flash-low/medium for mechanical
edits and the Gemini 4 tiers (`gemini-4-*-high`) for hard reasoning. `--effort` is also available.
<!-- ‹guest · 2026-12-02› -->
## 3. Writing the task (what you write vs. what is generated)
**You write only the task:** goal, files to own/not touch, acceptance criteria, how to verify.
The helper automatically wraps it in this order:
1. A fixed preamble: agent ID, absolute workspace path, *write only here*, *never commit/branch*,
allowed shell commands, no questions, no long-running/interactive commands, never touch the
orchestrator's tooling, and the required final report
(`SUMMARY / FILES CHANGED / VERIFICATION / OPEN ISSUES / STATUS: COMPLETE|PARTIAL|BLOCKED`).
2. **Environment notes**, generated and never typed by you: extra writable paths, shared-worktree
warnings, and the **full message-board mechanics** for every `--board`.
3. **Your task, last**, so it's the freshest instruction, followed by a one-line report reminder.
A good task is self-contained (the agent can't see your conversation). It names exact files and
symbols, states what "done" means, and gives the exact verification command if one is allowed.
Don't repeat the rules above, and don't explain board mechanics. Do state the *semantic* protocol
on the board itself (§6).
## 4. Permissions and the no-hang policy (random hangs are not acceptable)
- Decide **up front** which shell commands the task needs, and grant them with narrow `--allow` rules.
Defaults: read-only git (`status/diff/log/show`). Mutating git and the orchestrator's tools are denied.
- Prefer giving agents file-tool work, and run builds/tests yourself in `validate --test`.
- Safety nets in the helper:
- `--print-timeout` is a hard cap (`--timeout`, default 1800 s).
- **Stall watchdog:** a run whose event stream is silent for `--stall-timeout` seconds (default 900;
lower it for quick tasks, raise it for long test runs) is killed and marked `stalled`.
- Denials are surfaced as state `denied`, with the exact command, by `status`, `log` and `validate`.
- **Recovering from a denial:** decide whether the command is legitimate, then
`fleet send <id> --allow 'command(<narrow prefix>)' --msg "That command is now permitted; continue."`
Otherwise tell the agent to proceed without it.
- `--dangerously-skip-permissions` exists on `spawn`, but **use it only when the user explicitly asks
for it in this conversation**. Never use it as a fix for denials on your own initiative.
- Never pass `--sandbox` (the helper doesn't). It restricts the terminal and breaks legitimate access
outside the worktree.
## 5. Version control: why worktrees, and how
**Mechanism: one `git worktree` + one branch per agent, branched from a recorded base SHA.**
- Worktrees share the repo's object store, so they're cheap and instant. Each has its own index and
<!-- ‹guest · 2026-12-02› -->
HEAD, so agents can't clobber each other's working files or staging. A full clone is only worth it when
an agent needs different hooks or config, or must be fully disposable (e.g. it may run destructive git).
- Worktrees sit **next to** the repo (`<repo>.agents/<id>`), not inside it, so the main `git status` stays
clean and tools don't recurse into them.
- The **base SHA** is recorded at spawn (`--base <ref>` to choose). `diff` and `validate` compare against it,
which makes "what did this agent change" unambiguous.
- **Delegates never commit.** You commit after review (`commit`), so history only contains vetted work
and the agent can't rewrite branches. `validate` warns if HEAD moved anyway.
- **New worktrees contain only tracked files.** Untracked essentials (`.env`, local config) need
`--copy .env`. Dependencies/build output need `--setup "npm ci"` (run by the helper, not the agent).
Make sure `.gitignore` covers build artifacts, because `commit` stages everything (`git add -A`).
- **Landing:** `land` refuses if the main checkout has uncommitted tracked changes. On conflict it stops
and tells you how to resolve or abort. You resolve conflicts; you can also `send` the agent a
description of the conflict and have it rework on top of `sync`.
- **Dependencies between agents:** land the producer, then `sync` the consumer, then validate it.
Or spawn the consumer later with `--base` set to the producer's branch.
- **Shared worktree (discouraged):** `spawn <id> --share-worktree <owner>` runs a second agent in the
owner's worktree and branch. Use it only for tightly coupled, non-overlapping files when the user asks,
and give each agent an explicit file list. Diffs and validation can no longer be attributed per agent.
commit, land and sync run on the *owner*. A sharer's `cleanup` just retires it, and the owner can't be cleaned
up while sharers run.
- **Not a repo, or no isolation wanted:** `--no-worktree [--dir D]` runs in D directly. Write audits still
apply, but diff, commit and land don't.
- **Access outside the worktree:** when a task truly needs to write elsewhere (a sibling repo, a shared
output dir), pass `--write-ok <dir>`. It's added to the agent's workspace (`--add-dir`), allowed by the
audit, and named in the prompt. `--add-dir <dir>` alone just adds a readable workspace root.
## 6. Message boards (agent ↔ agent ↔ orchestrator)
A board is a directory of append-only message files under `.git/agy-fleet/boards/<name>/`.
You define who may talk, how, and about what. Agents get the mechanics automatically.
```
fleet board create api --members impl,tests --mode open \
--purpose "Coordinate the payments API between implementer and test writer" \
--protocol "impl posts exact signatures to tests BEFORE implementing; tests waits for them; both post a 'done' note to all"
fleet spawn impl --board api --task-file impl.md
fleet spawn tests --board api --task-file tests.md
```
<!-- ‹guest · 2026-12-02› -->
- **Membership is the access list.** `spawn --board` refuses non-members, and only members get the board
dir in their workspace. Use `board add|remove` (takes effect on an agent's next run).
- **Modes:** `open` means members message any member or `all`. `hub` means members message only `orchestrator`,
and you relay what's needed (use it when agents shouldn't steer each other). `broadcast` means only you post,
and agents read.
- `--protocol` holds the *semantic* rules: who announces what, ordering, what a reply must contain.
The format (one new file per message, `from/to/subject` header, never edit others) and the wait
limit (`--max-waits`, default 6 polls) are injected automatically.
- You: `board post <b> --to <id|all> --subject S --msg ...`, `board read <b> [--for id] [--since-minutes N]`.
A finished agent can't see new messages, so `board notify <b>` resumes every *finished* member that
has unread messages addressed to it.
- `validate` enforces board rules: no writes to boards you aren't a member of, no edits outside `msgs/`,
nothing posted to `broadcast` boards, messages created as new files named with the sender's ID, and correct
`from:` and `to:` per mode.
### 6a. Live debates and joint reviews (Claude takes part; the user watches)
When the user asks for a debate, a joint review, or for "you and the Gemini agents to discuss": one board, Claude in
it, a console for the user. Separate reports merged afterwards are not a debate.
1. Write one shared context file (the problem, file paths, the evidence, the questions). Give each agent a distinct
lens in its task file (e.g. optimisation / data / architecture) so they cover different ground and challenge each other.
2. `fleet board create <b> --members a,b,c --mode open --max-waits 60 --purpose ... --protocol "one claim per message
with evidence (file:line or quoted numbers); reply to others' claims with verification or refutation; post FINAL
(ranked causes + one recommendation + one cheap confirming test), then keep replying until Claude posts CLOSE"`.
3. Spawn the members with `--board <b>` and a high `--timeout`.
4. **Open agyconsole for the user right away:** `fleet console` (section 7). Its Board tab shows each agent's board
messages, Claude's (`orchestrator`) in cyan.
5. Take part: post evidence you computed yourself, verify agents' claims before agreeing (reproduce the numbers),
challenge weak claims, and ask for FINALs once the arguments converge. Watch the board with a Monitor that prints
each new message's subject. Read a message file only when its subject matters.
6. Close: first write the resolution to a file in the repo, then post `CLOSE` (saying what was accepted or changed)
and stop the monitor. `board notify` resumes finished members if the debate must continue.
## 7. Monitoring: keep your own context lean
**For the user: a live console.** Whenever agents are running and the user wants to watch them, open the built
console. Never write a one-off console script.
```
<!-- ‹guest · 2026-12-02› -->
fleet console # = agyconsole.bat <main repo>, in its own window
cmd //c "${CLAUDE_SKILL_DIR}/agyconsole.bat <repo>" # the same, for any repo (Windows)
python "${CLAUDE_SKILL_DIR}/agyconsole.py" <repo> # macOS/Linux: run it in a terminal
```
`agyconsole.py` is read-only over `.git/agy-fleet`, so it's safe to open at any time. It needs Textual
(`pip install textual`). It shows:
- one table row per agent;
- per-agent scrollable tabs: Activity, Plan, Files, Report, Board and Task;
- key `s` saves the screen as an SVG image to `.git/agy-fleet/screenshots/` (Ctrl+P → "Save screenshot" also works).
Reading every step of a Gemini run burns a lot of your tokens and rots your context. **Don't.**
- Routine: `wait --any` and `status` (one line per agent), then `validate` (a verdict plus reasons).
- `log <id>` (compact by default) shows the final report, the files written, denials and tool errors. Read
it when the final report is relevant.
- `log <id> --steps [--tail 20]` is the full step trace. **Use it only to trace a problem** (FAIL,
stalled, denied, a surprising diff). Start with `--tail`.
- Don't open the raw `.ndjson` files or `cat` worktree files wholesale. `diff --stat` first, then
targeted diffs.
## 8. Validation: never trust the agent's word or `status: SUCCESS`
`validate <id> [--test CMD]` fails on any of these: non-zero exit, no `result` event, stall or kill,
`denied_actions`, an empty response, self-reported `STATUS` not COMPLETE, **any recorded write outside the
worktree or granted paths**, board violations, wrong branch, no changes vs base, or test failure. It warns
about new dirt in the main checkout since spawn (a possible leak), commits made by the agent, tool errors,
whitespace/conflict markers, and missing STATUS lines.
PASS is necessary, not sufficient. Also:
- Review the diff against the task's acceptance criteria. Look for scope creep, deleted tests,
weakened assertions, hard-coded expected values, and TODO stubs.
- Run the project's real checks (tests, typecheck, lint, build) via `--test`, or yourself in the worktree.
- If a write audit flags leaks into the main checkout or elsewhere, **inspect and revert those files**
before anything else.
## 9. Recovery playbook
| Symptom | Action |
|---|---|
<!-- ‹guest · 2026-12-02› -->
| `denied` | Grant narrowly via `send --allow ...` or tell the agent to proceed without it |
| `stalled` | `log --steps --tail 15` to see the hung step; `send` with guidance, or re-spawn with a smaller task |
| `failed` / `crashed` | `log` (stderr is shown). Auth or quota errors: tell the user to run `! agy` and sign in |
| STATUS PARTIAL/BLOCKED | Read OPEN ISSUES; answer via `send`, or split the task |
| Tests fail | `send <id> --msg-file failures.md` with the exact failure output; then re-validate |
| Wrong approach | `kill`, then `cleanup --force`, and re-spawn with a sharper task (a new ID) |
| Out-of-scope writes | Revert them, then FAIL the agent; re-spawn with an explicit file list |
| "not under trustedWorkspaces" warning at spawn | Ask the user to add the `<repo>.agents` dir to `trustedWorkspaces` in `~/.gemini/antigravity-cli/settings.json`, or use `--worktree-root` under a trusted path |
| Research/review task with no diff | `validate <id> --no-changes-ok` |
`send` only works on a stopped agent, and keeps the conversation, worktree and rules. Use it rather than
re-spawning when the agent's context is valuable.
## 10. Hard rules
- Delegates never commit, push, merge or touch other worktrees. You do all VCS work, after review.
- Delegates can't run this helper. It refuses inside agent shells (agy exports `ANTIGRAVITY_*` and
the runner adds `AGYFLEET_DELEGATE_ID`; verified). Never grant agents access to `~/.claude` or
`.git/agy-fleet`. The only exception is the board directories, which the helper grants itself. Deny rules are
not the boundary here. The guard and the post-run audit are.
- Push to a remote only when the user asks.
- Clean up every worktree and branch you create (`status` lists leftovers). Use `cleanup --purge` to drop logs.
- If `agy` is missing or signed out, stop and ask the user to install it or run `! agy` to sign in.
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.