Core Functions

API reference for createGovernance, register, enforce, recordOutcome, audit, integrityChain, score, and scoreFleet.

The primary API surface of governance-sdk — create an instance, register agents, enforce policies, record outcomes, and inspect state.

createGovernance(config)

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

GovernanceConfig fields (all optional):

FieldTypeDefaultDescription
rulesPolicyRule[][]Policy rules evaluated on every enforce(). User priorities are clamped to ≤998.
storageGovernanceStoragein-memoryStorage adapter — swap for createPostgresStorage(pool) in production.
defaultOutcome"allow" | "block""allow"Returned when no rule matches.
serverUrlstringWhen set, enforce() / register() POST to this URL instead of running locally.
apiKeystringBearer token for remote calls. Required when serverUrl is set.
timeoutnumber30000Remote call timeout (ms).
maxRetriesnumber3Remote retry attempts on transient failure.
fallbackMode"allow" | "block""allow"What to do when the remote API is unreachable after retries.
onAuditError(err) => voidnoopCalled when a fire-and-forget audit write fails.
integrityAudit{ signingKey; onFailure? }offEnables HMAC-SHA256 hash chaining of EVERY audit event. See Audit Trail.
ts

Note: Rules are evaluated in priority order (descending). User rules with priority >= 999 are clamped to 998 so the kill switch wins unconditionally.


gov.register(agent)

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

ts
ts

Warning: Self-reported booleans (hasAuth, etc.) are accepted at face value. Cross-check callers' claims against scanRepoContents() from governance-sdk/repo-patterns. See Governance Scoring for the pattern.


gov.enforce(ctx)

Evaluates all matching policy rules before a tool call executes. Returns an EnforcementDecision. Every call is automatically recorded in the audit trail (and HMAC-chained when integrityAudit is set).

ts

Notable EnforcementContext fields:

FieldPopulated byRead by
agentId, action, tool, inputalwaysevery condition
recentActionCounthostrateLimit
sessionTokensUsedhosttokenBudget
identityVerified, identityCapabilityMatchhost (after Ed25519 verify)requireSignedIdentity
mlInjectionScore, mlInjectionCategorieshost (after ML classifier)mlInjectionGuard
outputText, outputTokenCount, executionDurationMshost (postprocess)output rules
ts

Also available: gov.enforcePreprocess(ctx) and gov.enforcePostprocess(ctx) for stage-scoped evaluation.


gov.recordOutcome(outcome)

Closes the decision → outcome loop. Call after the tool / LLM returns so the audit chain covers what actually happened, not just the permission check.

ts

For most callers, the one-line helper is easier:

ts

gov.audit

ts

gov.integrityChain (opt-in)

Populated only when integrityAudit: { signingKey } was passed. Exports the HMAC-chained events for offline verification.

ts
ts

gov.score / gov.scoreFleet

ts

gov.addRule / gov.removeRule

Mutate the policy set at runtime. User rules with priority >= 999 are clamped to 998 to preserve the kill-switch invariant.


gov.eval (in-memory)

Submit results from your adversarial harness (inspect-ai, PyRIT, Garak). Durable eval storage lives in Lua Governance Cloud.

ts

Remote mode (when serverUrl is set)

ts