Governance owns the agent’s signed identity, the bundle cache, the audit sink, and the trace uploader. Most application code should use the decorator API instead — rubric.init() once, @rubric.tool per function. Reach for Governance directly when you need:
- Multiple agents in one process. The singleton supports one identity at a time;
Governanceinstances are independent. - Tests. Construct a
Governanceper test for isolation. - Library code. Don’t claim the process-wide singleton on a consumer’s behalf — accept a
Governancevia dependency injection.
Governance.bootstrap(...)
Class method that builds a fully-initialized instance.
Parameters
Bootstrap resolution
Bothenrollment_token and agent_name are required. If either is missing (after env-var fallback), bootstrap() raises ValueError — the SDK will not start unauthenticated.
Example
Lifecycle
Governance is a context manager. The recommended pattern:
with block calls gov.shutdown() automatically on exit, which:
- Stops the bundle poller.
- Flushes any queued audit events.
- Closes the trace uploader’s HTTP session.
- Stops the JWT refresh thread.
Properties
agent_id: str
The stable id bound to the JWT’s sub claim. Set on bootstrap; never changes.
current_bundle: Bundle | None
The most recently pulled policy bundle. None until the first pull completes.
Methods
wait_until_ready(timeout=10.0) -> bool
Block until the first bundle pull completes (success or failure). Returns True if a bundle was pulled, False on timeout.
Optional — evaluate() is safe to call before the first pull (default-allow). But if you want your agent to stop and wait for policies, call this first.
evaluate(tool_name, *, session_id, ...) -> EvaluationResult
Evaluate a tool call against the current bundle and ship an audit event. See evaluate() for the full signature.
start() / shutdown()
Manual lifecycle for cases where the with block doesn’t fit (e.g., long-lived service classes). Don’t call start() more than once.
Without bootstrap
For tests and advanced flows, you can pass a pre-built TokenStore:
bootstrap().