> ## Documentation Index
> Fetch the complete documentation index at: https://docs.algovoi.co.uk/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent Guard

> A spend budget an AI agent cannot raise itself: a human-signed mandate, fail-closed pre-execution checks, and receipts anyone can recompute offline. Free, Apache-2.0, runnable in one command.

[![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/chopmob-cloud/algovoi-agent-guard/blob/master/LICENSE)

**The budget your agent can't raise.** A human signs a spend mandate. The agent holds its own key but never the human's. Every charge is checked fail-closed *before* execution, and every decision produces a receipt anyone can recompute offline from public material — no mediator signature required. Then an adversary — a live AI model, a human red-teamer, an authored attack file, or a seeded fuzzer — tries to break it, and you watch every attack fail.

> [!NOTE]
>
> **Free and Apache-2.0.** Install via `pip install algovoi-agent-guard` (only dependency: `cryptography>=42`). A TypeScript port is published as [`algovoi-agent-guard`](https://www.npmjs.com/package/algovoi-agent-guard) on npm. This is a runnable reference, not a deployed service; **no production adoption is claimed**. It moves no funds.

## Try it

**1. Install**

```bash theme={null}
pip install algovoi-agent-guard
```

**2. Run the rogue-agent demo**

```bash theme={null}
algovoi-agent-guard demo --outdir ./demo
```

A forged mandate, a replay, a forged countersign, a ledger rewrite and a foreign payee are each denied or detected, while an honest charge is ALLOWed and recomputes offline. The run ends `DEMO PASSED` and writes its evidence artefacts to `./demo`.

**3. Run the red-team**

```bash theme={null}
algovoi-agent-guard redteam --adversary fuzz --seed 7 --attacks 20 --outdir ./rt
```

A deterministic attack battery plus a pluggable adversary. Every attack is executed against the real guard, its receipt recomputed offline, and checked against an **independent** policy predicate — the security claim never rests on the adversary's verdict.

A commented, self-contained starter lives at [`examples/quickstart.py`](https://github.com/chopmob-cloud/algovoi-agent-guard/blob/master/examples/quickstart.py): issue a human-signed mandate, countersign a charge, verify the receipt offline, bind it to settlement, and watch a foreign payee denied.

## The one claim

Pre-execution **monetary** spend authority under a **human key the agent never holds**, with receipts **recomputable offline** from public material. It stops an agent raising its own budget *before* the money moves, and lets a third party recompute the monetary receipt without trusting a mediator.

## How it works

* **Mandate** — a human-signed envelope; `mandate_ref = sha256(JCS({cap, payer, period, revocation_state}))` over a frozen, float-free RFC 8785 JCS form.
* **Guard** — a pure `evaluate()` shared by enforcement and verification; checks authority binding → validity → payee → scope → per-charge cap → period cap → replay → human countersign bound to the exact intent. `set_envelope` refuses any envelope with a different human key or payer.
* **Receipts** — `guardrail_ref = sha256(JCS({agent_ref, mandate_ref, policy_bound_ref, verdict}))`; recomputable, not mediator-signed. DENY receipts embed the presented countersign.
* **Ledger** — a single-writer hash chain with full-history rewrite and atomic `os.replace`; a failed commit is a final DENY, never an uncommitted ALLOW.

## The red-team is negative-controlled

The adversary supplies creativity; the deterministic guard and an independent violation predicate supply the guarantee. The harness is itself proven to detect a bypass: [`tests/test_redteam_negative_control.py`](https://github.com/chopmob-cloud/algovoi-agent-guard/blob/master/tests/test_redteam_negative_control.py) shows a deliberately fail-open guard is caught and the run FAILED, while the real guard DENIES the identical charge. A red-team that cannot detect a bypass is hollow; this one is proven to detect one.

The default adversary is a live AI model (any OpenAI-compatible provider you configure); `--adversary` also accepts a human red-teamer, an authored attack file, or a seeded fuzzer. A model that refuses the adversary role is recorded as `refused`.

## Honest limits

* **Ed25519 only** in this public format. The commercial post-quantum engine is a separate product and is not reimplemented here.
* The guard **moves no funds**; it is an enforcement + verification layer emitting canonical refs for a settlement rail.
* The ledger is a single-writer chain, **not** distributed consensus.
* The red-team guarantee rests on the deterministic guard + independent predicate, **not** the LLM.
* **No production adoption is claimed.** This is a runnable reference, not a deployed service.
* A zero-bypass result covers only the attacks actually run against the mandate shape exercised — **not a proof of security**.
* Replay is exact-`charge_id`: an agent can mint id variants (whitespace, zero-width) to dodge replay, but every charge still counts against the period cap, so total spend stays bounded. The cap is the monetary backstop.

Full terms: [`DISCLAIMER.md`](https://github.com/chopmob-cloud/algovoi-agent-guard/blob/master/DISCLAIMER.md). No warranty; Apache-2.0.

## Conformance and composition

Zero AlgoVoi runtime dependencies (`cryptography>=42` only). Agent Guard emits the keystone `mandate` step (`order 2`, `canon_version: jcs-rfc8785-v1`) and refs byte-identical to the published [conformance vectors](https://github.com/chopmob-cloud/algovoi-jcs-conformance-vectors) (28 vector tests), so it composes with [`algovoi-fabric`](https://github.com/chopmob-cloud/algovoi-fabric) by construction. It also bolts into [`algovoi-secure-hub`](https://github.com/chopmob-cloud/algovoi-secure-hub) as a spend-authority service via a thin wrapper exposing `/health` reflecting a live enforcement self-check.

The suite is 256 tests: frozen-vector conformance, guard enforcement, red-team and countersign negative controls, per-adversary lane tests, and a fault-tolerance / error-correction suite. Each load-bearing property has an isolating mutation probe that fails a dedicated test when disabled.

## Relationship to the estate

Agent Guard is the free, standalone entry point to the AlgoVoi spend-authority stack. It sits on the open [JCS Canonicalisation Substrate](https://docs.algovoi.co.uk/canonicalisation-substrate.md) and shares the `guardrail_ref` construction with [Spend Guardrail (lite)](https://docs.algovoi.co.uk/spend-guardrail-lite.md); the commercial [Spend Guardrail](https://docs.algovoi.co.uk/spend-guardrail.md) adds post-quantum signing and the full [Agent Passport](https://docs.algovoi.co.uk/agent-passport.md) + [Payment Mandate](https://docs.algovoi.co.uk/payment-mandate.md) enforcement stack.

## Source

* Python: [chopmob-cloud/algovoi-agent-guard](https://github.com/chopmob-cloud/algovoi-agent-guard)
* TypeScript: [chopmob-cloud/algovoi-agent-guard-ts](https://github.com/chopmob-cloud/algovoi-agent-guard-ts)
* Evidence (captured clean-room run, raw logs): [`docs/evidence/EVIDENCE.md`](https://github.com/chopmob-cloud/algovoi-agent-guard/blob/master/docs/evidence/EVIDENCE.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.