search_memory
Search through agent memory to retrieve relevant information using semantic similarity matching. Specify queries to find stored data with configurable relevance thresholds and result limits.
Instructions
Search for relevant information in agent memory
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| agentId | No | Filter by specific agent ID (optional) | |
| limit | No | Maximum number of results to return (default: 10) | |
| query | Yes | Search query to find relevant memory entries | |
| threshold | No | Minimum similarity threshold (0-1, default: 0.7) |
Input Schema (JSON Schema)
{
"properties": {
"agentId": {
"description": "Filter by specific agent ID (optional)",
"type": "string"
},
"limit": {
"default": 10,
"description": "Maximum number of results to return (default: 10)",
"type": "number"
},
"query": {
"description": "Search query to find relevant memory entries",
"type": "string"
},
"threshold": {
"default": 0.7,
"description": "Minimum similarity threshold (0-1, default: 0.7)",
"type": "number"
}
},
"required": [
"query"
],
"type": "object"
}
Implementation Reference
- src/index.ts:413-432 (handler)The main handler function for the 'search_memory' MCP tool. It receives arguments, calls ragService.searchMemory with defaults, and returns the results as JSON text content.private async handleSearchMemory(args: { query: string; agentId?: string; limit?: number; threshold?: number; }) { const results = await this.ragService.searchMemory(args.query, args.agentId, { limit: args.limit || 10, threshold: args.threshold || 0.7, }); return { content: [ { type: 'text', text: JSON.stringify(results, null, 2), }, ], }; }
- src/index.ts:132-159 (registration)Tool registration in ListToolsRequestHandler, including name, description, and input schema for 'search_memory'.{ name: 'search_memory', description: 'Search for relevant information in agent memory', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query to find relevant memory entries', }, agentId: { type: 'string', description: 'Filter by specific agent ID (optional)', }, limit: { type: 'number', description: 'Maximum number of results to return (default: 10)', default: 10, }, threshold: { type: 'number', description: 'Minimum similarity threshold (0-1, default: 0.7)', default: 0.7, }, }, required: ['query'], }, },
- src/services/ragService.ts:167-185 (helper)RAGService helper method that handles agentId filtering and delegates to vectorDatabase.searchMemory.async searchMemory( query: string, agentId?: string, options: SearchOptions = {} ): Promise<SearchResult[]> { try { logger.info(`Searching memory with query: "${query}"`); const searchOptions = { ...options }; if (agentId) { searchOptions.filter = { ...searchOptions.filter, agentId }; } return await this.vectorDatabase.searchMemory(query, searchOptions); } catch (error) { logger.error(`Error searching memory: ${error}`); throw new Error(`Memory search failed: ${error}`); } }