AgentForge

Cleanup

Manage memory lifecycle with MemoryCleanupManager — TTL, limits, and scheduled cleanup.

MemoryCleanupManager

import { MemoryCleanupManager } from '@ahzan-agentforge/core';

const cleanup = new MemoryCleanupManager(store, {
  maxAge: 30 * 24 * 60 * 60 * 1000,  // 30 days
  maxEntries: 10_000,
  batchSize: 100,
});

CleanupConfig

interface CleanupConfig {
  maxAge?: number;       // Max memory age in ms
  maxEntries?: number;   // Max total entries
  batchSize?: number;    // Entries processed per batch
}

Running Cleanup

const stats = await cleanup.run();
console.log(stats);
// CleanupStats { removed: 150, remaining: 9850, duration: 1200 }

CleanupStats

interface CleanupStats {
  removed: number;
  remaining: number;
  duration: number;  // ms
}

Scheduled Cleanup

Run cleanup on a schedule:

// Every hour
setInterval(() => cleanup.run(), 60 * 60 * 1000);

Next Steps

  • Types — memory type reference
  • Overview — memory architecture