Quickstart
Put a real governance gate in front of an agent in under five minutes — no PostgreSQL, no Redis, no API key.
Every agent call you govern with AgentTrust is intercepted twice: once before the function body runs, to decide whether the call is allowed at all, and once after it returns, to decide whether the result may be released. This page gets that gate running locally against an in-process gateway, then shows you the audit record it produced.
What you need
Python ≥ 3.10 and pip. Nothing else — no database, no API key, no network access. The
embedded gateway runs inside your own process and stores its ledger in SQLite.
Step-by-Step Guide
Install the SDK
The PyPI distribution is agentrust-py. The Python module you import is
agentrust_sdk — the names differ, and that is expected.
pip install "agentrust-py[embedded,retry]"| Extra | What it adds |
|---|---|
embedded | FastAPI + uvicorn, required by embed_gateway() |
retry | Exponential backoff on transient gateway errors, via tenacity |
Do not install `agentrust-sdk`
agentrust-sdk on PyPI and npm are unrelated third-party packages by different authors.
Installing either will not give you AgentTrust.
Confirm the install and see which tier you are on:
agentrust whoami Not authenticated (OSS mode — schema validation only)
Get a free key: https://app.agent-trust.tech/signupThat is the expected output here — with no API key you are on the OSS tier, which is all this quickstart needs. The full capability matrix only prints once a key is configured.
Write a governed agent
Create agent.py. The @harness decorator is the entire integration — one line above the
function you want governed.
from agentrust_sdk import harness, embed_gateway
# Starts an in-process governance gateway on http://127.0.0.1:8765 and points
# every AgentTrust client created afterwards at it. Idempotent.
embed_gateway()
@harness
def my_agent(user: str, input: str) -> dict:
"""Your agent. Return a dict so the schema check has something to validate."""
return {"answer": "Hello from a governed agent"}
if __name__ == "__main__":
result = my_agent(user="alice", input="What is AI governance?")
print(result)Call your agent with keyword arguments
@harness reads the end user and the input from the keyword arguments named user
and input. Call my_agent("alice", "...") positionally and the audit record will say
user="unknown" with an empty input. Rename the arguments it looks for with
@harness(user_kwarg="actor", input_kwarg="prompt").
Run it
python agent.py{'answer': 'Hello from a governed agent'}Your agent returns exactly what it always did — @harness never changes the return value.
What changed is invisible from the outside, and it is the whole point:
- Pre-check —
POST /v1/runtime/pre-checkran before the function body. Had the decision beenblock,BlockedErrorwould have been raised and the body would never have executed — no payment sent, no row written, no email delivered. - Your function ran.
- Post-check —
POST /v1/runtime/post-checkscored the actual output and decided whether you were allowed to see it.
Both phases were persisted to an append-only SQLite ledger.
Read the audit trail
Every governed call leaves two rows — one per phase.
agentrust audit tail ENVELOPE AGENT DECISION RISK CONF TIMESTAMP
───────────────────────────────────────────────────────────────────────────
4988f888 my_agent approve low 91.5 2026-08-15 09:14:02
3000a5b2 my_agent approve low 89.5 2026-08-15 09:14:02You can also query the gateway over HTTP — but only while your process is still alive.
The embedded gateway runs in a daemon thread, so it dies the moment agent.py exits;
python agent.py & followed by curl just gives you connection refused.
Keep it up long enough to inspect by parking the script:
import os
os.environ["AGENTRUST_EMBED_TOKEN"] = "local-dev-token" # pin it BEFORE starting
from agentrust_sdk import harness, embed_gateway
embed_gateway()
@harness
def my_agent(user: str, input: str) -> dict:
return {"answer": "Hello from a governed agent"}
my_agent(user="alice", input="What is AI governance?")
input("gateway running on :8765 — press Enter to stop") # keeps the thread aliveThen, from another shell:
curl -s http://127.0.0.1:8765/v1/health
curl -s -H "Authorization: Bearer local-dev-token" \
"http://127.0.0.1:8765/v1/audit/executions?limit=5" | python -m json.tool/v1/health is the only unauthenticated route; everything else answers 401 without the
bearer token. Set AGENTRUST_EMBED_TOKEN before embed_gateway() runs — otherwise a
fresh token is generated inside the Python process and your shell never sees it.
Watch it block something
Governance you have never seen refuse anything is governance you cannot trust. Set the kill switch and re-run — every agent is hard-blocked, ahead of any scoring:
AGENTRUST_KILL_SWITCH=1 python agent.pyfrom agentrust_sdk import BlockedError
try:
my_agent(user="alice", input="What is AI governance?")
except BlockedError as e:
print(e.outcome) # "block"
print(e.reason) # "Kill switch: Environment kill switch (AGENTRUST_KILL_SWITCH=1)"
print(e.envelope_id) # the audit row to quote in an incident reviewThe block lands at the pre-check, so the function body never runs — confirm it by
putting a print() inside my_agent and watching it stay silent. The blocked attempt is
still written to the ledger, with decision=block and risk_tier=critical.
Promote to production
Application code does not change between environments. Only the environment does:
export AGENTRUST_GATEWAY_URL=https://agentrust.internal:8000
export AGENTRUST_KEY=at_team_your_key_here
export AGENTRUST_FAILURE_MODE=closedDelete the embed_gateway() call and the same @harness now runs against the full Edge
gateway — PostgreSQL-backed audit, the review queue, analytics, and the LLM judge.
And when you need governance gone right now, with no redeploy and no code change:
export AGENTRUST_ENABLED=false@harness becomes an identity wrapper. Your agents run exactly as they did before you
installed anything.
Watch the walkthrough
Three recordings covering the product, the AI-assisted onboarding path, and the manual developer setup. Each one stands alone — start with whichever matches what you are trying to do.
Product demo — runtime governance in action
What AgentTrust does at runtime: intercepting an agent mid-execution, scoring it, and blocking a dangerous action before it reaches the downstream system. Start here if you want to see the outcome before the code.
Onboarding via Claude — onboard and certify an agent
The AI-assisted path: hand an existing agent to Claude and let it register the agent, declare its tools, and drive it through the full certification workflow.
DevEx onboarding — set up, connect, and verify
The hands-on developer setup, end to end: installing the SDK, connecting to a gateway, adding the harness, and verifying that governance is genuinely running.
Verifying governance is really on
Under the default AGENTRUST_FAILURE_MODE=open, an unreachable gateway is logged as a
warning and your agent continues — availability wins over enforcement. That is the right
default for production, and a trap while you are integrating: a typo in the gateway URL
looks exactly like a healthy system.
Making failure loud takes two settings, because @harness catches every exception
except BlockedError and proceeds regardless of failure mode:
@harness(raise_on_error=True) # stop swallowing transport errors
def my_agent(user: str, input: str) -> dict: ...export AGENTRUST_FAILURE_MODE=closed # make an unreachable gateway an exceptionWith both set, a bad gateway URL raises GatewayUnavailableError instead of silently
passing your agent through. Drop raise_on_error and switch back to open once you are
confident in the deployment.
(The direct client is different: AgentTrustClient.validate() raises on its own under
closed, with no extra flag.)
| Check | Command | Expected |
|---|---|---|
| Gateway is up | curl http://127.0.0.1:8765/v1/health | {"status":"ok", …} |
| Records are landing | agentrust audit tail | Two rows per governed call |
| Tier is what you think | agentrust whoami | On OSS (no key) it prints Not authenticated (OSS mode — schema validation only) and stops; the capability matrix appears only once a key is configured |
agentrust status prints config file locations and the resolved tier — it does not
contact the gateway, so it cannot tell you whether the gateway is reachable.
Common Mistakes
- Installing
agentrust-sdkinstead ofagentrust-py - Installing
agentrust-pywithout the[embedded]extra, then callingembed_gateway()— you getImportErrorfor FastAPI or uvicorn - Calling the agent positionally, so
userandinputnever reach the envelope - Expecting
AGENTRUST_FAILURE_MODE=closedalone to make@harnessfail loudly — it also needsraise_on_error=True - Backgrounding the script and then curling the gateway — the daemon thread exits with the process
- Assuming embedded risk scores match production — the embedded gateway has no historical-reliability signal
Troubleshooting
| Issue | Fix |
|---|---|
Port 8765 in use | export AGENTRUST_EMBED_PORT=8766 |
ModuleNotFoundError: uvicorn | pip install "agentrust-py[embedded]" |
| No audit records | Add @harness(raise_on_error=True) and AGENTRUST_FAILURE_MODE=closed to surface the real error, then check AGENTRUST_GATEWAY_URL |
401 from the embedded gateway | Send Authorization: Bearer <token>; set AGENTRUST_EMBED_TOKEN before embed_gateway() runs |
curl: connection refused | The process exited — the embedded gateway is a daemon thread and does not outlive it |
| Audit list always empty | Check AGENTRUST_EMBED_DB is not :memory: |
agentrust: command not found | Reinstall agentrust-py and confirm your virtualenv's bin/ is on PATH |
Next Steps
Python Quickstart
Every integration pattern: auto-instrumentation, the decorator, and the direct client.
Harness Decorator
The full parameter reference for @harness and how the two-phase gate behaves.
How It Works
The validation, confidence, risk, and decision engines behind each outcome.
Failure Modes
open, closed, and queue — choosing between availability and enforcement.
Embedded Gateway
What the in-process gateway supports, and where it stops.
Docker Compose
Stand up the full Edge stack: gateway, PostgreSQL, Redis, and the dashboard.