add_short_term_memory
Store recent conversation messages as indexed short-term memory with keyword-based relevance scoring that decays over time.
Instructions
Add a new short-term memory entry from recent conversation messages. The memory will be indexed by keywords and scored based on relevance over time.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| messages | Yes | Array of recent messages to create memory from | |
| conversation_id | Yes | Unique identifier for the conversation | |
| roleWeights | No | Optional weights for different roles when extracting keywords (default: user=2.7, assistant=2.0, system=1.0) |
Implementation Reference
- src/tools/short-term-tools.js:33-60 (handler)The core handler function for the 'add_short_term_memory' tool. It processes input arguments, adds the memory entry using ShortTermMemoryManager.addMemory(), persists the memories to storage, and returns success status with total count.handler: async (args) => { try { const success = await memoryManager.addMemory( args.messages, args.conversation_id, { roleWeights: args.roleWeights } ); if (success) { await storageManager.saveShortTermMemories(memoryManager.getMemories()); return { success: true, message: 'Memory added successfully', totalMemories: memoryManager.getMemories().length }; } else { return { success: false, message: 'Failed to add memory (possibly empty content)' }; } } catch (error) { return { success: false, error: error.message }; } }
- src/tools/short-term-tools.js:20-32 (schema)Zod schema defining the input structure for the tool, including messages array, conversation_id, and optional roleWeights.inputSchema: z.object({ messages: z.array(z.object({ role: z.enum(['user', 'assistant', 'system']).describe('Message role'), content: z.string().describe('Message content'), timestamp: z.number().optional().describe('Unix timestamp in milliseconds') })).describe('Array of recent messages to create memory from'), conversation_id: z.string().describe('Unique identifier for the conversation'), roleWeights: z.object({ user: z.number().optional(), assistant: z.number().optional(), system: z.number().optional() }).optional().describe('Optional weights for different roles when extracting keywords (default: user=2.7, assistant=2.0, system=1.0)') }),
- src/index.js:284-289 (registration)Dynamic registration and execution of short-term tools (including add_short_term_memory) during tool calls, creating conversation-specific tool instances with appropriate managers.if (toolScope === 'short-term' || toolName.includes('short_term')) { manager = await getShortTermManager(conversationId); storage = getStorageManager(conversationId); const tools = createShortTermTools(manager, storage, queryCache); const tool = tools.find(t => t.name === toolName); result = await withTimeout(tool.handler(validatedArgs), timeout, `Tool ${toolName} timeout`);
- src/index.js:153-155 (registration)Initial registration of default short-term tools for list_tools response using default managers.const shortTermTools = createShortTermTools(defaultShortTermManager, defaultStorageManager); shortTermTools.forEach(tool => registerTool(tool, 'short-term'));