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 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.
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.
event -> Governor -> actor -> request -> fulfiller -> event -> ... -> finished, with an outcome
-> parked: waiting, with a pending request -> your code answers it
The big picture draws this, and What the 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 | run_agent |
Agent |
A model picks the tool calls and writes the answer. | completed, failed, overflowed |
Adding a tool | Agent |
Errand |
Code fixes the tool calls, with no model: a payment, a write, a notification. | done, failed, refused, declined |
Errands | Errand |
Approval |
A person says yes or no to one named thing. | approved, declined |
An approval on its own | Approval |
Inquiry |
A person answers a question with text or one of your choices. | answered, withdrawn |
Asking a person | Inquiry |
Choice |
A model picks one of a declared set of options, and the run branches on it. | chosen, failed |
Model-backed choices | 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 | Conversation |
Timer |
The run waits until a time. | elapsed |
Time | 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 | 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 raisesDefinitionRejectednaming every finding, such asincomplete s/stop. Every non-final state needs a route or a fallback for each input. Quickstart, step 1. - Tools are objects, never names.
Agent(tools=[...]),Plan(tools=[...]),FixedCall(tool=...)andRules().clear(...)takeToolobjects; astris aTypeError. Tools. - A workflow has three parts. The machine says which stage follows which; a
Hostsays which actor a stage runs and what starts it; thePlanties them together. Your class subclassesWorkflowand returns the plan from the classmethodplan(). Workflow tutorial. - A
Hostroutes every ending.routesnames exactly the final states of the child's class (the table above), orjudge=gives aDecisionthat reads the child's outcome. Exactly one of the two, elseValueError. Judges. - A
Planis checked when constructed. It raisesPlanRejectedlisting 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. - A
Planlists 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 aValueError. Declared tools. - Stages pass data through the memo.
make(name, memo)andstart(memo)readmemo.input()andmemo.results("stage")[0].payload();Report(result.outcome())reads the same afterwards. The Memo. - Opening events.
AgentandChoicestart onEvent("started", {"prompt": ...}),InquiryonEvent("started", {"question": ...}),ErrandandApprovalonEvent("started"). Actors and events. - Fulfillers are keyed by request kind.
"invoke_model":ModelFulfiller;"invoke_tools":ToolFulfiller;"consult_policy":PolicyFulfiller. A kind that is neither fulfilled nor external raisesUnfulfillable. The fulfillers. - Declaring a kind external makes the run park.
Governor(external=["request_approval"])for approvals,"request_input"for anInquiryorConversation.deliverthen returns a result withstatus() == "waiting"and the request inpending(). Tell the Governor who answers. - Answer the pending request.
governor.answer(actor=..., request=..., event=...). Approve withEvent("approved"), which carries no payload:{}is refused withValueError. Deny one call withEvent("approved", {"denied": [{"call_id": ..., "reason": ...}]}), all of them withEvent("denied")orEvent("denied", {"reason": ...}). Approve. - A structured answer is a
Record. Passanswer=Record({...})toAgentorrun_agent. Read the checked data fromoutcome().payload()["answer"], orAgentRun.answer(). A reply that does not fit ends the agentfailed. In tests,answer_reply(data)scripts such a reply. Structured answers. - Recovery finds a run by its name. The actor's
nameis the run id.await Recovery(journal).recover(run_id=..., actor_class=...)rebuilds the actor; then answer itspending()request or callgovernor.resume(actor=...). A workflow is rebuilt through its class, soplan()returns the same module-levelPlanevery time. Crash and resume. - Policies come from
gvn-tools.from gvn_tools.rules import Rules, thenRules(default="forbidden").clear(tool).approve(other_tool). Rules. - 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. - Tests run on fakes.
gvn.testing.fakeshasScriptedModel,MemoryJournal,ManualClock,RecordingOutputandStubTool. 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 |
approve_tool.py |
An agent's tool call waits for a person, and the journal records who approved | 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 |
resume_approval.py |
An agent's pending approval survives a restart | Agent approval across a restart |
check_agent_offline.py |
Offline tests for a run_agent harness |
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 |
The build, verify, test loop¶
- Declare. Write the tools, the policy, each actor and, for a workflow, the machine,
the
Hoststages and thePlan. Workflow tutorial, steps 1 to 3. - Let the verifier reject the gaps. Import the module.
.build(),Host(...)andPlan(...)raise with the missing cases named; route each one. Forget one answer. - Run it on a scripted model. Give
ScriptedModelthe replies in the order the stages ask for them, and wire the Governor withMemoryJournal,ManualClockandRecordingOutput. Test a whole run. - Assert the result and the effects. Check
result.status(),result.pending()andresult.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. - Swap in a vendor model. Replace
ScriptedModelwithAnthropicModelorOpenAIModelinModelFulfiller; nothing else changes. 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 |
| A policy from a few rules | Rules |
| Structured output from a model | Structured answers |
| Several steps in a fixed order | A workflow of two actors, Workflows, Workflows in depth |
| An effect chosen by code | Errands |
| Branch on a model's choice | Model-backed choices |
| Branch on data from a stage | Judges |
| Fan out over items or branches | Fan-out over items, with retries, Different kinds of child in one stage |
| A deadline on a stage | A deadline |
| Survive a crash or a restart | The journal: crash and resume, Recovery guarantees |
| Run as a service with several processes | Running gvn as a service |
| A real model | Using a vendor model, A real model and ready-made tools |
| Logs, traces and streams | Logs, traces and streams |
| Tests | Testing your harness, Testing concepts, Testing with the tools |
| Evals | Evals, Your first eval |
| MCP servers | MCP servers |
| Ready-made tools: files, shell, Git, web | Tools |
| Complete harnesses to read | Domains |
Build a harness from a brief¶
Replace the marked line with your brief and give the prompt to your coding agent.
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¶
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¶
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¶
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¶
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.