Skip to main content

Run the control plane in-process

In this tutorial you run the full authorization flow inside one Python process. That means:

  • registering three agents
  • consenting as a user
  • narrowing authority over three hops
  • being refused a tool nobody consented to
  • reading the delegation chain back to the user

You need no Docker, database, Redis or open port.

:::info Available from 0.2.0 authzai[embedded] is published from 0.2.0. :::

:::warning Development and testing only The embedded control plane runs the signing keys and the policy decision point in the same process as the agent they constrain. Use it to learn the product, to try a manifest, and to test your own agents. Don't use it to enforce anything real. For that, deploy the control plane with the sidecar, gateway or boundary adapter in front of your agents. The instance prints a warning when it starts, and every decision it records is labelled deployment: embedded. :::

1. Install​

pip install 'authzai[embedded]'
git clone https://github.com/xinweiiiii/agentic-auth && cd agentic-auth # for the example manifests

2. Run the quickstart​

examples/embedded/quickstart.py
"""The whole control plane in-process: consent, three narrowing hops, a refusal, the chain."""

import asyncio

from agentic_auth.embedded import EmbeddedControlPlane, PolicyDenied


async def main() -> None:
async with EmbeddedControlPlane.open(
"examples/drift-fixture/manifests", override_reason="quickstart"
) as cp:
client = cp.client()
session = await client.consent(scope="bank-assistant", user_sub="user:alice")
grant, ctx = await client.hop(
session.context(), target="agent://balance-agent", data_class="account.read"
)
grant, ctx = await client.hop(ctx, target="agent://support-agent", data_class="kb.internal")
grant, ctx = await client.hop(
ctx, target="mcp://kb.internal/search", data_class="kb.internal"
)
print("allow", grant.hop, " → ".join(ctx.act_chain))
try:
await client.authorize(
ctx, target="mcp://accounts.internal/terminate_account", data_class="account.write"
)
except PolicyDenied as denied:
print("deny", denied.reason.value)
chain = await client.audit.chain(grant.action_id)
print(
"chain",
" → ".join(
[chain["root_consent"]["user_sub"], *(h["acting_agent"] for h in chain["chain"])]
),
)


asyncio.run(main())
python examples/embedded/quickstart.py
embedded control plane: development and testing only — signing keys and policy decisions run inside this process (store=:memory:)
allow 4 user:alice → agent://bank-assistant → agent://balance-agent → agent://support-agent
deny OUT_OF_SCOPE
chain user:alice → bank-assistant → balance-agent → support-agent

3. What just happened​

  • Registration. open() registered the three manifests downstream-first. Their tool hosts have no capability documents here, so discovery was unavailable. override_reason was recorded as the human attestation for that gap, exactly as it would be on a deployed control plane. Pass capabilities={host: rfc9728_document} to reconcile against real documents instead.
  • Narrowing. Each hop was a policy decision followed by an RFC 8693 token exchange. The act chain grew by one agent per hop, and the grant narrowed to one target and one data class.
  • Refusal. terminate_account was never consented to. The refusal was recorded before anything could be dispatched.
  • The chain. One query traced the last call back to user:alice.

4. Use it in your own tests​

cp.client() returns the same AgenticAuthClient you would point at a deployed control plane. Code under test can therefore take a client and run unchanged against either:

@pytest.fixture
async def auth():
async with EmbeddedControlPlane.open("manifests/", capabilities=DOCS) as cp:
yield cp.client()

The two deployments are held to the same answers. tests/conformance runs every scenario against both, and it fails on any difference in decisions, deny reasons, hop numbers, delegation chains or audit records. The one exception is the deployment label.

Each instance owns its keys, sessions and audit log, so tests can run instances side by side.

5. Keep state across restarts​

EmbeddedControlPlane.open("manifests/", store="dev/auth.db", override_reason="local")

A durable store keeps these across a restart:

  • manifests and compiled policies
  • enrollments
  • the signing key
  • the audit log

Only one process may have the store open at a time; a second gets StoreLocked, which names the process holding it. Sessions do not survive a restart. Their taint marks and replay records lived in memory, so an old session is refused with session_superseded rather than honoured with less protection than it had. Consent again.

cp.export("bundle.ndjson") writes the manifests, enrollments and audit history to a bundle. From 0.2.1, two commands carry that bundle into a deployed control plane:

# Every manifest version, in order, through the admin API. Each one reconciles against the
# deployment's real capability discovery.
AGENTIC_AUTH_ADMIN_TOKEN=... agentic-auth manifest register-bundle bundle.ndjson \
--control-plane https://control-plane.example --override-reason "moved from embedded"

# The decisions, into the append-only imported_audit table, apart from the deployment's own log.
agentic-auth audit import bundle.ndjson --database-url postgresql+asyncpg://...

Enrollments are not carried over, and that is deliberate. The bundle holds no private keys, and enrollment is proof of possessing one, so each agent re-enrolls with its own key. Sessions and signing keys are never exported.