Skip to content
Mandate

The Warden

The Mandate Warden is an HTTP gateway that sits between an agent and the Fly.io Sprites connectors. It runs on its own Sprite, the only one allowed to use the connectors. The agent runs on a second Sprite whose network is locked so it can only reach the Warden.

For each call, the Warden:

  1. Recovers which agent signed the request.
  2. Classifies the call into an action, a resource and (sometimes) a recipient.
  3. Asks mandate-core whether the agent's mandates allow it.
  4. On a deny, answers 403 with a reason. On an allow, forwards the call through the connector, which attaches the real credential. The Warden never holds a GitHub or Ollama token.

Every decision is written to a log that the dashboard and GET /v1/state read.

HTTP API

RouteAuthWhat it does
GET /noneThe live dashboard: the path every call takes, decisions, mandates, owner controls, and a "Try to break it" panel that sends unsigned, forged and stale calls
GET /healthnoneok
GET /v1/statenoneOwner, labels, mandates, revocations, the last 200 decisions and the known-good checkpoint
GET /v1/proofnoneWhat the agent can reach, read live from the Sprites API (cached 60 s), and whether GitHub and Ollama go through connectors or Warden-held tokens. No secrets
POST /v1/mandatesnoneSubmit a mandate someone else signed, such as an agent delegating to a sub-agent. It is stored only if its chain leads back to the owner and is valid now. Body: { "mandate": {...}, "label": "..." } (label up to 64 characters)
POST /v1/admin/mandatesadminThe owner signs a root mandate (see Granting mandates)
POST /v1/admin/revokeadminThe owner revokes one of its mandates. Body: { "mandateId": "0x...", "reason": "..." }
POST /v1/admin/agent/checkpointadminCheckpoint the agent Sprite. Body: { "comment": "...", "markGood": true }. With markGood, it becomes the restore target
POST /v1/admin/agent/restoreadminRestore the agent Sprite. Body: { "checkpoint": "v5" }, or empty to use the known-good one
ANY /v1/gateway/github/{path}agent signatureA GitHub REST call, e.g. /v1/gateway/github/repos/OWNER/REPO/issues
ANY /v1/gateway/ollama/{path}agent signatureAn Ollama API call, e.g. /v1/gateway/ollama/api/chat

Admin routes accept an owner signature, and still accept Authorization: Bearer $WARDEN_ADMIN_TOKEN so the dashboard keeps working. The bearer token is a shared secret: prefer the signature. A request that sends either admin header is checked as a signature and is not silently accepted with the token instead.

Signing an admin request

HeaderValue
x-mandate-admin-timestampUnix seconds
x-mandate-admin-signature0x + 65-byte EIP-191 signature over the digest below
digest = keccak256(
  "mandate-admin/1\n" + METHOD + "\n" + path_and_query + "\n" + timestamp + "\n" + "0x" + hex(keccak256(body))
)

path_and_query is the Warden path, for example /v1/admin/mandates. The recovered signer must be the Warden's owner address (GET /v1/state field owner). The same 60 s window and one-time signature rules as agent calls apply. Auth errors return 401 with MISSING_ADMIN_AUTH, BAD_TIMESTAMP, STALE_REQUEST, BAD_SIGNATURE, NOT_OWNER or REPLAYED_REQUEST.

The owner key lives in WARDEN_DATA/owner.key (0x + 32-byte hex). Sign with that key. The Warden still uses it to sign the mandate or revocation it records.

Signing a request

An agent proves who it is with three headers:

HeaderValue
x-mandate-agentThe agent's address, 0x…
x-mandate-timestampUnix seconds
x-mandate-signature0x + 65-byte EIP-191 (personal_sign) signature over the digest below
digest = keccak256(
  "mandate-call/1\n" + METHOD + "\n" + path_and_query + "\n" + timestamp + "\n" + "0x" + hex(keccak256(body))
)

