Governance Administration API
These explicit policy templates, simulation and enforcement operations are server administration. Runtime billable admission is the versioned model-policy registry; current authority, retention, locks and tombstones remain enforced independently. A compliance template is not a legal certification.
Usage boundary
Access the namespace on an explicitly configured root Cortex client. Host JWT and deployment-operator transports are distinct; validate current resource scope and do not infer authority from AuthContext metadata. See administrative operations.
Policy configuration, simulation and reports
GovernancePolicy defines conversation retention/purging, immutable version retention by type, mutable TTL/inactivity, vector retention by importance/source, optional session lifecycle/cleanup/limits and compliance mode/audit requirements. Durations use supported strings such as 30d/7y. setPolicy returns the saved policy, version and timestamps. getPolicy(scope?) retrieves the selected organization/space policy; setAgentOverride sets a partial space override. Template names are GDPR, HIPAA, SOC2 and FINRA; template policy settings are configuration starting points rather than compliance certification.
import type { Cortex } from '@cortexmemory/sdk';
export async function previewApprovedRetention(cortex: Cortex) {
const template = await cortex.governance.getTemplate('GDPR');
const simulation = await cortex.governance.simulate(template);
return { proposed: template, simulation };
}
simulate accepts proposed partial policy and returns affected counts/estimates without applying enforcement. enforce validates its options and then throws GovernanceCapabilityError: BACKEND_ENFORCEMENT_ONLY, outcome: "not_dispatched", retryable: false, required execution trusted_backend_worker. The current enforcement adapter is SIMULATION; automatic retention deletion is not implemented. Retained EnforcementResult signatures describe the compatibility contract and are not evidence that manual/automatic deletion runs. Reports/statistics return scope/time-window coverage and layer counts rather than proving complete erasure. Governance retention is separate from backend model/interface/capability policy: every billable runtime primary/secondary/media/embedding call still passes the versioned model policy and shared budget.
Parameter and result contracts
These are reference definitions for the explicit server APIs. Optional fields use ?; timestamps are milliseconds since epoch unless an operation accepts a Date. Resource identifiers and participant metadata do not grant runtime authority.
GovernancePolicy
export interface GovernancePolicy {
organizationId?: string;
memorySpaceId?: string;
conversations: {
retention: {
deleteAfter: string;
archiveAfter?: string;
purgeOnUserRequest: boolean;
};
purging: {
autoDelete: boolean;
deleteInactiveAfter?: string;
};
};
immutable: {
retention: {
defaultVersions: number;
byType: Record<
string,
{
versionsToKeep: number;
deleteAfter?: string;
}
>;
};
purging: {
autoCleanupVersions: boolean;
purgeUnusedAfter?: string;
};
};
mutable: {
retention: {
defaultTTL?: string;
purgeInactiveAfter?: string;
};
purging: {
autoDelete: boolean;
deleteUnaccessedAfter?: string;
};
};
vector: {
retention: {
defaultVersions: number;
byImportance: Array<{
range: [number, number];
versions: number;
}>;
bySourceType?: Record<string, number>;
};
purging: {
autoCleanupVersions: boolean;
deleteOrphaned: boolean;
};
};
sessions?: SessionPolicy;
compliance: {
mode: ComplianceMode;
dataRetentionYears: number;
requireJustification: number[];
auditLogging: boolean;
};
}
ComplianceTemplate
export type ComplianceTemplate = "GDPR" | "HIPAA" | "SOC2" | "FINRA";
PolicyScope
export interface PolicyScope {
organizationId?: string;
memorySpaceId?: string;
}
PolicyResult
export interface PolicyResult {
policyId: string;
appliedAt: number;
scope: PolicyScope;
success: boolean;
}
EnforcementOptions
export interface EnforcementOptions {
layers?: ("conversations" | "immutable" | "mutable" | "vector")[];
rules?: ("retention" | "purging")[];
scope?: PolicyScope;
}
EnforcementResult
export interface EnforcementResult {
enforcedAt: number;
versionsDeleted: number;
recordsPurged: number;
storageFreed: number;
affectedLayers: string[];
}
SimulationOptions
export interface SimulationOptions extends Partial<GovernancePolicy> {}
Also inherits Partial. See shared contracts.
SimulationResult
export interface SimulationResult {
versionsAffected: number;
recordsAffected: number;
storageFreed: number;
costSavings: number;
breakdown: {
conversations?: { affected: number; storageMB: number };
immutable?: { affected: number; storageMB: number };
mutable?: { affected: number; storageMB: number };
vector?: { affected: number; storageMB: number };
};
}
ComplianceReportOptions
export interface ComplianceReportOptions {
organizationId?: string;
memorySpaceId?: string;
period: {
start: Date;
end: Date;
};
}
ComplianceReport
export interface ComplianceReport {
organizationId?: string;
memorySpaceId?: string;
period: { start: number; end: number };
generatedAt: number;
conversations: {
total: number;
deleted: number;
archived: number;
complianceStatus: "COMPLIANT" | "NON_COMPLIANT" | "WARNING";
};
immutable: {
entities: number;
totalVersions: number;
versionsDeleted: number;
complianceStatus: "COMPLIANT" | "NON_COMPLIANT" | "WARNING";
};
vector: {
memories: number;
versionsDeleted: number;
orphanedCleaned: number;
complianceStatus: "COMPLIANT" | "NON_COMPLIANT" | "WARNING";
};
dataRetention: {
oldestRecord: number;
withinPolicy: boolean;
};
userRequests: {
deletionRequests: number;
fulfilled: number;
avgFulfillmentTime: string;
};
}
EnforcementStatsOptions
export interface EnforcementStatsOptions {
period: string;
organizationId?: string;
memorySpaceId?: string;
}
EnforcementStats
export interface EnforcementStats {
period: { start: number; end: number };
conversations: {
purged: number;
archived: number;
};
immutable: {
versionsDeleted: number;
entitiesPurged: number;
};
vector: {
versionsDeleted: number;
memoriesPurged: number;
};
mutable: {
keysDeleted: number;
};
storageFreed: number;
costSavings: number;
}
Public methods
The following signatures describe the TypeScript namespace. Parameter and result fields are defined on this page; the installed @cortexmemory/sdk declarations also provide their compile-time types. Signatures are reference notation, not application code to execute.
setPolicy
Set governance policy for organization or memory space
cortex.governance.setPolicy(policy: GovernancePolicy): Promise<PolicyResult>
getPolicy
Get current governance policy
cortex.governance.getPolicy(scope?: PolicyScope): Promise<GovernancePolicy>
setAgentOverride
Override policy for specific memory space
cortex.governance.setAgentOverride(memorySpaceId: string, overrides: Partial<GovernancePolicy>): Promise<void>
getTemplate
Get compliance template (GDPR, HIPAA, SOC2, FINRA)
cortex.governance.getTemplate(template: ComplianceTemplate): Promise<GovernancePolicy>
enforce
Validate a manual enforcement request and reject client-side execution.
cortex.governance.enforce(options: EnforcementOptions): Promise<EnforcementResult>
simulate
Simulate policy impact without applying
cortex.governance.simulate(options: SimulationOptions): Promise<SimulationResult>
getComplianceReport
Generate compliance report
cortex.governance.getComplianceReport(options: ComplianceReportOptions): Promise<ComplianceReport>
getEnforcementStats
Get enforcement statistics
cortex.governance.getEnforcementStats(options: EnforcementStatsOptions): Promise<EnforcementStats>
Errors and lifecycle
Validation, missing capability, authorization, stale version and partial/unknown committed outcomes are explicit. Inspect operation/write/deletion receipts before recovery; do not repeat an external effect under a new identity after uncertainty. Close owned clients and graph resources at the end of the server workflow.
See runtime client for ordinary app execution and error handling for recovery boundaries.