cleanup_expired_working_memory
Removes expired working memories from the AGI MCP Server's persistent storage system to maintain efficient memory management and free up resources.
Instructions
Clean up expired working memories
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/memory-manager.js:486-503 (handler)The actual implementation that deletes expired working memory records from the database. It queries the working_memory table for records where expiry is not null and less than or equal to current timestamp, then deletes and returns them.
async cleanupExpiredWorkingMemory() { try { const expired = await this.db .delete(schema.workingMemory) .where( and( isNotNull(schema.workingMemory.expiry), lte(schema.workingMemory.expiry, new Date()) ) ) .returning(); return expired; } catch (error) { console.error('Error cleaning up expired working memory:', error); throw error; } } - src/db/schema.js:29-35 (schema)Database schema definition for the working_memory table that includes the expiry timestamp field used to identify expired records.
export const workingMemory = pgTable("working_memory", { id: uuid().defaultRandom().primaryKey().notNull(), createdAt: timestamp("created_at", { withTimezone: true, mode: 'string' }).default(sql`CURRENT_TIMESTAMP`), content: text().notNull(), embedding: vector({ dimensions: 1536 }).notNull(), expiry: timestamp({ withTimezone: true, mode: 'string' }), }); - src/tools/memory-tools.js:424-431 (registration)Tool schema definition in the memory-tools module that defines the input/output structure for cleanup_expired_working_memory tool.
{ name: "cleanup_expired_working_memory", description: "Clean up expired working memories", inputSchema: { type: "object", properties: {} } }, - mcp.js:450-457 (registration)MCP tool registration that exposes cleanup_expired_working_memory as an available tool to MCP clients.
{ name: "cleanup_expired_working_memory", description: "Clean up expired working memories", inputSchema: { type: "object", properties: {} } }, - mcp.js:670-672 (handler)MCP request handler that routes cleanup_expired_working_memory tool calls to the MemoryManager's cleanupExpiredWorkingMemory method and returns the cleaned memories as JSON.
case "cleanup_expired_working_memory": const cleanedMemories = await memoryManager.cleanupExpiredWorkingMemory(); return { content: [{ type: "text", text: JSON.stringify(cleanedMemories, null, 2) }] };