Metadata-Version: 2.5
Name: gvn
Version: 0.3.0
Summary: gvn (governor): an agent harness framework built on complete state machines.
Project-URL: Homepage, https://gvn-harness.dev
Project-URL: Documentation, https://gvn-harness.dev/paths/
Project-URL: Repository, https://github.com/humbertopoliti/gvn
Project-URL: Changelog, https://github.com/humbertopoliti/gvn/blob/main/CHANGELOG.md
Author: Humberto Politi
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: agents,harness,llm,state-machine,workflow
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.12
Provides-Extra: anthropic
Requires-Dist: anthropic>=2.9; extra == 'anthropic'
Provides-Extra: openai
Requires-Dist: openai>=3.51; extra == 'openai'
Provides-Extra: otel
Requires-Dist: opentelemetry-api>=1.27; extra == 'otel'
Provides-Extra: postgres
Requires-Dist: psycopg[binary,pool]>=3.2; extra == 'postgres'
Description-Content-Type: text/markdown

# gvn

**Agent harnesses built from state machines that are verified before they run.**

gvn ("governor") is a Python framework for building **agent harnesses**: the code around a
language model that decides when to call the model, which tools it may use, when a person
must approve, and what happens when something fails.

Every agent and workflow is an **actor** that follows a **state machine**, and gvn checks
that machine before it runs. Every non-final state needs a route or a fallback for every
declared input. gvn refuses to build a machine with a gap, and names the gap.

```bash
pip install gvn
```

gvn needs Python 3.12 or newer and has no runtime dependencies. Model vendors, PostgreSQL
and OpenTelemetry come as extras, for example `pip install "gvn[anthropic]"`.

## A first agent

This runs offline, with a scripted stand-in for the model and one tool.

```python
import asyncio

from gvn.harness.messages import Message, ToolCall
from gvn.harness.ports import Reply
from gvn.kernel.schema import Record, Text
from gvn.shortcuts import FunctionTool, run_agent
from gvn.testing.fakes import ScriptedModel


def order_status(order_id: str) -> dict[str, str]:
    return {"order_id": order_id, "status": "shipped"}


tool = FunctionTool(
    name="order_status",
    description="Look up an order's shipping status.",
    arguments=Record({"order_id": Text()}),
    function=order_status,
)
model = ScriptedModel(script=[
    Reply(message=Message.assistant(calls=[
        ToolCall(call_id="lookup-1", name="order_status", arguments={"order_id": "A-17"}),
    ])),
    Reply(message=Message.assistant(text="Order A-17 has shipped.")),
])

run = asyncio.run(run_agent(
    instructions="Look up the order before answering.",
    prompt="Where is order A-17?",
    model=model,
    tools=[tool],
))
assert run.outcome().payload()["tools"][0]["content"]["status"] == "shipped"
print(run.outcome().payload()["text"])
```

## What is in the package

| Module | What it holds |
|---|---|
| `gvn.kernel` | State machines, the verifier, decisions, durable objects and schemas |
| `gvn.harness` | The actors (agent, errand, approval, inquiry, choice, conversation, timer, workflow), tools and ports |
| `gvn.runtime` | The Governor, recovery, replay, inspection, forks, leases, allowances and throttles |
| `gvn.adapters` | Anthropic, OpenAI and Chat Completions models, SQLite and PostgreSQL journals, logs and traces |
| `gvn.evals` | Cases, criteria, judges, reports and comparisons, and the `gvn` command line |
| `gvn.testing` | Fakes for every port, so tests run offline |

## Documentation and source

- Documentation: <https://gvn-harness.dev>
- Source, issues and the other gvn packages: <https://github.com/humbertopoliti/gvn>
- Changelog: <https://github.com/humbertopoliti/gvn/blob/main/CHANGELOG.md>

## License

[Apache License 2.0](https://github.com/humbertopoliti/gvn/blob/main/LICENSE)
