Skip to main content
Glama

find_related_memories

Traverse memory graphs to discover related memories by exploring connections from a starting point, with configurable depth and relationship strength parameters.

Instructions

Find memories related through graph traversal

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
memory_idYesUUID of the starting memory
max_depthNoMaximum depth to traverse
min_strengthNoMinimum relationship strength

Implementation Reference

  • mcp.js:618-624 (handler)
    Tool handler that executes find_related_memories - extracts args.memory_id, args.max_depth (default 2), and args.min_strength (default 0.3), then calls memoryManager.findRelatedMemories() and returns JSON stringified results
    case "find_related_memories":
      const relatedMemories = await memoryManager.findRelatedMemories(
        args.memory_id,
        args.max_depth || 2,
        args.min_strength || 0.3
      );
      return { content: [{ type: "text", text: JSON.stringify(relatedMemories, null, 2) }] };
  • Core implementation using recursive CTE to traverse memory relationship graph up to maxDepth, filtering by minimum strength and avoiding cycles. Returns related memories with content, type, importance ordered by strength descending and depth ascending.
    async findRelatedMemories(memoryId, maxDepth = 2, minStrength = 0.3) {
      try {
        // Use recursive CTE to find related memories up to maxDepth
        const results = await this.db.execute(sql`
          WITH RECURSIVE memory_graph AS (
            -- Base case: direct relationships
            SELECT 
              mr.to_memory_id as memory_id,
              mr.relationship_type,
              mr.strength,
              1 as depth,
              ARRAY[mr.from_memory_id] as path
            FROM memory_relationships mr
            WHERE mr.from_memory_id = ${memoryId} AND mr.strength >= ${minStrength}
            
            UNION ALL
            
            -- Recursive case: follow relationships
            SELECT 
              mr.to_memory_id as memory_id,
              mr.relationship_type,
              mr.strength * mg.strength as strength,
              mg.depth + 1,
              mg.path || mr.from_memory_id
            FROM memory_relationships mr
            JOIN memory_graph mg ON mr.from_memory_id = mg.memory_id
            WHERE mg.depth < ${maxDepth}
              AND mr.strength >= ${minStrength}
              AND NOT (mr.to_memory_id = ANY(mg.path))
          )
          SELECT 
            mg.*,
            m.content,
            m.type,
            m.importance
          FROM memory_graph mg
          JOIN memories m ON mg.memory_id = m.id
          WHERE m.status = 'active'
          ORDER BY mg.strength DESC, mg.depth ASC
        `);
        
        return results.rows || [];
      } catch (error) {
        console.warn('Related memories query failed:', error.message);
        return [];
      }
    }
  • Tool schema definition defining input parameters: memory_id (required UUID string), max_depth (optional integer, default 2), min_strength (optional number, default 0.3)
    {
      name: "find_related_memories",
      description: "Find memories related through graph traversal",
      inputSchema: {
        type: "object",
        properties: {
          memory_id: {
            type: "string",
            description: "UUID of the starting memory"
          },
          max_depth: {
            type: "integer",
            description: "Maximum depth to traverse",
            default: 2
          },
          min_strength: {
            type: "number",
            description: "Minimum relationship strength",
            default: 0.3
          }
        },
        required: ["memory_id"]
      }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but lacks behavioral details. It doesn't disclose if this is read-only (likely, but not stated), what the output format is (e.g., list of memories, graph structure), performance implications (e.g., depth affects speed), or error handling (e.g., invalid memory_id). The phrase 'graph traversal' hints at complexity but doesn't clarify behavior beyond the basic action.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with no wasted words, making it easy to parse. However, it's under-specified rather than concise—it could benefit from slightly more detail (e.g., 'Find memories connected via relationship edges in a graph') without losing brevity, but it's not overly verbose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and a tool with graph traversal complexity (implied by parameters like max_depth and min_strength), the description is incomplete. It doesn't explain what 'related' means, the traversal algorithm, output format, or error cases, leaving significant gaps for an agent to use it correctly in context with siblings.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so parameters are well-documented in the schema. The description adds no additional meaning beyond implying traversal uses 'memory_id' as a start point and 'max_depth/min_strength' as limits, but this is already clear from schema descriptions. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Find memories related through graph traversal' states the action (find) and resource (memories) but is vague about scope and mechanism. It doesn't specify what 'related' means (e.g., by content, relationships, themes) or how graph traversal works, nor does it distinguish from siblings like 'find_similar_clusters' or 'search_memories_similarity', leaving ambiguity about when to use this versus other search tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., requires an existing memory ID), exclusions (e.g., not for direct content search), or compare to siblings like 'search_memories_advanced' or 'get_memory_relationships', leaving the agent to guess based on the name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/randyandrade/agi-mcp-server'

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