get_memory_by_agent
Retrieve all stored memory entries for a specific agent to access relevant context and information for AI interactions.
Instructions
Get all memory entries for a specific agent
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| agentId | Yes | ID of the agent to get memory for |
Input Schema (JSON Schema)
{
"properties": {
"agentId": {
"description": "ID of the agent to get memory for",
"type": "string"
}
},
"required": [
"agentId"
],
"type": "object"
}
Implementation Reference
- src/index.ts:174-187 (registration)Tool registration in the ListTools response, including name, description, and input schema.{ name: 'get_memory_by_agent', description: 'Get all memory entries for a specific agent', inputSchema: { type: 'object', properties: { agentId: { type: 'string', description: 'ID of the agent to get memory for', }, }, required: ['agentId'], }, },
- src/index.ts:446-456 (handler)MCP server tool handler that processes the get_memory_by_agent tool call by invoking the RAG service and formatting the response.private async handleGetMemoryByAgent(args: { agentId: string }) { const results = await this.ragService.getMemoryByAgent(args.agentId); return { content: [ { type: 'text', text: JSON.stringify(results, null, 2), }, ], }; }
- src/services/ragService.ts:211-219 (helper)RAG service method that delegates the getMemoryByAgent call to the vector database service.async getMemoryByAgent(agentId: string): Promise<SearchResult[]> { try { logger.info(`Getting memory for agent: ${agentId}`); return await this.vectorDatabase.getMemoryByAgent(agentId); } catch (error) { logger.error(`Error getting memory by agent: ${error}`); throw new Error(`Failed to get memory by agent: ${error}`); } }
- src/services/vectorDatabase.ts:256-279 (handler)Core implementation that queries the Pinecone memory index using a metadata filter for the specified agentId to retrieve all associated memory entries.async getMemoryByAgent(agentId: string): Promise<SearchResult[]> { try { const results = await this.memoryIndex.query({ vector: new Array(CONFIG.EMBEDDING_DIMENSION).fill(0), // Dummy vector for metadata query topK: 10000, // Large number to get all memory entries includeMetadata: true, filter: { agentId } }); if (results.matches) { return results.matches.map((match: any) => ({ id: match.id, content: match.metadata?.content || '', metadata: match.metadata || {}, score: match.score || 1.0 })); } return []; } catch (error) { logger.error(`Error getting memory by agent: ${error}`); throw new Error(`Failed to get memory by agent: ${error}`); } }