Concepts
How governance works: the mental model behind agents, policies, enforcement, and scoring.
The mental model behind governance-sdk. Understand these four concepts and you understand the entire SDK.
Agents
An agent is any autonomous program that makes decisions and takes actions — calling tools, sending messages, executing code. In governance-sdk, every agent is registered with gov.register() and receives a unique ID, a 7-dimension governance score, and a maturity level (L0–L4).
Registration is framework-agnostic. Whether your agent runs on Mastra, Vercel AI SDK, LangChain, or a custom loop — the governance layer doesn't care. It only cares about what the agent does.
Policies
A policy is a declarative rule that controls what agents can do. Policies are evaluated before every action — not after. They define conditions (what to check) and outcomes (allow, block, or require approval).
8 built-in presets cover 90% of use cases. For complex scenarios, compose them with boolean combinators (any_of, all_of, not) or write custom conditions.
| Preset | Description |
|---|---|
blockTools | Block specific tools by name |
allowOnlyTools | Allowlist-only mode |
requireApproval | Human-in-the-loop gate |
tokenBudget | Per-session token limits |
rateLimit | Threshold-based rate check |
requireLevel | Minimum governance level |
requireSequence | Tool prerequisites |
timeWindow | Business hours restriction |
Deep dive: Policies & Rules
Enforcement
Enforcement is the core loop. Every time an agent wants to do something, call gov.enforce(). The SDK evaluates all policies against the proposed action and returns allow or block — in under 1ms, with zero network calls.
- Agent requests action — e.g.
tool_call: shell_exec - enforce() intercepts — Before execution, less than 1ms
- BLOCKED or ALLOWED — Policy matched → action stopped, or all rules pass → proceed
- Audit logged — HMAC-chained event recorded automatically
Every enforcement decision is automatically written to the audit trail — no extra code needed.
Scoring
Every registered agent gets a governance score (0–100) computed across 7 dimensions: authentication, guardrails, observability, tool scoping, audit logging, human oversight, and compliance. The score maps to a governance level:
| Level | Name | Score Range |
|---|---|---|
| L0 | Unregistered | 0–20 |
| L1 | Basic | 21–40 |
| L2 | Managed | 41–60 |
| L3 | Governed | 61–80 |
| L4 | Certified | 81–100 |
Deep dive: Governance Scoring
Architecture: Thin Client
governance-sdk is a thin client SDK. Policy evaluation, scoring, injection detection, and adapter logic all run locally in your process — no network calls, no external services, no latency.
| Layer | What Runs There |
|---|---|
| SDK (local) | Policy evaluation · Scoring · Injection detection · Framework adapters · Audit integrity |
| Your API layer | Rate limiting (Upstash/Redis) · Distributed kill switch · Durable audit storage |
| Enterprise package | Multi-tenant isolation · RBAC · Fleet analytics · Policy templates |