consolidate
Compress old working memories into dense long-term summaries using AI, archiving originals to optimize storage and maintain semantic context.
Instructions
Consolidate old working memories into dense long-term summaries via LLM. Archives originals.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session identifier | |
| batch | No | Number of memories to consolidate (default 50) | |
| keep | No | Most recent N to leave untouched (default 20) | |
| dryRun | No | Preview summaries without writing (default false) |
Implementation Reference
- src/index.ts:253-260 (handler)Handler for the 'consolidate' tool that executes when the tool is called. Extracts arguments (sessionId, batch, keep, dryRun) and calls memory.consolidate() from the Engram library, returning the result as JSON.
case 'consolidate': { const result = await memory.consolidate(args.sessionId as string, { batch: args.batch as number | undefined, keep: args.keep as number | undefined, dryRun: args.dryRun as boolean | undefined, }); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; } - src/index.ts:103-116 (registration)Registration of the 'consolidate' tool with the MCP server. Defines the tool name, description, and input schema including sessionId (required), batch, keep, and dryRun parameters.
{ name: 'consolidate', description: 'Consolidate old working memories into dense long-term summaries via LLM. Archives originals.', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'Session identifier' }, batch: { type: 'number', description: 'Number of memories to consolidate (default 50)' }, keep: { type: 'number', description: 'Most recent N to leave untouched (default 20)' }, dryRun: { type: 'boolean', description: 'Preview summaries without writing (default false)' }, }, required: ['sessionId'], }, }, - src/index.ts:106-115 (schema)Input schema definition for the 'consolidate' tool. Specifies the parameters: sessionId (required string), batch (optional number for memories to consolidate), keep (optional number for recent memories to preserve), and dryRun (optional boolean for preview mode).
inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'Session identifier' }, batch: { type: 'number', description: 'Number of memories to consolidate (default 50)' }, keep: { type: 'number', description: 'Most recent N to leave untouched (default 20)' }, dryRun: { type: 'boolean', description: 'Preview summaries without writing (default false)' }, }, required: ['sessionId'], }, - src/index.ts:16-27 (helper)Configuration setup for the consolidate functionality. Defines CONSOLIDATE_MODEL environment variable default and initializes the Engram memory instance with consolidate model configuration.
const CONSOLIDATE_MODEL = process.env.ENGRAM_CONSOLIDATE_MODEL || 'qwen2.5:32b'; const dbDir = path.dirname(DB_PATH); if (!fs.existsSync(dbDir)) fs.mkdirSync(dbDir, { recursive: true }); const memory = new Engram({ dbPath: DB_PATH, embeddingUrl: EMBEDDING_URL, semanticSearch: true, graphMemory: process.env.ENGRAM_GRAPH === '1', graphModel: GRAPH_MODEL, consolidateModel: CONSOLIDATE_MODEL,