Skip to main content
Glama

cleanup_memories

Remove old or low-relevance short-term memories to maintain system performance by deleting entries older than one year or with minimal relevance while preserving essential data.

Instructions

Manually trigger cleanup of old or low-relevance short-term memories. This removes memories older than 1 year or with very low relevance scores, keeping at least 512 memories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
conversation_idYesConversation ID for storage

Implementation Reference

  • MCP tool 'cleanup_memories' handler: triggers ShortTermMemoryManager.cleanup() and persists changes via storage.
    {
      name: 'cleanup_memories',
      description: 'Manually trigger cleanup of old or low-relevance short-term memories. This removes memories older than 1 year or with very low relevance scores, keeping at least 512 memories.',
      inputSchema: z.object({
        conversation_id: z.string().describe('Conversation ID for storage')
      }),
      handler: async (args) => {
        try {
          const removedCount = memoryManager.cleanup();
          await storageManager.saveShortTermMemories(memoryManager.getMemories());
    
          return {
            success: true,
            removedCount,
            remainingCount: memoryManager.getMemories().length,
            message: `Cleanup complete: removed ${removedCount} memor${removedCount === 1 ? 'y' : 'ies'}`
          };
        } catch (error) {
          return {
            success: false,
            error: error.message
          };
        }
      }
    },
  • Core cleanup logic in ShortTermMemoryManager: filters out memories older than 1 year or below relevance threshold, ensures minimum 512 retained by score.
    cleanup(currentTimeStamp = Date.now()) {
      const initialCount = this.memories.length;
      const oneYearAgo = currentTimeStamp - MEMORY_TTL_MS;
    
      const passingMemories = [];
      const failingMemories = [];
    
      for (const mem of this.memories) {
        const relevance = this.calculateRelevance(mem, [], currentTimeStamp, {});
        mem._relevance = relevance;
    
        if (mem.time_stamp.getTime() < oneYearAgo) {
          failingMemories.push(mem);
        } else if (relevance >= CLEANUP_MIN_SCORE_THRESHOLD) {
          passingMemories.push(mem);
        } else {
          failingMemories.push(mem);
        }
      }
    
      if (passingMemories.length >= MIN_RETAINED_MEMORIES) {
        this.memories = passingMemories;
      } else {
        const neededFromFailing = MIN_RETAINED_MEMORIES - passingMemories.length;
        failingMemories.sort((a, b) => b._relevance - a._relevance);
        const supplementaryMemories = failingMemories.slice(0, neededFromFailing);
        this.memories = [...passingMemories, ...supplementaryMemories];
      }
    
      // 清理临时属性
      for (const mem of this.memories) {
        delete mem._relevance;
      }
    
      this.lastCleanupTime = currentTimeStamp;
      const removed = initialCount - this.memories.length;
      
      if (removed > 0) {
        console.log(`[Memory] Cleanup: removed ${removed} entries, ${this.memories.length} remaining`);
      }
    
      return removed;
    }
  • Input schema for cleanup_memories tool: requires conversation_id.
    inputSchema: z.object({
      conversation_id: z.string().describe('Conversation ID for storage')
    }),
  • src/index.js:152-154 (registration)
    Registers all short-term tools including cleanup_memories to the toolRegistry.
    // 注册所有短期记忆工具
    const shortTermTools = createShortTermTools(defaultShortTermManager, defaultStorageManager);
    shortTermTools.forEach(tool => registerTool(tool, 'short-term'));
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses that the tool performs a destructive action ('removes memories') and specifies behavioral traits like cleanup criteria and retention rules. However, it lacks details on permissions, rate limits, or what happens if the conversation_id is invalid, leaving some behavioral aspects unclear.

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 front-loaded with the core purpose in the first sentence, followed by specific behavioral details in the second sentence. It is appropriately sized with zero wasted words, making it efficient and easy to parse.

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 (destructive cleanup operation), lack of annotations, and no output schema, the description is moderately complete. It covers the what and how of cleanup but misses contextual details like error handling, confirmation prompts, or side effects, which are important for a mutation tool with no structured safety hints.

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 the 'conversation_id' parameter. The description does not add any additional meaning or context about this parameter beyond what the schema provides, such as how it affects the cleanup process. Baseline 3 is appropriate as the schema handles the parameter documentation.

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 ('manually trigger cleanup') and resource ('old or low-relevance short-term memories'), with specific criteria for removal (older than 1 year or low relevance scores) and a retention minimum (keeping at least 512 memories). However, it does not explicitly differentiate from siblings like 'delete_short_term_memories', which might handle more targeted deletions.

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 implies usage for maintenance purposes ('manually trigger cleanup') and specifies criteria (age and relevance), but does not provide explicit guidance on when to use this tool versus alternatives like 'delete_short_term_memories' or 'backup_memories', nor does it mention prerequisites or exclusions.

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