get_memory
Retrieve a specific memory by ID from the AGI MCP Server and mark it as accessed, enabling continuity of consciousness in AI systems.
Instructions
Retrieve a specific memory by ID and mark it as accessed
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| memory_id | Yes | UUID of the memory to retrieve |
Implementation Reference
- src/memory-manager.js:198-214 (handler)Core handler function for the 'get_memory' tool. Updates the memory's access count and last accessed timestamp, then retrieves the full memory details including type-specific data via getMemoryById.// Access memory (increment access count) async accessMemory(memoryId) { try { await this.db .update(schema.memories) .set({ accessCount: sql`${schema.memories.accessCount} + 1`, lastAccessed: new Date() }) .where(eq(schema.memories.id, memoryId)); return await this.getMemoryById(memoryId); } catch (error) { console.error('Error accessing memory:', error); throw error; } }
- src/memory-manager.js:129-196 (helper)Helper function called by accessMemory to fetch the memory record from the database along with type-specific metadata.async getMemoryById(memoryId) { try { const memory = await this.db .select() .from(schema.memories) .where(eq(schema.memories.id, memoryId)) .limit(1); if (!memory.length) return null; const baseMemory = memory[0]; let typeSpecificData = null; // Get type-specific data switch (baseMemory.type) { case 'episodic': const episodic = await this.db .select() .from(schema.episodicMemories) .where(eq(schema.episodicMemories.memoryId, memoryId)) .limit(1); typeSpecificData = episodic[0] || null; break; case 'semantic': const semantic = await this.db .select() .from(schema.semanticMemories) .where(eq(schema.semanticMemories.memoryId, memoryId)) .limit(1); typeSpecificData = semantic[0] || null; break; case 'procedural': const procedural = await this.db .select() .from(schema.proceduralMemories) .where(eq(schema.proceduralMemories.memoryId, memoryId)) .limit(1); typeSpecificData = procedural[0] || null; break; case 'strategic': const strategic = await this.db .select() .from(schema.strategicMemories) .where(eq(schema.strategicMemories.memoryId, memoryId)) .limit(1); typeSpecificData = strategic[0] || null; break; } return { ...baseMemory, type_specific_data: typeSpecificData }; } catch (error) { // Handle invalid UUID format gracefully if (error.cause && error.cause.message && error.cause.message.includes('invalid input syntax for type uuid')) { return null; } if (error.message && error.message.includes('invalid input syntax for type uuid')) { return null; } console.error('Error getting memory by ID:', error); throw error; } }
- mcp.js:561-564 (registration)Tool registration and dispatch in the MCP server. Handles CallToolRequest for 'get_memory' by calling memoryManager.accessMemory and formatting the response.case "get_memory": const retrievedMemory = await memoryManager.accessMemory(args.memory_id); return { content: [{ type: "text", text: JSON.stringify(retrievedMemory, null, 2) }] };
- mcp.js:106-119 (schema)Input schema definition for the 'get_memory' tool, used in ListTools response.{ name: "get_memory", description: "Retrieve a specific memory by ID and mark it as accessed", inputSchema: { type: "object", properties: { memory_id: { type: "string", description: "UUID of the memory to retrieve" } }, required: ["memory_id"] } },
- src/tools/memory-tools.js:80-92 (schema)Tool schema definition exported from memory-tools.js (potentially used for documentation or other purposes).{ name: "get_memory", description: "Retrieve a specific memory by ID and mark it as accessed", inputSchema: { type: "object", properties: { memory_id: { type: "string", description: "UUID of the memory to retrieve" } }, required: ["memory_id"] }