Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
agentIdYesID of the agent to get memory for

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'],
      },
    },
  • 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),
          },
        ],
      };
    }
  • 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}`);
      }
    }
  • 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}`);
      }
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/santis84/mcp-rag'

If you have feedback or need assistance with the MCP directory API, please join our Discord server