Skip to main content
Glama

update_long_term_memory

Modify existing long-term memory entries by adjusting trigger conditions, updating content, or adding context to improve recall accuracy.

Instructions

Update an existing long-term memory. You can update the trigger condition, prompt content, or add update context.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesName of the memory to update
triggerNoNew trigger condition (JavaScript code)
promptNoNew memory content
conversation_idNoConversation ID that owns this memory
updatedContextNoContext about this update
recentMessagesNoOptional recent messages to auto-generate updatedContext

Implementation Reference

  • The main handler function for the 'update_long_term_memory' MCP tool. It handles input arguments, optionally generates updatedContext from recentMessages using createContextSnapshot, prepares the updates object, calls memoryManager.updateMemory, persists changes via storageManager, and returns appropriate success/error responses.
    handler: async (args) => {
      try {
        // Auto-generate context if messages provided
        let updatedContext = args.updatedContext;
        if (!updatedContext && args.recentMessages) {
          updatedContext = createContextSnapshot(args.recentMessages, 4);
        }
    
        const updates = {
          trigger: args.trigger,
          prompt: args.prompt,
          updatedContext
        };
    
        // Remove undefined values
        Object.keys(updates).forEach(key => {
          if (updates[key] === undefined) delete updates[key];
        });
    
        const result = await memoryManager.updateMemory(args.name, updates);
    
        if (result.success) {
          await storageManager.saveLongTermMemories(memoryManager.getMemories());
          return {
            success: true,
            message: `Memory "${args.name}" updated successfully`
          };
        } else {
          return {
            success: false,
            error: result.error
          };
        }
      } catch (error) {
        return {
          success: false,
          error: error.message
        };
      }
    }
  • Zod input schema defining parameters for updating a long-term memory: name (required), optional trigger, prompt, conversation_id, updatedContext, and recentMessages for auto-generating context.
    inputSchema: z.object({
      name: z.string().describe('Name of the memory to update'),
      trigger: z.string().optional().describe('New trigger condition (JavaScript code)'),
      prompt: z.string().optional().describe('New memory content'),
      conversation_id: z.string().optional().describe('Conversation ID that owns this memory'),
      updatedContext: z.string().optional().describe('Context about this update'),
      recentMessages: z.array(z.object({
        role: z.enum(['user', 'assistant', 'system']),
        content: z.string()
      })).optional().describe('Optional recent messages to auto-generate updatedContext')
    }),
  • The complete tool definition object for 'update_long_term_memory' exported via createLongTermTools function, which is registered in src/index.js by calling createLongTermTools and adding to tool registry.
    {
      name: 'update_long_term_memory',
      description: 'Update an existing long-term memory. You can update the trigger condition, prompt content, or add update context.',
      inputSchema: z.object({
        name: z.string().describe('Name of the memory to update'),
        trigger: z.string().optional().describe('New trigger condition (JavaScript code)'),
        prompt: z.string().optional().describe('New memory content'),
        conversation_id: z.string().optional().describe('Conversation ID that owns this memory'),
        updatedContext: z.string().optional().describe('Context about this update'),
        recentMessages: z.array(z.object({
          role: z.enum(['user', 'assistant', 'system']),
          content: z.string()
        })).optional().describe('Optional recent messages to auto-generate updatedContext')
      }),
      handler: async (args) => {
        try {
          // Auto-generate context if messages provided
          let updatedContext = args.updatedContext;
          if (!updatedContext && args.recentMessages) {
            updatedContext = createContextSnapshot(args.recentMessages, 4);
          }
    
          const updates = {
            trigger: args.trigger,
            prompt: args.prompt,
            updatedContext
          };
    
          // Remove undefined values
          Object.keys(updates).forEach(key => {
            if (updates[key] === undefined) delete updates[key];
          });
    
          const result = await memoryManager.updateMemory(args.name, updates);
    
          if (result.success) {
            await storageManager.saveLongTermMemories(memoryManager.getMemories());
            return {
              success: true,
              message: `Memory "${args.name}" updated successfully`
            };
          } else {
            return {
              success: false,
              error: result.error
            };
          }
        } catch (error) {
          return {
            success: false,
            error: error.message
          };
        }
      }
    },
  • Core updateMemory method in LongTermMemoryManager class that finds the memory by name, validates new trigger if provided, applies updates to trigger/prompt/updatedContext/modalities, sets updatedAt timestamp, and returns success status. Called by the tool handler.
    async updateMemory(name, updates) {
      const memoryIndex = this.memories.findIndex(mem => mem.name === name);
      
      if (memoryIndex === -1) {
        return {
          success: false,
          error: `Memory "${name}" not found`
        };
      }
    
      // 如果更新触发条件,先验证
      if (updates.trigger) {
        const testResult = await this.testTriggerCondition(updates.trigger);
        if (!testResult.valid) {
          return {
            success: false,
            error: `Invalid trigger condition: ${testResult.error?.message || 'Unknown error'}`
          };
        }
      }
    
      const memory = this.memories[memoryIndex];
    
      // 应用更新
      if (updates.trigger !== undefined) memory.trigger = updates.trigger;
      if (updates.prompt !== undefined) memory.prompt = updates.prompt;
      if (updates.updatedContext !== undefined) memory.updatedContext = updates.updatedContext;
    
      if (updates.modalities !== undefined || updates.attachments !== undefined) {
        const modalities = normalizeModalities(updates.modalities ?? updates.attachments ?? []);
        memory.modalities = modalities;
        memory.attachments = modalities;
      }
      
      memory.updatedAt = new Date();
    
      return { success: true };
    }
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 states this is an update operation, implying mutation, but lacks details on permissions, side effects, error conditions, or response format. For a mutation tool with zero annotation coverage, this is insufficient.

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

Conciseness5/5

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

The description is a single, efficient sentence that front-loads the core action and lists updatable elements without unnecessary words. Every part earns its place by conveying essential information.

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 this is a mutation tool with no annotations and no output schema, the description is incomplete. It lacks behavioral context (e.g., what happens on success/failure), usage prerequisites, and differentiation from siblings, making it inadequate for safe and effective tool invocation.

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 fully documents all 6 parameters. The description mentions 'trigger condition, prompt content, or add update context,' which loosely maps to parameters like 'trigger,' 'prompt,' and 'updatedContext,' but adds no significant meaning beyond what the schema already provides.

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 action ('Update') and resource ('existing long-term memory'), and specifies what can be updated (trigger condition, prompt content, or context). However, it doesn't explicitly differentiate from sibling tools like 'add_long_term_memory' or 'delete_long_term_memory' beyond the update action.

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., needing an existing memory), exclusions, or comparisons to siblings like 'add_long_term_memory' for creation or 'delete_long_term_memory' for removal.

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