Getting Started

Quickstart

Put a real governance gate in front of an agent in under five minutes — no PostgreSQL, no Redis, no API key.

Quickstart

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]"
ExtraWhat it adds
embeddedFastAPI + uvicorn, required by embed_gateway()
retryExponential 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/signup

That 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.

agent.py
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:

  1. Pre-checkPOST /v1/runtime/pre-check ran before the function body. Had the decision been block, BlockedError would have been raised and the body would never have executed — no payment sent, no row written, no email delivered.
  2. Your function ran.
  3. Post-checkPOST /v1/runtime/post-check scored 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:02

You 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:

serve.py
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 alive

Then, 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.py
from 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 review

The 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=closed

Delete 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.

Watch on YouTube

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.

Watch on YouTube

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.

Watch on YouTube

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 exception

With 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.)

CheckCommandExpected
Gateway is upcurl http://127.0.0.1:8765/v1/health{"status":"ok", …}
Records are landingagentrust audit tailTwo rows per governed call
Tier is what you thinkagentrust whoamiOn 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-sdk instead of agentrust-py
  • Installing agentrust-py without the [embedded] extra, then calling embed_gateway() — you get ImportError for FastAPI or uvicorn
  • Calling the agent positionally, so user and input never reach the envelope
  • Expecting AGENTRUST_FAILURE_MODE=closed alone to make @harness fail loudly — it also needs raise_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

IssueFix
Port 8765 in useexport AGENTRUST_EMBED_PORT=8766
ModuleNotFoundError: uvicornpip install "agentrust-py[embedded]"
No audit recordsAdd @harness(raise_on_error=True) and AGENTRUST_FAILURE_MODE=closed to surface the real error, then check AGENTRUST_GATEWAY_URL
401 from the embedded gatewaySend Authorization: Bearer <token>; set AGENTRUST_EMBED_TOKEN before embed_gateway() runs
curl: connection refusedThe process exited — the embedded gateway is a daemon thread and does not outlive it
Audit list always emptyCheck AGENTRUST_EMBED_DB is not :memory:
agentrust: command not foundReinstall agentrust-py and confirm your virtualenv's bin/ is on PATH

Next Steps