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)

ts

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.

ts

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".
ts

Note: Rules are evaluated in priority order. Higher priority wins when multiple rules match the same tool.


gov.register(agent)

ts

Registers an agent with the governance instance. Computes a 7-dimension governance score instantly and assigns a level (L0 through L4).

ts
ts

gov.enforce(ctx)

ts

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.

ts
ts

Note: If multiple rules match, the highest-priority rule wins. Kill switch rules always evaluate at priority 999.


gov.storage.getAgent(agentId)

ts

Retrieves a registered agent by ID including name, tools, score, and registration metadata. Returns undefined if not found.

ts
ts

gov.audit.query(filters)

ts

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.

ts
ts

Note: Use createIntegrityAudit() from Integrity Audit for HMAC-SHA256 tamper-evident audit chains with verify() support.