search_long_term_memories
Retrieve relevant long-term memories from conversation history to maintain context and enable serendipitous recall.
Instructions
Search and activate relevant long-term memories based on current conversation context. Returns activated memories (whose triggers evaluated to true) and random memories for serendipity.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| messages | Yes | Recent conversation messages | |
| conversation_id | Yes | Current conversation ID | |
| participants | No | Optional participants information |
Implementation Reference
- src/tools/long-term-tools.js:196-223 (handler)The handler function that implements the core logic of the 'search_long_term_memories' tool. It processes input arguments to create context and invokes the LongTermMemoryManager to search and activate memories.handler: async (args) => { try { const context = { messages: args.messages, conversation_id: args.conversation_id, participants: args.participants || {} }; const results = await memoryManager.searchAndActivateMemories(context); const formatMemory = (mem) => ({ name: mem.name, prompt: mem.prompt, createdAt: mem.createdAt.toISOString(), updatedAt: mem.updatedAt?.toISOString() }); return { activated: results.activated.map(formatMemory), random: results.random.map(formatMemory), totalMemories: memoryManager.getMemories().length, formattedText: memoryManager.formatActivatedMemories(results.activated, results.random) }; } catch (error) { return { error: error.message }; }
- src/tools/long-term-tools.js:188-195 (schema)Zod input schema defining the expected parameters for the search_long_term_memories tool: recent messages, conversation ID, and optional participants.inputSchema: z.object({ messages: z.array(z.object({ role: z.enum(['user', 'assistant', 'system']), content: z.string() })).describe('Recent conversation messages'), conversation_id: z.string().describe('Current conversation ID'), participants: z.object({}).passthrough().optional().describe('Optional participants information') }),
- src/tools/long-term-tools.js:185-225 (registration)The complete tool definition object for 'search_long_term_memories' within the createLongTermTools function, which registers the tool by including it in the returned array of MCP tools.{ name: 'search_long_term_memories', description: 'Search and activate relevant long-term memories based on current conversation context. Returns activated memories (whose triggers evaluated to true) and random memories for serendipity.', inputSchema: z.object({ messages: z.array(z.object({ role: z.enum(['user', 'assistant', 'system']), content: z.string() })).describe('Recent conversation messages'), conversation_id: z.string().describe('Current conversation ID'), participants: z.object({}).passthrough().optional().describe('Optional participants information') }), handler: async (args) => { try { const context = { messages: args.messages, conversation_id: args.conversation_id, participants: args.participants || {} }; const results = await memoryManager.searchAndActivateMemories(context); const formatMemory = (mem) => ({ name: mem.name, prompt: mem.prompt, createdAt: mem.createdAt.toISOString(), updatedAt: mem.updatedAt?.toISOString() }); return { activated: results.activated.map(formatMemory), random: results.random.map(formatMemory), totalMemories: memoryManager.getMemories().length, formattedText: memoryManager.formatActivatedMemories(results.activated, results.random) }; } catch (error) { return { error: error.message }; } } },