# agengo user guide
This is the complete reference for agengo 0.3. It covers installation, the plan format, every CLI command, the workflow and its states, how to answer requests, quality gates, storage and cleanup, the adapter protocol, security limits and testing. For an overview, start with the [README](../README.md). Terms are defined in the [glossary](glossary.md). A Vietnamese translation is available: [docs/vi/huong-dan.md](vi/huong-dan.md).
**Contents:** [Requirements](#requirements) · [Quick start](#quick-start) · [Plan format](#plan-format) · [Commands](#commands) · [Workflow and states](#workflow-and-states) · [Answering requests](#answering-requests) · [Quality gates](#quality-gates) · [Storage and cleanup](#storage-and-cleanup) · [Adapter protocol](#adapter-protocol) · [Security](#security-limits) · [Testing](#testing)
## Requirements
- Linux or macOS. Windows is not supported natively, because agengo relies on process groups and POSIX APIs. Use WSL instead.
- To build from source only: Rust/Cargo 1.90+ and a C compiler (for the bundled SQLite).
- Git 2.31+ with `user.name` and `user.email` configured.
- One of:
- [Claude Code](https://claude.com/claude-code) on `PATH` and logged in; or
- your own adapter passed with `--agent <executable>` (see [Adapter protocol](#adapter-protocol)).
Install a prebuilt binary (Linux and macOS, x64 and arm64) with npm or the shell installer, or build from source:
```bash
npm install -g agengo # Node.js 14.18+; or run without installing: npx agengo --help
cargo install --path . --locked # from a local checkout
agengo --help
```
npm and the shell installer download the binary for your platform from the GitHub Release of that version and check its SHA-256 checksum.
## Quick start
1. Write `plan.yaml`, or let the agent draft one with `agengo plan --goal "..." --format yaml > plan.yaml`.
```yaml
schema_version: 1
goal: Add a greeting command
tasks:
- id: greet
title: Greeting helper
goal: Add greet(name) to src/greet.py returning "Hello, <name>!".
owns: [src/greet.py, tests/test_greet.py]
acceptance: ["greet('An') returns 'Hello, An!'"]
verify: [["python3", "-m", "pytest", "-q", "tests/test_greet.py"]]
- id: cli
goal: Expose greet through `python3 -m app NAME`.
depends: [greet]
owns: [src/app]
acceptance: ["python3 -m app An prints Hello, An!"]
verify: [["python3", "-m", "pytest", "-q"]]
final_verify: [["python3", "-m", "pytest", "-q"]]
```
2. Validate the plan without calling an agent: `agengo plan --file plan.yaml --brief`.
3. Run it: `agengo run plan.yaml --id demo --jobs 2`. Add `--await-approval` if you want to approve the plan before any agent starts.
4. Follow progress with `agengo status demo` and `agengo inbox demo`. Each request that needs you comes with the exact `agengo respond ...` command.
5. When the run prints `[DELIVERED]`, inspect the result with `git log af/demo`, then merge it yourself.
Exit codes: `0` delivered · `2` waiting for your answer (run `resume` after answering) · `1` error · `130` interrupted with Ctrl‑C (run `resume` to continue).
## Plan format
A plan is YAML or JSON, validated against [specs/plan.schema.json](../specs/plan.schema.json). agengo rejects unknown fields, dependency cycles and paths outside the repository.
| Field | Required | Meaning |
|---|---|---|
| `goal` | ✔ | Overall goal of the run |
| `tasks[].id` | ✔ | 1–64 characters from `A-Z a-z 0-9 _ -`, unique |
| `tasks[].goal`, `title` | goal ✔ | Instructions for the agent / short title for people |
| `tasks[].owns` | ✔ | Files or directories, relative to the repository root, that the Builder may change. Changes outside this scope are rejected. Tasks with overlapping `owns` never run in parallel |
| `tasks[].acceptance` | ✔ | Acceptance criteria, as strings or `{id, text}`. Strings get the IDs `AC-1`, `AC-2`, … |
| `tasks[].verify` | ✔ | argv commands, run on the candidate before review and again at integration |
| `tasks[].depends` | | Tasks that must be integrated first |
| `tasks[].setup` | | Commands that prepare this task's worktrees, in addition to the shared `setup` |
| `tasks[].dependency_context`, `related_to` | | Explain relationships to the agent (`needed_for` / `reason`, `refs`) |
| `setup` | | Commands that prepare every worktree, for example `[["npm","ci"]]` |
| `integration_verify` | | Commands run after every integration |
| `final_verify` | ✔ | Commands run on the final branch before delivery |
| `quality` | | See [Quality gates](#quality-gates) |
Commands are always argv arrays (`["cmd", "arg"]`) and never go through a shell. Use `["sh", "-c", "..."]` if you need shell syntax.
## Commands
| Command | Purpose |
|---|---|
| `plan --file F` / `--goal G` / `--from F` | Validate a plan, or have the agent draft one (`--brief`, `--format yaml`, `--context`) |
| `run PLAN [--id ID] [--jobs N] [--base REV]` | Start a run. Other options: `--review-limit` (default 3), `--gate-limit` (default 2), `--timeout` seconds per agent attempt (default 900), `--builder-handoff worktree\|commit`, `--agent`, `--roles`, `--await-approval` |
| `resume ID` | Continue or recover a run |
| `resume ID --task T` / `pause ID --task T` | Unpause / pause one task |
| `status ID [--json]` | Plan, task states, requests and evidence (`--json` includes every attempt's request and result) |
| `inbox ID [--json]` | Pending requests, each with the command that answers it |
| `respond ID Y-xx ...` | Answer a request (see below) |
| `resolve ID T --note N` | Record guidance and reopen a blocked task |
| `amend ID PLAN --note N` | Approve a new plan revision (only tasks that have not started or are blocked may change) |
| `metrics ID [--json]` | Time, tokens and cost per role, per task and in total; rework count |
| `clean ID` | Remove the run's worktrees, and its temporary refs once the run is delivered |
| `roles [--file F]` | Validate a custom role catalog and its prompts |
`-C <dir>` selects the repository; the default is the current directory.
## Workflow and states
```
pending → building → [verifying] → ready_review → reviewing → passed → integrated
↘───────────────── blocked (waiting for you) ─────────────────↙
```
1. **Build.** The Builder works in a fresh worktree on branch `af-work/<run>/<task>/<attempt>`. There are two handoff modes:
- `worktree` (default with Claude Code): the Builder only edits files. agengo captures the changes as a commit and pins it at `refs/agent-flow/builds/...`.
- `commit` (default with `--agent`): the Builder commits to its assigned branch.
2. **Verify.** The task's `setup` and `verify` commands run on the candidate commit in a clean worktree. The Reviewer only sees commits that pass.
3. **Review.** The Reviewer must report on exactly the SHA it was given. Requested changes become findings (`F-01`, …) that the next Builder attempt receives. After `--review-limit` rounds, the run asks you.
4. **Integrate.** agengo runs `merge --no-ff` into `af/<run>`, then the task's `verify` and `integration_verify`. Integration failures go back to the Builder; after `--gate-limit` failures, the run asks you.
5. **Final checks.** `setup`, `final_verify`, `quality.checks`, the duplicate gate and the optional whole-branch review run on the final branch. If they pass, agengo delivers and cleans up.
All state lives in SQLite. If agengo is interrupted at any point, even in the middle of an integration, `resume` continues from exactly there. A file lock ensures only one coordinator runs per run.
## Answering requests
Every request has a `Y-xx` code. `status`, `inbox` and notices print a `Command — ...` line you can copy.
| Kind | When | How to answer |
|---|---|---|
| `approval` | `run --await-approval` | `respond ID Y-xx --choice approve` (or `reject`) |
| `decision` | Review or integration limit reached; the Builder needs a choice; **an agent incident** (crash, timeout, reply that breaks the contract); final checks failed | `--choice A --note "guidance"` to retry under the current plan, or `--choice B --note "reason" --plan new-plan.yaml` to approve a new plan |
| `action` | A missing external prerequisite, for example an uninstalled check command or Claude Code not logged in | Do it, then `respond ID Y-xx --note "installed ..."` |
| `information` | The agent needs more information | `respond ID Y-xx --note "answer"` |
After answering, run `agengo resume ID`.
## Quality gates
```yaml
quality:
python_duplicates: warn # off | warn (default) | block
ignore_paths: [vendor] # skipped by the duplicate search
checks: [["ruff", "check", "."]] # extra commands for the final checks
review: false # true: add a whole-branch review
```
**Python duplicates** compares syntax fingerprints (tree-sitter) of functions. Parameter and local variable names are normalized, so a copied function with renamed variables is still found. Functions that only store values into attributes (`self.x = x` boilerplate in `__init__`) are ignored. Only new duplicates, or more copies than at `base`, count.
- `warn`: records the result in the `quality_duplicates` attempt and still delivers, with a warning.
- `block`: checks at **every integration**, so the Builder of the task that adds a duplicate has to fix it. At the final checks, duplicates block delivery.
- `true`/`false` from 0.2.x plans are still accepted and mean `block`/`off`.
## Storage and cleanup
| State and evidence | `.git/agent-flow/state.sqlite3` (shared by all worktrees of the repository) |
| Agent worktrees | `~/.cache/agengo/worktrees/<repo>-<id>/<run>/<step>/<attempt>`. Precedence: `$AGENGO_WORKTREES`, then `$XDG_CACHE_HOME/agengo/worktrees`. The location chosen first is recorded in `.git/agent-flow/worktree-root` |
| Result branch | `refs/heads/af/<run>` |
| Temporary refs | `refs/heads/af-work/<run>/…`, `refs/agent-flow/builds/<run>/…` |
Worktrees live **outside `.git`**, because Claude Code refuses to write below `.git/`. Each step's worktree is removed as soon as the step finishes, except a blocked Builder's worktree, which is kept for inspection. On delivery, agengo removes all of the run's worktrees and temporary refs. `agengo clean ID` cleans up manually; for a run that is not delivered it keeps the temporary refs, because unfinished tasks still need those commits.
## Adapter protocol
With `--agent <exe>`, agengo runs `<exe>` once per attempt, with the assigned worktree as the working directory. The request is one JSON document on **stdin**, following [specs/request.schema.json](../specs/request.schema.json). The adapter prints exactly one JSON document on **stdout**, following [specs/outcome.schema.json](../specs/outcome.schema.json) (the `plan` role follows [specs/planner-output.schema.json](../specs/planner-output.schema.json)). Environment variables are inherited from agengo.
Main request fields: `role` (`plan`/`build`/`review`), `run_id`, `attempt_id`, `plan_revision`, `task` (id, goal, owns, acceptance, verify, …), `head`, `base`, `integration_sha`, `worktree`, `builder_handoff`, `merge_parent` (when present), `feedback`, `decisions`, `context` (`acceptance`, `decisions`, `open_findings`) and `relationships`.
Result:
```json
{"status": "done", "head": "<sha>", "summary": "…", "blocker": null,
"findings": [], "finding_resolutions": [], "resolved_conflicts": []}
```
- Builder, `commit` mode: `done` with the new HEAD SHA (clean worktree, unchanged branch). `worktree` mode: `ready` with `head` set to the starting commit, and the index untouched.
- Reviewer: `pass` or `changes_requested`, with `head` equal to the SHA it was given. New findings go in `findings` with an `acceptance_id`; existing findings are answered in `finding_resolutions`.
- Any role may return `blocked` with a `blocker` (`action`/`decision`/`information`). agengo turns it into a `Y-xx` request.
- A non-zero exit, output that is not JSON, or exceeding `--timeout` is an incident: the task is blocked with a `decision` request.
A complete reference adapter lives in [`tests/support/mod.rs`](../tests/support/mod.rs) (function `adapter`).
### Token and cost usage (optional)
An adapter may add a top-level `usage` object next to `status`, following [specs/usage.schema.json](../specs/usage.schema.json). agengo stores it per attempt, shows it in `status --json`, and totals it in `agengo metrics` per role, per task and per run.
```json
{"status": "done", "head": "<sha>", "summary": "…", "blocker": null,
"findings": [], "finding_resolutions": [], "resolved_conflicts": [],
"usage": {"input_tokens": 1200, "output_tokens": 300, "cache_read_tokens": 0,
"cache_write_tokens": 0, "cost_usd": 0.012, "model": "my-model"}}
```
- Every field is optional. Fields with the wrong type or a negative value are dropped; an attempt never fails because of usage data.
- `input_tokens` counts input that was **not** read from a cache.
- agengo never prices tokens itself. If the adapter knows the cost, it fills in `cost_usd`.
- Attempts that report no `usage` are shown as "no usage", not as 0. Attempts killed by a timeout have no usage.
- For Claude Code, agengo reads `usage`, `total_cost_usd` and `modelUsage` from the `claude -p` JSON automatically.
Mapping from common providers (field names as in each provider's API):
| `input_tokens` | `input_tokens` | `prompt_tokens − prompt_tokens_details.cached_tokens` | `input_tokens − input_tokens_details.cached_tokens` | `promptTokenCount − cachedContentTokenCount` | `prompt_eval_count` |
| `output_tokens` | `output_tokens` | `completion_tokens` | `output_tokens` | `candidatesTokenCount + thoughtsTokenCount` | `eval_count` |
| `cache_read_tokens` | `cache_read_input_tokens` | `prompt_tokens_details.cached_tokens` | `input_tokens_details.cached_tokens` | `cachedContentTokenCount` | — |
| `cache_write_tokens` | `cache_creation_input_tokens` | — | — | — | — |
If your agent calls a model several times in one attempt, sum the values before returning them.
### Claude Code
Without `--agent`, agengo runs `claude -p --output-format json --json-schema … --strict-mcp-config` with the prompts in [specs/prompts](../specs/prompts). Print mode has nobody to approve permission prompts, so permissions are granted per role:
| plan | Read, Grep, Glob | `default` (read-only) |
| build | Read, Grep, Glob, Edit, Write, Bash | `acceptEdits`, plus `Bash` allowed |
| review | Read, Grep, Glob, Bash | `default`, plus `Bash` allowed |
Prompts can be replaced with `--roles path/roles.yaml` (see [specs/roles.yaml](../specs/roles.yaml); validate with `agengo roles --file ...`).
## Security limits
- Plan commands (`setup`, `verify`, …) run with your permissions. Only run plans you have read; `--await-approval` enforces an approval step.
- The Builder and Reviewer can use Bash and are **not sandboxed**. Worktrees separate the working directory but share `.git` with the repository, so an agent could in principle read or change refs and the state file. The checks after every attempt (HEAD, index, `owns` scope, SHA, the `af/<run>` ref) catch most deviations but do not replace a sandbox. For untrusted code or agents, run agengo inside a container or VM.
- Child processes inherit your full environment, including tokens.
- agengo never pushes and never changes your current branch.
## Testing
```bash
cargo test --locked # unit tests + system tests with a simulated agent
AGENGO_CLAUDE_E2E=1 cargo test --locked --test system # plus one real Claude Code run (uses API credits)
```
`tests/support/mod.rs` builds temporary Git repositories and a simulated adapter; scenarios are selected with `AGENGO_SYSTEM_TEST_SCENARIO`. See [CHANGELOG.md](../CHANGELOG.md) for release history.