path_and_query is the full Warden path, starting with /v1/gateway/. The Warden treats the recovered signer as the mandate subject, not the claimed address, and rejects the call if they differ. Auth errors return 401 with one of these codes:

  • MISSING_AUTH
  • BAD_TIMESTAMP
  • STALE_REQUEST (more than 60 s of clock skew)
  • BAD_SIGNATURE
  • SIGNER_MISMATCH
  • REPLAYED_REQUEST (a signature can be used only once)

warden-call and mandate-agent sign for you. Both read MANDATE_AGENT_KEY (hex) and MANDATE_WARDEN_URL.

warden-call keygen                                   # new agent key and address
warden-call GET  repos/OWNER/REPO/issues
warden-call POST repos/OWNER/REPO/issues '{"title":"hi"}'
warden-call --ollama POST api/chat '{"model":"gpt-oss:120b","stream":false,"messages":[{"role":"user","content":"hi"}]}'
mandate-agent "Triage the open issues and label anything that is a bug"

How calls are classified

GitHub. The resource is github:OWNER/REPO for paths under repos/OWNER/REPO/, otherwise github:account.

CallActionRecipient
any GET / HEADread
POST issuesissues.create
POST issues/N/commentsissues.comment
PATCH issues/Nissues.update
POST issues/N/labelsissues.label
POST pullspulls.createbase branch
PUT pulls/N/mergepulls.merge
PUT contents/...contents.writebranch from the body, default main
DELETE contents/...contents.deletebranch from the body, default main
POST git/refsrefs.createthe new branch
PATCH / DELETE git/refs/heads/NAMErefs.update / refs.deleteNAME
POST git/blobs, git/trees, git/commitsgit.objects
other DELETEdelete
write outside a repoaccount.write
anything elseother.<method>.<first segment>

Ollama. The resource is always ollama:cloud, and the recipient is the model field. Ollama calls never trigger checkpoints.

CallAction
POST api/chatmodel.chat
POST api/generatemodel.generate
GET api/tagsmodel.list
anything elseother.<method>.<last segment>

The other.* actions exist so that no mandate grants them by accident. Anything the classifier doesn't recognise is denied.

Decisions

An allowed call returns the upstream response with x-mandate-decision: allow and x-mandate-mandate-id. A denied call returns 403 with x-mandate-decision: deny:

{
  "decision": "deny",
  "reason": "RECIPIENT_NOT_ALLOWED",
  "message": "Target main is not one of the allowed: agent/fix.",
  "action": "contents.write",
  "resource": "github:OWNER/REPO",
  "recipient": "main",
  "mandateId": "0x…",
  "delegationPath": ["0x…owner", "0x…agent"],
  "note": "agent restored to its last known-good checkpoint"
}

reason is a stable code from mandate-core: NO_MANDATE, ACTION_NOT_ALLOWED, RESOURCE_NOT_ALLOWED, RECIPIENT_NOT_ALLOWED, AMOUNT_EXCEEDED, EXPIRED, REVOKED, ANCESTOR_REVOKED, INVALID_SIGNATURE, INVALID_DELEGATION or UNTRUSTED_ROOT. note is present only when the Warden did something extra, such as a restore.

