Core Functions
API reference for createGovernance, register, enforce, score, and scoreFleet.
The primary API surface of governance-sdk — create an instance, register agents, enforce policies, and inspect state.
createGovernance(options)
Creates a governance instance that holds your policy rules, registered agents, and audit trail. Export as a singleton so all agents share the same policy set.
Parameters:
rules?— Array of policy rules (blockTools, requireApproval, etc.)storage?— Storage backend. Defaults to in-memory. Use createPostgresStorage for persistence.defaultOutcome?— Default outcome when no rules match: "allow" or "block".
Note: Rules are evaluated in priority order. Higher priority wins when multiple rules match the same tool.
gov.register(agent)
Registers an agent with the governance instance. Computes a 7-dimension governance score instantly and assigns a level (L0 through L4).
gov.enforce(ctx)
Evaluates all matching policy rules before a tool call executes. Returns an EnforcementDecision with blocked, reason, outcome, and more. Every call is automatically recorded in the audit trail.
Note: If multiple rules match, the highest-priority rule wins. Kill switch rules always evaluate at priority 999.
gov.storage.getAgent(agentId)
Retrieves a registered agent by ID including name, tools, score, and registration metadata. Returns undefined if not found.
gov.audit.query(filters)
Query audit entries from enforce() calls. Each entry includes a timestamp, agent ID, tool, decision, and metadata. Use gov.audit.log(event) to write custom entries and gov.audit.count(filters?) to count entries.
Note: Use
createIntegrityAudit()from Integrity Audit for HMAC-SHA256 tamper-evident audit chains withverify()support.