Skip to main content
Glama

link_memories

Idempotent

Connect related memories in a knowledge graph to establish relationships between concepts. Define connections using relation types like depends_on, implements, or references.

Instructions

메모리 간 관계를 연결합니다 (지식 그래프).

키워드: 연결해, 관계 설정, 링크, connect memories, link, relate

사용 예시:

  • "project-architecture와 design-patterns를 연결해"

  • "이 두 메모리를 related_to로 링크해"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceKeyYes소스 메모리 키
targetKeyYes타겟 메모리 키
relationTypeYes관계 유형 (related_to, depends_on, implements, extends, uses)
strengthNo관계 강도 (0.0 ~ 1.0, 기본값: 1.0)
bidirectionalNo양방향 관계 여부 (기본값: false)

Implementation Reference

  • The primary handler function for the 'link_memories' tool. It parses arguments, verifies source and target memories exist, calls MemoryManager.linkMemories to create the relationship (and bidirectional if requested), and returns a formatted success or error message.
    export async function linkMemories(args: LinkMemoriesArgs): Promise<ToolResult> {
      try {
        const { sourceKey, targetKey, relationType, strength = 1.0, bidirectional = false } = args;
        const memoryManager = MemoryManager.getInstance();
    
        // Verify both memories exist
        const sourceMemory = memoryManager.recall(sourceKey);
        const targetMemory = memoryManager.recall(targetKey);
    
        if (!sourceMemory) {
          return {
            content: [{
              type: 'text',
              text: `✗ 소스 메모리를 찾을 수 없습니다: ${sourceKey}`
            }]
          };
        }
    
        if (!targetMemory) {
          return {
            content: [{
              type: 'text',
              text: `✗ 타겟 메모리를 찾을 수 없습니다: ${targetKey}`
            }]
          };
        }
    
        // Create the link
        const success = memoryManager.linkMemories(sourceKey, targetKey, relationType, strength);
    
        if (!success) {
          return {
            content: [{
              type: 'text',
              text: `✗ 관계 연결에 실패했습니다`
            }]
          };
        }
    
        // Create bidirectional link if requested
        if (bidirectional) {
          memoryManager.linkMemories(targetKey, sourceKey, relationType, strength);
        }
    
        const result = `✓ 메모리 관계가 연결되었습니다
    
    **소스**: ${sourceKey}
    **타겟**: ${targetKey}
    **관계 유형**: ${relationType}
    **강도**: ${strength}
    **양방향**: ${bidirectional ? '예' : '아니오'}
    
    이제 get_memory_graph로 관계를 시각화할 수 있습니다.`;
    
        return {
          content: [{
            type: 'text',
            text: result
          }]
        };
      } catch (error) {
        return {
          content: [{
            type: 'text',
            text: `✗ 오류: ${error instanceof Error ? error.message : '알 수 없는 오류'}`
          }]
        };
      }
    }
  • ToolDefinition object defining the 'link_memories' tool, including name, description, inputSchema with properties for sourceKey, targetKey, relationType, strength, bidirectional, and annotations.
    export const linkMemoriesDefinition: ToolDefinition = {
      name: 'link_memories',
      description: `메모리 간 관계를 연결합니다 (지식 그래프).
    
    키워드: 연결해, 관계 설정, 링크, connect memories, link, relate
    
    사용 예시:
    - "project-architecture와 design-patterns를 연결해"
    - "이 두 메모리를 related_to로 링크해"`,
      inputSchema: {
        type: 'object',
        properties: {
          sourceKey: {
            type: 'string',
            description: '소스 메모리 키'
          },
          targetKey: {
            type: 'string',
            description: '타겟 메모리 키'
          },
          relationType: {
            type: 'string',
            description: '관계 유형 (related_to, depends_on, implements, extends, uses)',
            enum: ['related_to', 'depends_on', 'implements', 'extends', 'uses', 'references', 'part_of']
          },
          strength: {
            type: 'number',
            description: '관계 강도 (0.0 ~ 1.0, 기본값: 1.0)',
            minimum: 0,
            maximum: 1
          },
          bidirectional: {
            type: 'boolean',
            description: '양방향 관계 여부 (기본값: false)'
          }
        },
        required: ['sourceKey', 'targetKey', 'relationType']
      },
      annotations: {
        title: 'Link Memories',
        audience: ['user', 'assistant'],
        readOnlyHint: false,
        destructiveHint: false,
        idempotentHint: true,
        openWorldHint: false
      }
    };
  • src/index.ts:169-169 (registration)
    Registration of the linkMemories handler function in the toolHandlers object, used for dynamic dispatch in CallToolRequestSchema.
    'link_memories': linkMemories,
  • src/index.ts:102-102 (registration)
    Inclusion of linkMemoriesDefinition in the tools array, used for ListToolsRequestSchema to expose the tool schema.
    linkMemoriesDefinition,
  • Core MemoryManager.linkMemories method that inserts or updates the relationship record in the memory_relations SQLite table, called by the tool handler.
    public linkMemories(
      sourceKey: string,
      targetKey: string,
      relationType: string,
      strength: number = 1.0,
      metadata?: Record<string, any>
    ): boolean {
      const timestamp = new Date().toISOString();
      const metadataJson = metadata ? JSON.stringify(metadata) : null;
    
      try {
        const stmt = this.db.prepare(`
          INSERT OR REPLACE INTO memory_relations
          (sourceKey, targetKey, relationType, strength, metadata, timestamp)
          VALUES (?, ?, ?, ?, ?, ?)
        `);
        stmt.run(sourceKey, targetKey, relationType, strength, metadataJson, timestamp);
        return true;
      } catch (error) {
        return false;
      }
    }
