# Docs for coding agents

This page is for an AI coding agent that has been handed a brief ("build a harness that
does X"), and for the person handing it over. It gives the model of gvn, the actor to
choose, the rules to get right, a complete file to start from, and the page for each task.
The [Markdown index](https://gvn-harness.dev/llms.txt) lists every page below as plain
Markdown and names the documented package version. Everything here runs offline on Python
3.12 or newer with `gvn` [installed](install.md#install-gvn).

## How gvn runs a harness

A **harness** is the program around a model: it calls the model, does the work and keeps
the records. In gvn it is made of these parts:

- An **actor** is a state machine that is checked before it runs. It only decides: given an
  **event** (something that happened, with data), it moves to its next state and says what
  it needs. It ends in one of its **final states**.
- A **request** is what an actor needs from outside: a model call, tool calls, a policy
  verdict, a person's answer. Each request has a **kind**, such as `invoke_model`.
- The **Governor** is the runtime. It drives a run forward one event at a time.
- A **fulfiller** does the work of one request kind and returns the result as an event.
- The **journal** is the Governor's record of every event, in order. The journal is the run.
- A request that no fulfiller serves is answered from outside. The run **parks** on it: it
  stops and waits, as data in the journal, until your code answers that request.

```text
event -> Governor -> actor -> request -> fulfiller -> event -> ... -> finished, with an outcome
                                      -> parked: waiting, with a pending request -> your code answers it
```

[The big picture](quickstart.md#the-big-picture) draws this, and
[What the recipes rely on](recipes.md#what-both-recipes-rely-on) shows parking and
answering as a sequence.

## Choose the actor

A **tool** is a function the harness may run. A **policy** gives each tool call a verdict
before it runs: `cleared`, `needs_approval` or `forbidden`.

| Actor | Use it when | Final states | Taught in | API |
|---|---|---|---|---|
| `run_agent` | One agent, run to the end in one call. The one-call form of `Agent`. | as `Agent` | [The short path](guides/shortcuts.md) | [`run_agent`](https://gvn-harness.dev/reference/python/shortcuts.md#run_agent) |
| `Agent` | A model picks the tool calls and writes the answer. | `completed`, `failed`, `overflowed` | [Adding a tool](tutorials/adding-a-tool.md) | [`Agent`](https://gvn-harness.dev/reference/python/harness.md#Agent) |
| `Errand` | Code fixes the tool calls, with no model: a payment, a write, a notification. | `done`, `failed`, `refused`, `declined` | [Errands](concepts/errands.md) | [`Errand`](https://gvn-harness.dev/reference/python/harness.md#Errand) |
| `Approval` | A person says yes or no to one named thing. | `approved`, `declined` | [An approval on its own](concepts/human-in-the-loop.md#an-approval-on-its-own) | [`Approval`](https://gvn-harness.dev/reference/python/harness.md#Approval) |
| `Inquiry` | A person answers a question with text or one of your choices. | `answered`, `withdrawn` | [Asking a person](concepts/asking-a-person.md) | [`Inquiry`](https://gvn-harness.dev/reference/python/harness.md#Inquiry) |
| `Choice` | A model picks one of a declared set of options, and the run branches on it. | `chosen`, `failed` | [Model-backed choices](guides/model-backed-choices.md) | [`Choice`](https://gvn-harness.dev/reference/python/harness.md#Choice) |
| `Conversation` | A model talks with a person over many turns, using tools. | `closed` (the outcome names the closing), `exhausted`, `left`, `failed`, `overflowed` | [A conversation](tutorials/conversation.md) | [`Conversation`](https://gvn-harness.dev/reference/python/harness.md#Conversation) |
| `Timer` | The run waits until a time. | `elapsed` | [Time](concepts/time.md#step-2-the-timer) | [`Timer`](https://gvn-harness.dev/reference/python/harness.md#Timer) |
| `Workflow` | Several of the actors above run as **stages** of a machine you write, in an order fixed by code. | the final states of your machine | [A workflow of two actors](tutorials/workflow.md) | [`Workflow`](https://gvn-harness.dev/reference/python/harness.md#Workflow) |

A brief with more than one step is a `Workflow`. Each step is a stage holding one of the
other actors: an `Agent` where a model must judge, an `Errand` where the effect is fixed.

## Rules of the framework

- **Declare, then build.** `.build()` on a blueprint runs the **verifier** and raises
  `DefinitionRejected` naming every finding, such as `incomplete s/stop`. Every non-final
  state needs a route or a fallback for each input.
  [Quickstart, step 1](quickstart.md#step-1-build-a-machine-and-let-gvn-find-the-gaps).
- **Tools are objects, never names.** `Agent(tools=[...])`, `Plan(tools=[...])`,
  `FixedCall(tool=...)` and `Rules().clear(...)` take `Tool` objects; a `str` is a
  `TypeError`. [Tools](concepts/tools.md#who-refers-to-tools-and-how).
- **A workflow has three parts.** The machine says which stage follows which; a `Host` says
  which actor a stage runs and what starts it; the `Plan` ties them together. Your class
  subclasses `Workflow` and returns the plan from the classmethod `plan()`.
  [Workflow tutorial](tutorials/workflow.md#step-1-the-workflows-own-machine).
- **A `Host` routes every ending.** `routes` names exactly the final states of the child's
  class (the table above), or `judge=` gives a `Decision` that reads the child's outcome.
  Exactly one of the two, else `ValueError`.
  [Judges](concepts/workflows-in-depth.md#judges-deciding-on-what-a-child-said).
- **A `Plan` is checked when constructed.** It raises `PlanRejected` listing every problem:
  a stage on the initial or a final state, or a route or judge outcome with no declared
  transition. [What a plan checks](concepts/workflows.md#deeper-what-a-plan-checks).
- **A `Plan` lists every child's tools.** `Plan(tools=[...])` names each tool any child is
  offered or calls. A child built with a tool the plan does not list is a `ValueError`.
  [Declared tools](concepts/workflows-in-depth.md#declared-tools).
- **Stages pass data through the memo.** `make(name, memo)` and `start(memo)` read
  `memo.input()` and `memo.results("stage")[0].payload()`; `Report(result.outcome())` reads
  the same afterwards. [The Memo](concepts/workflows-in-depth.md#the-memo-in-full).
- **Opening events.** `Agent` and `Choice` start on `Event("started", {"prompt": ...})`,
  `Inquiry` on `Event("started", {"question": ...})`, `Errand` and `Approval` on
  `Event("started")`. [Actors and events](concepts/actors-and-events.md).
- **Fulfillers are keyed by request kind.** `"invoke_model"`: `ModelFulfiller`;
  `"invoke_tools"`: `ToolFulfiller`; `"consult_policy"`: `PolicyFulfiller`. A kind that is
  neither fulfilled nor external raises `Unfulfillable`.
  [The fulfillers](concepts/governor.md#step-1-the-fulfillers).
- **Declaring a kind external makes the run park.** `Governor(external=["request_approval"])`
  for approvals, `"request_input"` for an `Inquiry` or `Conversation`. `deliver` then
  returns a result with `status() == "waiting"` and the request in `pending()`.
  [Tell the Governor who answers](tutorials/agent-with-approval.md#step-3-tell-the-governor-who-answers-approvals).
- **Answer the pending request.** `governor.answer(actor=..., request=..., event=...)`.
  Approve with `Event("approved")`, which carries no payload: `{}` is refused with
  `ValueError`. Deny one call with `Event("approved", {"denied": [{"call_id": ...,
  "reason": ...}]})`, all of them with `Event("denied")` or `Event("denied", {"reason":
  ...})`. [Approve](tutorials/agent-with-approval.md#step-5-approve).
- **A structured answer is a `Record`.** Pass `answer=Record({...})` to `Agent` or
  `run_agent`. Read the checked data from `outcome().payload()["answer"]`, or
  `AgentRun.answer()`. A reply that does not fit ends the agent `failed`. In tests,
  `answer_reply(data)` scripts such a reply. [Structured answers](guides/structured-answers.md).
- **Recovery finds a run by its name.** The actor's `name` is the run id.
  `await Recovery(journal).recover(run_id=..., actor_class=...)` rebuilds the actor; then
  answer its `pending()` request or call `governor.resume(actor=...)`. A workflow is
  rebuilt through its class, so `plan()` returns the same module-level `Plan` every time.
  [Crash and resume](tutorials/durability.md#step-5-approve-from-a-new-process).
- **Policies come from `gvn-tools`.** `from gvn_tools.rules import Rules`, then
  `Rules(default="forbidden").clear(tool).approve(other_tool)`. [Rules](tools/rules.md).
- **Three packages.** `gvn`: kernel, actors, Governor, adapters (`gvn.adapters.sqlite`,
  `gvn.adapters.anthropic`, `gvn.adapters.openai`) and the test kit. `gvn-tools`
  (`gvn_tools`): ready-made tools, `Rules`, MCP. `gvn-domains` (`gvn_domains`): complete
  example harnesses. [What you are installing](install.md#what-you-are-installing).
- **Tests run on fakes.** `gvn.testing.fakes` has `ScriptedModel`, `MemoryJournal`,
  `ManualClock`, `RecordingOutput` and `StubTool`.
  [Run it on fake ports](concepts/testing.md#step-2-run-it-on-fake-ports).

## Start from a complete file

Each file is tested with the docs and runs with `python <name>`. Download it from
`https://gvn-harness.dev/downloads/<name>`.

| File | What it demonstrates | Explained in |
|---|---|---|
| `first_agent.py` | `run_agent` with one tool and a scripted model | [Run your first agent](start.md#run-the-example) |
| `approve_tool.py` | An agent's tool call waits for a person, and the journal records who approved | [Approve a tool call](recipes.md#approve-a-tool-call) |
| `recover_inquiry.py` | An `Inquiry` parks in SQLite and a second Governor recovers and answers it | [Park and recover with SQLite](recipes.md#park-and-recover-with-sqlite) |
| `resume_approval.py` | An agent's pending approval survives a restart | [Agent approval across a restart](recipes.md#agent-approval-across-a-restart) |
| `check_agent_offline.py` | Offline tests for a `run_agent` harness | [Test an agent offline](recipes.md#test-an-agent-offline) |
| `claims_workflow.py` | A workflow on SQLite: an agent with a structured answer, a judge, then an `Errand` that needs approval | [A two-stage workflow](recipes.md#a-two-stage-workflow) |

## The build, verify, test loop

1. **Declare.** Write the tools, the policy, each actor and, for a workflow, the machine,
   the `Host` stages and the `Plan`. [Workflow tutorial, steps 1 to 3](tutorials/workflow.md#step-1-the-workflows-own-machine).
2. **Let the verifier reject the gaps.** Import the module. `.build()`, `Host(...)` and
   `Plan(...)` raise with the missing cases named; route each one.
   [Forget one answer](tutorials/decisions-and-branching.md#step-2-route-the-decision-and-forget-one-answer).
3. **Run it on a scripted model.** Give `ScriptedModel` the replies in the order the stages
   ask for them, and wire the Governor with `MemoryJournal`, `ManualClock` and
   `RecordingOutput`. [Test a whole run](tutorials/testing.md#step-3-test-a-whole-run-with-a-stub-tool).
4. **Assert the result and the effects.** Check `result.status()`, `result.pending()` and
   `result.outcome().state()`, and check that a tool with an effect ran exactly when it
   should: not while the run waits, once after approval.
   [Run until a person is needed](tutorials/agent-with-approval.md#step-4-run-until-a-person-is-needed).
5. **Swap in a vendor model.** Replace `ScriptedModel` with `AnthropicModel` or
   `OpenAIModel` in `ModelFulfiller`; nothing else changes.
   [Use it where the fake was](guides/vendors.md#step-4-use-it-where-the-fake-was).

## Find the page for a task

| Task | Read |
|---|---|
| A tool that needs a person's approval | [A policy, and approval by a person](tutorials/agent-with-approval.md) |
| A policy from a few rules | [Rules](tools/rules.md) |
| Structured output from a model | [Structured answers](guides/structured-answers.md) |
| Several steps in a fixed order | [A workflow of two actors](tutorials/workflow.md), [Workflows](concepts/workflows.md), [Workflows in depth](concepts/workflows-in-depth.md) |
| An effect chosen by code | [Errands](concepts/errands.md) |
| Branch on a model's choice | [Model-backed choices](guides/model-backed-choices.md) |
| Branch on data from a stage | [Judges](concepts/workflows-in-depth.md#judges-deciding-on-what-a-child-said) |
| Fan out over items or branches | [Fan-out over items, with retries](guides/items-and-retries.md), [Different kinds of child in one stage](guides/mixed-stages.md) |
| A deadline on a stage | [A deadline](tutorials/deadline.md) |
| Survive a crash or a restart | [The journal: crash and resume](tutorials/durability.md), [Recovery guarantees](reference/runtime-guarantees.md#recovery) |
| Run as a service with several processes | [Running gvn as a service](guides/running-as-a-service.md) |
| A real model | [Using a vendor model](guides/vendors.md), [A real model and ready-made tools](tutorials/real-model.md) |
| Logs, traces and streams | [Logs, traces and streams](guides/observability.md) |
| Tests | [Testing your harness](tutorials/testing.md), [Testing concepts](concepts/testing.md), [Testing with the tools](tools/testing.md) |
| Evals | [Evals](evals/index.md), [Your first eval](evals/first-eval.md) |
| MCP servers | [MCP servers](tools/mcp.md) |
| Ready-made tools: files, shell, Git, web | [Tools](tools/index.md) |
| Complete harnesses to read | [Domains](domains/index.md) |

## Build a harness from a brief

Replace the marked line with your brief and give the prompt to your coding agent.

```text { .agent-prompt data-copy-label="Copy harness brief prompt" }
Build a gvn harness for this brief:

<<< REPLACE THIS LINE WITH YOUR BRIEF >>>

Read https://gvn-harness.dev/llms.txt and https://gvn-harness.dev/for-agents.md first.
Compare the documented version with python -m pip show gvn. If gvn is unavailable, report
the missing prerequisite.

1. Pick the actors with the "Choose the actor" table. Use a Workflow when the brief has
   more than one step, an Errand for an effect that code fixes, and an approval wherever
   the brief says a person must agree.
2. Start from the nearest complete file under "Start from a complete file". Download it
   and adapt it; follow "Rules of the framework" for every change.
3. Keep everything offline: ScriptedModel, ManualClock, no API keys, no network. Use
   SqliteJournal when the brief asks for runs that survive a restart.
4. Import the module and fix every finding the verifier names. Then write tests that
   check the status, the pending request, the outcome and each tool's side effects,
   including that nothing with an effect runs before its approval.
5. Run the tests until they pass.

Report the verifier result, the test output, the files changed, and the exact change that
switches the scripted model for a real one.
```

## First-run prompts

These four prompts are for a first offline run: each builds the one-agent example in
`first_agent.py`.

## Generic prompt

```text { .agent-prompt data-copy-label="Copy generic prompt" }
Build the offline order-status example in first_agent.py. Use Python 3.12 or newer.
Check the installed gvn version with python -m pip show gvn and compare it with
https://gvn-harness.dev/llms.txt. If gvn is unavailable, report the missing prerequisite.

Use https://gvn-harness.dev/start.md and the tested file at
https://gvn-harness.dev/downloads/first_agent.py. Keep the scripted model and the
assertion that the tool ran. Run python first_agent.py and report the output and files
changed. Use no API keys or outside services for the example.
```

## Codex

```text { .agent-prompt data-copy-label="Copy Codex prompt" }
In the current workspace, create first_agent.py from the tested offline recipe. Read
https://gvn-harness.dev/llms.txt and https://gvn-harness.dev/start.md. Compare the documented
version with the installed gvn version. If gvn is unavailable, report the missing prerequisite.

Use https://gvn-harness.dev/downloads/first_agent.py as the reference. Preserve unrelated
worktree changes, run python first_agent.py from the workspace with gvn installed, and
report the files changed and the exact result. Keep the tool assertion and scripted model.
```

## Claude Code

```text { .agent-prompt data-copy-label="Copy Claude Code prompt" }
Read the current project's instructions and https://gvn-harness.dev/llms.txt. Use
https://gvn-harness.dev/start.md to add an offline first_agent.py to the project.
Use https://gvn-harness.dev/downloads/first_agent.py as the complete baseline. Match the
docs to the installed gvn version, or report that gvn is missing.

Check from the terminal with python first_agent.py. Report the tool assertion and stdout.
Use the scripted model and avoid adding credentials, dependencies, or network calls.
```

## Cursor

```text { .agent-prompt data-copy-label="Copy Cursor prompt" }
Use the open project as context. Read https://gvn-harness.dev/llms.txt and
https://gvn-harness.dev/start.md, then confirm the installed gvn version. If gvn is
unavailable, report the missing prerequisite. Propose first_agent.py using the tested script at
https://gvn-harness.dev/downloads/first_agent.py.

Keep the change reviewable as a single file. Run python first_agent.py in the workspace
terminal with gvn already installed. Show the exact output and the assertion that the
order-status tool ran. Use the scripted model without credentials or outside services.
```