Other errors: 400 BAD_PATH (a path segment is empty, . or .., or contains an encoded dot, slash, backslash or NUL), 502 UPSTREAM_ERROR (the connector call failed; details are in the Warden's log, not the response), 503 NO_CONNECTOR (neither a connection nor a direct credential is configured for that provider), 413 BODY_TOO_LARGE (over 5 MiB).

Configuration

VariableDefaultPurpose
PORT8080Listen port
WARDEN_DATAwarden-dataDirectory for owner.key, store.json and decisions.jsonl. The owner key is created on first run
WARDEN_ADMIN_TOKENunsetLegacy shared secret for the admin routes. Owner signatures work without it
GITHUB_CONNECTION_IDunsetSprites GitHub connection to forward through
OLLAMA_CONNECTION_IDunsetSprites Ollama connection to forward through
GITHUB_TOKENunsetOutside Sprites: a GitHub token the Warden calls the API with directly. Ignored when GITHUB_CONNECTION_ID is set
GITHUB_API_URLhttps://api.github.comGitHub API base for direct mode (GitHub Enterprise)
OLLAMA_URLunsetOutside Sprites: Ollama base URL for direct mode, e.g. http://host.docker.internal:11434 or https://ollama.com. Ignored when OLLAMA_CONNECTION_ID is set
OLLAMA_API_KEYunsetBearer key for OLLAMA_URL (Ollama cloud)
SPRITES_TOKENunsetSprites API token; needed for checkpoints and restores
AGENT_SPRITEmandate-agentThe Sprite to checkpoint and restore
WARDEN_CHECKPOINT_ON_WRITEoffCheckpoint the agent before every allowed write (timeout 60 s)
WARDEN_RESTORE_ON_DENYoffRestore the agent to the known-good checkpoint after a denied write
SPRITES_GATEWAYhttps://api.sprites.dev/v1/gatewayConnector gateway base URL
SPRITES_APIhttps://api.sprites.devSprites management API base URL

The agent side reads MANDATE_AGENT_KEY and MANDATE_WARDEN_URL. mandate-agent also reads:

  • MANDATE_REPO (default dicethedev/mandate-demo)
  • MANDATE_MODEL (default gpt-oss:120b)
  • MANDATE_MAX_STEPS (default 12)

Setting up two Sprites

You need the sprite CLI, logged in to your Fly.io organization.

  1. Create two Sprites: mandate-warden labelled role:warden, and mandate-agent labelled role:agent.
  2. Add connectors. In Sprites, connect GitHub (with access to the repository the agent works on) and Ollama. Note each connection ID.
  3. Lock the connectors to the Warden. Give each connection an access policy that allows only the Warden: its name prefix mandate-warden and label role:warden. To check, call the connector gateway from both Sprites. The Warden should get 200 and the agent 403.
  4. Lock the agent's network. Set the agent Sprite's network policy to allow only the Warden's URL and deny everything else.
  5. Configure secrets. Create .env.sprites (gitignored) in the repository root with WARDEN_ADMIN_TOKEN (any long random string), GITHUB_CONNECTION_ID, OLLAMA_CONNECTION_ID and SPRITES_TOKEN.
  6. Deploy. Run scripts/deploy-warden.sh. It builds in release mode, installs mandate-warden on the Warden Sprite as the warden service (port 8080, with checkpoint-on-write on), and copies warden-call and mandate-agent to the agent Sprite's ~/bin.
  7. Make the agent a key. On the agent Sprite, run warden-call keygen. Keep MANDATE_AGENT_KEY on that Sprite only, and set MANDATE_WARDEN_URL to the Warden's public URL.
  8. Mark a known-good state. Run POST /v1/admin/agent/checkpoint with {"markGood": true}, so restores have a target.

Granting mandates

The Warden's owner key signs root mandates. expiresIn is in seconds and defaults to seven days.

Let the agent think with one model only:

curl -X POST "$WARDEN/v1/admin/mandates" \
  -H "authorization: Bearer $WARDEN_ADMIN_TOKEN" -H 'content-type: application/json' \
  -d '{
    "subject": "0xAGENT",
    "label": "mandate-agent",
    "action": "model.chat",
    "resource": "ollama:cloud",
    "allowedRecipients": ["gpt-oss:120b"]
  }'

Let it read the repository and open issues:

for action in read issues.create issues.comment; do
  curl -X POST "$WARDEN/v1/admin/mandates" \
    -H "authorization: Bearer $WARDEN_ADMIN_TOKEN" -H 'content-type: application/json' \
    -d "{\"subject\":\"0xAGENT\",\"action\":\"$action\",\"resource\":\"github:OWNER/REPO\"}"
done

Let it write files only on its own branches:

curl -X POST "$WARDEN/v1/admin/mandates" \
  -H "authorization: Bearer $WARDEN_ADMIN_TOKEN" -H 'content-type: application/json' \
  -d '{
    "subject": "0xAGENT",
    "action": "contents.write",
    "resource": "github:OWNER/REPO",
    "allowedRecipients": ["agent/fix"]
  }'

Revoke any of them with POST /v1/admin/revoke. Revocation takes effect on the next call.