Behavior3/5

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

Annotations already provide key behavioral hints: readOnlyHint=false (mutation), destructiveHint=false (non-destructive), idempotentHint=true (safe to retry). The description adds context about it being for '지식 그래프' (knowledge graph) relationships, which clarifies the domain beyond what annotations state. However, it doesn't disclose additional traits like potential side effects, authentication needs, or rate limits that aren't covered by annotations.

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 appropriately sized with a clear purpose statement upfront, followed by keywords and usage examples. Every sentence earns its place by providing practical guidance. However, the mixed Korean/English keywords and examples could be slightly more streamlined, and the structure isn't perfectly front-loaded with all critical information.

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

Completeness3/5

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

Given the tool's complexity (5 parameters, mutation operation, no output schema), the description is minimally adequate. It covers the core purpose and provides usage hints, but lacks details on return values, error conditions, or relationship management nuances. With annotations covering safety aspects and schema covering parameters, the description meets basic needs but doesn't fully address the contextual gaps for a knowledge graph linking tool.

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%, with all parameters well-documented in the schema (e.g., relationType enum values, strength range, bidirectional default). The description adds no parameter-specific information beyond what's in the schema. Examples mention 'related_to' and linking two memories, but these are already implied by parameter names. Baseline 3 is appropriate given high schema coverage.

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

Purpose4/5

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

The description clearly states the tool's purpose as '메모리 간 관계를 연결합니다 (지식 그래프)' (links relationships between memories/knowledge graph), which is a specific verb+resource combination. It distinguishes this from sibling tools like 'create_memory_timeline' or 'get_memory_graph' by focusing on relationship linking rather than creation or retrieval. However, it doesn't explicitly contrast with 'update_memory' which might also modify relationships.

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

Usage Guidelines3/5

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

The description provides keywords and usage examples that imply context for when to use this tool (e.g., 'connect memories, link, relate' and examples like linking 'project-architecture' with 'design-patterns'). However, it lacks explicit guidance on when NOT to use it or alternatives among siblings (e.g., vs. 'update_memory' for modifying existing links). The examples are helpful but don't constitute full usage guidelines.

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/su-record/hi-ai'

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