Skip to main content
Take a registered agent from the developer quickstart and embed the Python SDK in a real service. Tool calls route through the gateway, end-user identity flows on every request, and the audit trail correlates the run.
Prerequisites:
  • Completed Developer Quickstart — agent registered, API key minted, rules deployed
  • Agent token saved as $DOME_AGENT_TOKEN
  • Gateway URL saved as $DOME_GATEWAY_URL — must include the /gateways/{id} Gateway prefix (https://gateway.../gateways/{id}); a bare base URL fails closed
  • Control-plane URL saved as $DOME_CONTROL_PLANE_URL
  • Python 3.12+

1. Add the SDK

2. Initialize once at startup

Construct the client during application startup. Share one Client across threads — the gateway clients are thread-safe.
connect() prepares credentials and transport state. It does not block on local Cedar sync — only call client.start_policy_sync() if you also want in-process checks.

3. Route tool calls through the gateway

Replace direct tool invocations with client.gateway.tools.call(). The gateway evaluates authorization, resolves credentials, and audits the call before the upstream backend ever runs.
act_as carries the end user the agent is acting on behalf of. Cedar rules read principal.act_as.email, principal.act_as.sub, and so on — refer to Authorization model.

4. Correlate a run with an activity

Wrap each agent run in client.activity(...) so every gateway call and audit event shares an opaque activity ID.
Outside an activity context, calls carry no activity ID — the SDK never mints one implicitly.

5. Shut down cleanly

Call close() on shutdown to release transports.
Or use the context-manager form for short-lived scripts:

6. Verify in audit

Pull the run back with client.audit.query(...) (or the CLI):
Or from the CLI:
Each gateway call appears with the rule decision, the act-as identity, the upstream latency, and the activity ID.

Next steps

Adapters

Skip manual wrapping — use the LangChain adapter for gateway tools and governed chat models.

Reference

Full configuration, act-as methods, errors, and audit reads.