layer requires a shift in how memory operations are conceptualized. Instead of simple write and read operations, the API exposes three primitives: persist, retrieve, and expunge. Each operation triggers a governance pipeline that ensures data integrity, privacy, and auditability.
1. Persisting Memory with Governance
When storing a fact, the system applies policies before the data is written. This includes PII scanning, redaction, TTL assignment, and access policy binding.
import { GovernedMemoryClient } from '@trace-continuity/sdk';
const memoryService = new GovernedMemoryClient({
apiKey: process.env.MEMORY_API_KEY,
environment: 'production'
});
async function storeUserPreference(agentId: string, orgId: string, rawFact: string) {
try {
const result = await memoryService.persist({
context: {
agentId: 'support-ai-v2',
organizationId: 'acme-industries'
},
content: rawFact,
retention: '90d',
permissions: {
allowedRoles: ['support-agent', 'customer-success']
},
metadata: {
source: 'live-chat',
sessionId: 'sess_9f8e7d'
}
});
// Result includes governance metadata
console.log(`Memory stored: ${result.memoryId}`);
console.log(`Redactions applied: ${result.redactions.length}`);
console.log(`Expires at: ${result.expiresAt}`);
} catch (error) {
// Handle governance violations or storage errors
console.error('Memory persistence failed:', error);
}
}
// Example usage
storeUserPreference('support-ai-v2', 'acme-industries',
'User prefers email contact. Email: user@example.com. Phone: 555-0199.');
Architecture Decisions:
- Pre-Storage PII Scan: The system detects sensitive patterns (e.g., emails, phone numbers) before embedding. Detected PII is redacted (e.g.,
[EMAIL_REDACTED]) and the redaction event is logged. This ensures raw PII never enters the vector index.
- Infrastructure-Level TTL: Retention policies are enforced by the storage layer, not the application. This prevents "zombie" memories from accumulating due to application bugs.
- Role-Based Access: Access policies are stored with the memory record. Retrieval operations validate the requesting agent's role against the memory's permissions.
2. Retrieving Memories with Contextual Filtering
Retrieval operations respect tenant boundaries and access policies. The query is scoped to the agent and organization, and results are filtered based on permissions.
async function fetchRelevantMemories(agentId: string, orgId: string, query: string) {
const hits = await memoryService.retrieve({
context: {
agentId: 'support-ai-v2',
organizationId: 'acme-industries'
},
searchQuery: query,
maxResults: 5
});
return hits.map(hit => ({
id: hit.memoryId,
content: hit.content,
relevanceScore: hit.score,
created: hit.createdAt,
expires: hit.expiresAt
}));
}
// Example usage
const memories = await fetchRelevantMemories('support-ai-v2', 'acme-industries',
'How does the user prefer to be contacted?');
Key Behavior:
- Hard Tenant Isolation: The architecture enforces strict isolation between organizations. Queries cannot leak data across tenant boundaries, even if namespaces are misconfigured.
- Audit Trail: Every retrieval generates an immutable audit event, recording the agent, timestamp, and query context.
3. Expunging Memories for Compliance
Deletion operations must be immediate, verifiable, and auditable. The expunge primitive supports regulatory requirements by providing proof of erasure.
async function handleErasureRequest(orgId: string, memoryId: string, reason: string) {
await memoryService.expunge({
organizationId: orgId,
memoryId: memoryId,
justification: reason
});
// The system ensures deletion across all storage layers
// and logs the action with the provided justification.
}
// Example usage
handleErasureRequest('acme-industries', 'mem_xyz789', 'gdpr_article_17_request');
Compliance Features:
- Immutable Proof: Deletion events are logged with a reason code, timestamp, and requesting agent. This log is queryable and exportable for compliance reporting.
- Multi-Layer Deletion: The system removes the memory from vector indices, metadata stores, and any backup layers, ensuring complete erasure.
Retention Policy Hierarchy
Trace Continuity implements a three-tier retention model to balance flexibility with compliance guardrails:
- Memory-Level TTL: Set at write time. Allows granular control per fact (e.g.,
30d, 1y, session).
- Agent-Level Default TTL: Configured on the agent definition. Provides a baseline retention period for all memories created by a specific agent.
- Tenant-Level Maximum TTL: A hard ceiling set by platform administrators. This prevents individual agents from overriding organizational retention policies. For example, a compliance team can set a maximum TTL of
1y, ensuring no memory persists beyond one year regardless of agent configuration.
This hierarchy ensures that governance policies cannot be bypassed by application code, while still allowing agents to define appropriate retention for their use cases.
Pitfall Guide
Implementing AI memory systems introduces unique risks. The following pitfalls are common in production environments and should be addressed during architecture design.
| Pitfall | Explanation | Fix |
|---|
| Bolt-On Governance | Attempting to add PII scanning or access control via middleware after the memory layer is built. This creates latency and gaps in coverage. | Use a governed memory API where policies are intrinsic to the storage primitives. |
| Soft Tenant Isolation | Relying on namespaces or prefixes to separate tenant data. This is vulnerable to configuration errors and query bugs. | Enforce hard architectural isolation where tenant boundaries are immutable at the storage layer. |
| Ignoring Retention Hierarchies | Setting TTL only at the memory level without defining agent or tenant defaults. This leads to inconsistent data lifecycles. | Define a retention hierarchy with a tenant-level maximum TTL to enforce compliance guardrails. |
| Audit Gaps | Logging only write operations. Reads and deletes are equally important for compliance and security investigations. | Ensure every operation (persist, retrieve, expunge) generates an immutable audit event. |
| Manual Erasure Workflows | Relying on cron jobs or manual scripts to delete expired or requested data. This is slow and error-prone. | Use API-driven expunge operations with immediate enforcement and proof of deletion. |
| Over-Redaction | Redacting non-sensitive data due to overly aggressive PII detection rules. This degrades memory quality. | Use typed PII detection with configurable rules and review redaction logs to tune accuracy. |
| Access Control at API Key Only | Using a single API key for all agents. This prevents granular access control and increases blast radius. | Implement per-memory access policies tied to agent roles, validated at retrieval time. |
Production Bundle
Action Checklist
Decision Matrix
| Scenario | Recommended Approach | Why | Cost Impact |
|---|
| Startup MVP | Bare Vector Store | Low cost, fast iteration. Governance can be deferred if data is non-sensitive. | Low infrastructure cost; high future technical debt. |
| Enterprise SaaS | Governed Memory API | Hard isolation, audit trails, and compliance features are required for multi-tenant security. | Higher API cost; reduced compliance engineering overhead. |
| Regulated Industry | Governed Memory API | Mandatory PII redaction, retention enforcement, and erasure proof for GDPR/CCPA/HIPAA. | Compliance risk mitigation outweighs API cost. |
| High-Volume Analytics | Memory Framework + Custom Governance | Need for high throughput with custom governance logic. | High engineering cost; potential latency overhead. |
Configuration Template
Use this template to initialize the memory client with governance settings:
import { GovernedMemoryClient } from '@trace-continuity/sdk';
const memoryConfig = {
apiKey: process.env.MEMORY_API_KEY,
governance: {
retention: {
tenantMaxTTL: '1y',
agentDefaults: {
'support-ai': '90d',
'billing-bot': '30d'
}
},
pii: {
enabled: true,
detectionTypes: ['EMAIL', 'PHONE', 'SSN', 'CREDIT_CARD'],
redactionStrategy: 'mask'
},
audit: {
enabled: true,
exportFormat: 'json',
retentionPeriod: '7y'
},
accessControl: {
mode: 'role-based',
defaultPolicy: 'deny'
}
}
};
const memoryService = new GovernedMemoryClient(memoryConfig);
Quick Start Guide
- Install SDK: Run
npm install @trace-continuity/sdk to add the governed memory client to your project.
- Initialize Client: Create a
GovernedMemoryClient instance with your API key and governance configuration.
- Persist a Fact: Call
persist with context, content, retention, and permissions. Verify PII redaction and TTL assignment.
- Retrieve Memories: Use
retrieve with a search query and context. Confirm results respect access policies and tenant isolation.
- Expunge Data: Test compliance workflows by calling
expunge with a justification code. Verify audit logging and deletion proof.