Skip to main content
Glama

add_long_term_memory

Store persistent memories that automatically activate when specific conversation conditions are met, using JavaScript triggers to determine relevance.

Instructions

Add a new long-term memory with a trigger condition. The trigger is JavaScript code that determines when this memory should be activated. Available context: context.messages (array), context.conversation_id (string), context.participants (object). Available functions: match_keys(messages, keywords, scope, depth), match_keys_all(messages, keywords, scope, depth).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesUnique name for the memory
promptYesThe memory content to be recalled when triggered
triggerYesJavaScript code that returns true/false to determine if memory should activate. Example: "match_keys(context.messages, ['birthday'], 'any') || new Date().getMonth() === 6"
conversation_idNoConversation ID that owns this memory (defaults to "default")
createdContextNoOptional context about when/why this memory was created
recentMessagesNoOptional recent messages to auto-generate createdContext

Implementation Reference

  • The main handler function for the 'add_long_term_memory' tool. It processes input arguments, auto-generates context if recentMessages provided, adds the memory via memoryManager.addMemory, saves to storage, and returns success/error response.
    handler: async (args) => {
      try {
        // Auto-generate context if messages provided
        let createdContext = args.createdContext || '';
        if (!createdContext && args.recentMessages) {
          createdContext = createContextSnapshot(args.recentMessages, 4);
        }
    
        const result = await memoryManager.addMemory({
          name: args.name,
          prompt: args.prompt,
          trigger: args.trigger,
          createdContext
        });
    
        if (result.success) {
          await storageManager.saveLongTermMemories(memoryManager.getMemories());
          return {
            success: true,
            message: `Memory "${args.name}" added successfully`,
            totalMemories: memoryManager.getMemories().length
          };
        } else {
          return {
            success: false,
            error: result.error
          };
        }
      } catch (error) {
        return {
          success: false,
          error: error.message
        };
      }
    }
  • Zod inputSchema defining parameters for the tool: name, prompt, trigger, conversation_id (opt), createdContext (opt), recentMessages (opt).
    inputSchema: z.object({
      name: z.string().describe('Unique name for the memory'),
      prompt: z.string().describe('The memory content to be recalled when triggered'),
      trigger: z.string().describe('JavaScript code that returns true/false to determine if memory should activate. Example: "match_keys(context.messages, [\'birthday\'], \'any\') || new Date().getMonth() === 6"'),
      conversation_id: z.string().optional().describe('Conversation ID that owns this memory (defaults to "default")'),
      createdContext: z.string().optional().describe('Optional context about when/why this memory was created'),
      recentMessages: z.array(z.object({
        role: z.enum(['user', 'assistant', 'system']),
        content: z.string()
      })).optional().describe('Optional recent messages to auto-generate createdContext')
    }),
  • src/index.js:156-158 (registration)
    Static registration of default long-term tools (including add_long_term_memory) to the toolRegistry for list_tools response.
    // 注册所有长期记忆工具
    const longTermTools = createLongTermTools(defaultLongTermManager, defaultStorageManager);
    longTermTools.forEach(tool => registerTool(tool, 'long-term'));
  • src/index.js:291-295 (registration)
    Dynamic registration/execution: recreates long-term tools with conversation-specific managers and calls the handler for 'add_long_term_memory' during tool invocation.
    manager = await getLongTermManager(conversationId);
    storage = getStorageManager(conversationId);
    const tools = createLongTermTools(manager, storage);
    const tool = tools.find(t => t.name === toolName);
    result = await withTimeout(tool.handler(validatedArgs), timeout, `Tool ${toolName} timeout`);
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes the trigger mechanism and available context/functions, which is helpful. However, it doesn't address critical behavioral aspects: whether this operation is idempotent, what permissions are required, how errors are handled, or what happens on success (e.g., confirmation message). For a creation tool with zero annotation coverage, this leaves significant gaps.

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 concise with two sentences. The first sentence states the core purpose, and the second provides technical details about the trigger. There's no wasted text, though it could be slightly more front-loaded with key behavioral information given the lack of annotations.

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 the tool's complexity (creating a persistent memory with custom JavaScript triggers), no annotations, and no output schema, the description is incomplete. It doesn't explain what the tool returns, how to verify success, error conditions, or the implications of adding a memory (e.g., storage limits, trigger evaluation frequency). For a 6-parameter creation tool with behavioral nuances, this is inadequate.

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 the schema already documents all 6 parameters thoroughly. The description adds minimal value beyond the schema: it mentions the trigger is 'JavaScript code' and lists available context/functions, which the schema's trigger description also covers with an example. This meets the baseline of 3 when the schema does the heavy lifting.

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: 'Add a new long-term memory with a trigger condition.' It specifies the verb ('Add'), resource ('long-term memory'), and key mechanism ('trigger condition'), distinguishing it from siblings like 'update_long_term_memory' or 'delete_long_term_memory'. However, it doesn't explicitly differentiate from 'add_short_term_memory' beyond the resource name.

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?

The description provides no guidance on when to use this tool versus alternatives. It mentions the trigger condition but doesn't explain when to choose long-term over short-term memory, when to use this versus 'update_long_term_memory', or any prerequisites. The agent must infer usage from the tool 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/win10ogod/memory-mcp-server'

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