Enroll your first agent
In about ten minutes, with nothing but the Python package, you will:
- register an agent and have its manifest checked against what its tool really offers
- record a person's consent
- get one call allowed and one refused
- give the agent a key and enroll it, bound to that person
- verify its call at the tool, offline
- read the decision back, traced to the person who consented
Each step is a few lines of one script. The whole script is at the end, and its output there is from a real run.
You don't need to know what a "hop" or a "scope" is yet. A short definition appears the first time each term shows up.
Step 0 — Install
pip install 'authzai[embedded]'
Python 3.12 or later. The package installs as authzai and imports as agentic_auth.
Step 1 — Start a control plane
from agentic_auth.embedded import EmbeddedControlPlane
async with EmbeddedControlPlane.open(capabilities=CAPABILITIES) as cp:
ops = cp.client()
This runs the real control plane inside your Python process: the same decision point, token
exchange and audit log a deployment runs, with no database, Docker or ports. ops is the
platform team's client. It holds the admin credential and registers things.
CAPABILITIES stands in for what your tool hosts publish about themselves (RFC 9728). A
deployed control plane fetches the same document from
https://kb.internal/.well-known/oauth-protected-resource.
CAPABILITIES = {
"kb.internal": {
"resource": "https://kb.internal",
"scopes_supported": ["kb.public"],
"tools": {"search": {"data_classes": ["kb.public"], "privileged": False}},
}
}
The service that stores manifests, compiles policy, decides each call and mints tokens. Agents, and the enforcement points in front of them, call it. Embedded mode is for trying the product and for tests. Against a deployed control plane, below, shows the same steps against a real one.
Step 2 — Register the agent's manifest
A manifest is an agent's declared authority. It lists:
- which tools it may call
- which data classes it may read or write
- which agents it may delegate to
- how deep a delegation chain through it may go
MANIFEST = {
"apiVersion": "agentic-auth/v1",
"kind": "AgentManifest",
"metadata": {"agent": "kb-search-agent"},
"spec": {
"tools": [
{"ref": "mcp://kb.internal/search", "data_classes": ["kb.public"], "privileged": False}
],
"data_classes": {"reads": ["kb.public"], "writes": []},
"downstream_agents": [],
"hop_budget": 2,
},
}
(registration,) = await cp.register({"kb-search-agent": MANIFEST})
print("registered:", registration.status, "version", registration.manifest_version)
registered: reconciled version 1
The manifest was checked against what the tool host actually advertises, and nothing was
claimed that the tool doesn't offer. If something were, registration raises ManifestRejected
with a diff naming the exact tool and the remedy.
Register and reconcile a manifest shows how to
read it.
Manifests can also come from YAML files or directories: cp.register("manifests/").
Step 3 — A person consents
Nothing can run yet. A person has to consent to the scope first, and that consent is the root of every delegation chain that follows.
session = await ops.consent(scope="kb-search-agent", user_sub="user:alice")
print("session:", session.session_id, "policy version", session.policy_version)
session: 35967840-3346-4d82-81a3-01051124f397 policy version 1
The name a manifest compiles under; here, the agent's own name. Consenting pins one immutable policy version for the session. Every decision in the session is judged against that version, even after a newer one is published.
Step 4 — Ask for a decision, and for something nobody consented to
from agentic_auth.sdk import PolicyDenied
grant = await ops.authorize(
session.context(), target="mcp://kb.internal/search", data_class="kb.public"
)
print("allowed: hop", grant.hop, "scope", grant.scope, "action", grant.action_id)
try:
await ops.authorize(
session.context(), target="mcp://kb.internal/delete", data_class="kb.public"
)
except PolicyDenied as denied:
print("denied:", denied.reason.value, "| recoverable:", denied.recoverable)
allowed: hop 2 scope kb.public action bc9f70e2-791f-4891-a6a1-1e372c6986d7
denied: OUT_OF_SCOPE | recoverable: False
authorize is two things at once. The decision point rules on the call, and on an allow the
token is exchanged for one narrowed to exactly this target and data class. A refusal raises,
so a denied call can't slip through as a falsy return value. Both outcomes are already in the
audit log: action_id names the row.
One link in a delegation chain. The person's session is hop 1. The grant it produces is for
hop 2, and each delegation adds one more, up to the manifest's hop_budget. Depth comes from
the signed token, never from a number the caller supplies.
Step 5 — Give the agent a key and enroll it
So far anyone holding the session's token could make that call. Enrollment ties the agent to a key it alone holds, and to an accountable person.
from agentic_auth.sdk import AgentKey
key = AgentKey.generate() # in production: key.save(...) where the agent runs
agent_id = await ops.admin.agent_id("kb-search-agent")
enrolled = await ops.enroll(
agent_id,
key=key,
agent_name="kb-search-agent",
principal_assertion=cp.idp.mint(agent="kb-search-agent", sub="alice"),
enroll_token=cp.enroll_token,
)
print("enrolled:", enrolled["status"])
enrolled: enrolled
enroll proves the agent holds the key by signing a challenge. It also presents an ID token in
which a person, here alice, names this agent as theirs. An agent nobody vouches for comes back
quarantined: identified, but allowed nothing.
The accountable person behind an agent. cp.idp is a built-in stand-in for your company's
identity provider. Against a deployment, the ID token comes from your real IdP.
Step 6 — The agent presents its identity on every call
agent = cp.client("kb-search-agent", key=key)
grant = await agent.authorize(
session.context(), target="mcp://kb.internal/search", data_class="kb.public"
)
print("grant headers:", sorted(grant.headers()))
grant headers: ['Agent-Identity', 'Authorization']
The agent's own client signs a proof of possession on every exchange, and every grant carries a
signed Agent-Identity header next to the narrowed Authorization token.
Step 7 — The tool verifies the call, offline
verifier = await cp.verifier(agents=["kb-search-agent"])
admitted = verifier.admit(grant.headers(), target="mcp://kb.internal/search")
identity_only = {k: v for k, v in grant.headers().items() if k != "Authorization"}
refused = verifier.admit(identity_only, target="mcp://kb.internal/search")
print("admitted:", admitted.ok, "| identity alone:", refused.ok, refused.reason)
admitted: True | identity alone: False GRANT_MISSING
This is the check the tool, not the agent, runs. After a one-time bootstrap it needs no network
call: it checks the grant against the issuer's keys and the identity against the agent's pinned
key. Both must be present, so a valid identity without a grant is refused. A tool needs only
pip install authzai. Enroll and verify agent identity
shows the verifier set up by hand.
Step 8 — Read the decision back, traced to the person
chain = await ops.audit.chain(grant.action_id)
print("chain:", chain["root_consent"]["user_sub"], "->",
[hop["acting_agent"] for hop in chain["chain"]], "| complete:", chain["complete"])
chain: user:alice -> ['kb-search-agent'] | complete: True
"Who authorized this call, and through which agents?" is one query, not a log search.
The whole script
import asyncio
from agentic_auth.embedded import EmbeddedControlPlane
from agentic_auth.sdk import AgentKey, PolicyDenied
MANIFEST = {
"apiVersion": "agentic-auth/v1",
"kind": "AgentManifest",
"metadata": {"agent": "kb-search-agent"},
"spec": {
"tools": [
{"ref": "mcp://kb.internal/search", "data_classes": ["kb.public"], "privileged": False}
],
"data_classes": {"reads": ["kb.public"], "writes": []},
"downstream_agents": [],
"hop_budget": 2,
},
}
CAPABILITIES = {
"kb.internal": {
"resource": "https://kb.internal",
"scopes_supported": ["kb.public"],
"tools": {"search": {"data_classes": ["kb.public"], "privileged": False}},
}
}
async def main() -> None:
async with EmbeddedControlPlane.open(capabilities=CAPABILITIES) as cp:
ops = cp.client()
(registration,) = await cp.register({"kb-search-agent": MANIFEST})
print("registered:", registration.status, "version", registration.manifest_version)
session = await ops.consent(scope="kb-search-agent", user_sub="user:alice")
print("session:", session.session_id, "policy version", session.policy_version)
grant = await ops.authorize(
session.context(), target="mcp://kb.internal/search", data_class="kb.public"
)
print("allowed: hop", grant.hop, "scope", grant.scope, "action", grant.action_id)
try:
await ops.authorize(
session.context(), target="mcp://kb.internal/delete", data_class="kb.public"
)
except PolicyDenied as denied:
print("denied:", denied.reason.value, "| recoverable:", denied.recoverable)
key = AgentKey.generate()
agent_id = await ops.admin.agent_id("kb-search-agent")
enrolled = await ops.enroll(
agent_id,
key=key,
agent_name="kb-search-agent",
principal_assertion=cp.idp.mint(agent="kb-search-agent", sub="alice"),
enroll_token=cp.enroll_token,
)
print("enrolled:", enrolled["status"])
agent = cp.client("kb-search-agent", key=key)
grant = await agent.authorize(
session.context(), target="mcp://kb.internal/search", data_class="kb.public"
)
print("grant headers:", sorted(grant.headers()))
verifier = await cp.verifier(agents=["kb-search-agent"])
admitted = verifier.admit(grant.headers(), target="mcp://kb.internal/search")
identity_only = {k: v for k, v in grant.headers().items() if k != "Authorization"}
refused = verifier.admit(identity_only, target="mcp://kb.internal/search")
print("admitted:", admitted.ok, "| identity alone:", refused.ok, refused.reason)
await verifier.close()
chain = await ops.audit.chain(grant.action_id)
print("chain:", chain["root_consent"]["user_sub"], "->",
[hop["acting_agent"] for hop in chain["chain"]], "| complete:", chain["complete"])
asyncio.run(main())
python first_agent.py
embedded control plane: development and testing only — signing keys and policy decisions run inside this process (store=:memory:)
registered: reconciled version 1
session: 35967840-3346-4d82-81a3-01051124f397 policy version 1
allowed: hop 2 scope kb.public action bc9f70e2-791f-4891-a6a1-1e372c6986d7
denied: OUT_OF_SCOPE | recoverable: False
enrolled: enrolled
grant headers: ['Agent-Identity', 'Authorization']
admitted: True | identity alone: False GRANT_MISSING
chain: user:alice -> ['kb-search-agent'] | complete: True
The ids differ on every run; everything else is the same.
Against a deployed control plane
Every call above is the same against a real control plane. Only what you construct changes:
| Step | Embedded (above) | Deployed |
|---|---|---|
| Install | pip install 'authzai[embedded]' | pip install 'authzai[client]' |
| 1. Client | cp.client() | AgenticAuthClient("https://control-plane.example", admin_token=..., audit_token=...) |
| 2. Register | cp.register({...}) | await ops.admin.register_agent("kb-search-agent", MANIFEST), reconciled against the tool's real discovery document |
| 5. Enroll | cp.idp.mint(...), cp.enroll_token | an ID token from your IdP; the AGENTIC_AUTH_ENROLL_TOKEN bearer |
| 6. Agent's client | cp.client(name, key=key) | AgenticAuthClient(url, identity_key=key, agent_name=name) |
| 7. Verifier | await cp.verifier(agents=[...]) | Verifier(HttpJwks(...), HttpAnchors(...), ...), see Enroll and verify agent identity |
Install and verify a release covers running the
control plane, from PyPI or the ghcr.io/xinweiiiii/agentic-auth image.
Where to go next
- The whole product in one sitting: delegation three hops deep, a parameter-bound privileged call, a refused prompt injection, the CI drift gate, a revocation and an outage. The End-to-end walkthrough is an executed notebook where every output is from a real run.
- Enforce it in front of an agent you can't change: Deploy the sidecar PEP, the gateway, or a boundary adapter.
- Every method used here:
AgenticAuthClientandEmbeddedControlPlane. - Why it's built this way: Architecture overview.