add_memory
Store content in an agent's memory system for future retrieval, using categories, importance levels, and tags to organize information.
Instructions
Add information to the agent memory system
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| agentId | Yes | ID of the agent storing the memory | |
| category | No | Category for the memory entry (default: general) | general |
| content | Yes | Content to store in memory | |
| importance | No | Importance level 1-10 (default: 1) | |
| sessionId | Yes | ID of the current session | |
| tags | No | Tags for the memory entry |
Input Schema (JSON Schema)
{
"properties": {
"agentId": {
"description": "ID of the agent storing the memory",
"type": "string"
},
"category": {
"default": "general",
"description": "Category for the memory entry (default: general)",
"type": "string"
},
"content": {
"description": "Content to store in memory",
"type": "string"
},
"importance": {
"default": 1,
"description": "Importance level 1-10 (default: 1)",
"type": "number"
},
"sessionId": {
"description": "ID of the current session",
"type": "string"
},
"tags": {
"default": [],
"description": "Tags for the memory entry",
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"content",
"agentId",
"sessionId"
],
"type": "object"
}
Implementation Reference
- src/index.ts:94-131 (schema)Input schema and metadata for the 'add_memory' tool, registered in the ListToolsRequestSchema handler.{ name: 'add_memory', description: 'Add information to the agent memory system', inputSchema: { type: 'object', properties: { content: { type: 'string', description: 'Content to store in memory', }, agentId: { type: 'string', description: 'ID of the agent storing the memory', }, sessionId: { type: 'string', description: 'ID of the current session', }, category: { type: 'string', description: 'Category for the memory entry (default: general)', default: 'general', }, importance: { type: 'number', description: 'Importance level 1-10 (default: 1)', default: 1, }, tags: { type: 'array', items: { type: 'string' }, description: 'Tags for the memory entry', default: [], }, }, required: ['content', 'agentId', 'sessionId'], }, },
- src/index.ts:245-253 (registration)Tool dispatch/registration in the CallToolRequestSchema switch statement, routing to handleAddMemory.case 'add_memory': return await this.handleAddMemory(args as { content: string; agentId: string; sessionId: string; category?: string; importance?: number; tags?: string[]; });
- src/index.ts:386-411 (handler)Primary MCP tool handler `handleAddMemory` that executes the tool by calling RAGService.addMemory and returns standardized MCP content response.private async handleAddMemory(args: { content: string; agentId: string; sessionId: string; category?: string; importance?: number; tags?: string[]; }) { const result = await this.ragService.addMemory( args.content, args.agentId, args.sessionId, args.category, args.importance, args.tags ); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
- src/services/ragService.ts:120-165 (helper)Service layer implementation in RAGService.addMemory that constructs MemoryEntry with metadata and delegates persistence to vectorDatabase.async addMemory( content: string, agentId: string, sessionId: string, category: string = 'general', importance: number = 1, tags: string[] = [] ): Promise<{ success: boolean; memoryId: string; message: string; }> { try { const memoryId = uuidv4(); const memoryEntry: MemoryEntry = { id: memoryId, content, metadata: { agentId, sessionId, timestamp: new Date().toISOString(), category, importance, tags } }; await this.vectorDatabase.addMemory(memoryEntry); logger.info(`Added memory entry: ${memoryId}`); return { success: true, memoryId, message: 'Memory added successfully' }; } catch (error) { logger.error(`Error adding memory: ${error}`); return { success: false, memoryId: '', message: `Failed to add memory: ${error}` }; } }