Skip to main content
Glama

memory_optimization_metrics

Analyze memory usage patterns to identify optimization opportunities and receive actionable recommendations for improving application performance.

Instructions

Get comprehensive optimization metrics and recommendations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
includeRecommendationsNo
timeRangeNo

Implementation Reference

  • Registration of the 'memory_optimization_metrics' tool in the memoryTools export array, defining name, description, and input schema.
    {
      name: "memory_optimization_metrics",
      description: "Get comprehensive optimization metrics and recommendations",
      inputSchema: {
        type: "object",
        properties: {
          includeRecommendations: { type: "boolean", default: true },
          timeRange: {
            type: "object",
            properties: {
              start: { type: "string", format: "date-time" },
              end: { type: "string", format: "date-time" },
            },
          },
        },
      },
    },
  • Primary handler logic for memory optimization metrics via MemoryPruningSystem.getOptimizationMetrics(), computing key metrics like storage size, compression ratio, and entry counts.
    async getOptimizationMetrics(): Promise<OptimizationMetrics> {
      const allEntries = await this.storage.getAll();
      const totalEntries = allEntries.length;
    
      // Calculate storage size (approximate)
      const storageSize =
        allEntries.reduce((total, entry) => {
          return total + JSON.stringify(entry).length;
        }, 0) /
        (1024 * 1024); // Convert to MB
    
      // Calculate index size (approximate)
      const indexSize = (totalEntries * 100) / (1024 * 1024); // Rough estimate
    
      // Calculate compression ratio
      const compressedEntries = allEntries.filter((e) => this.isCompressed(e));
      const compressionRatio = compressedEntries.length / totalEntries;
    
      return {
        totalEntries,
        storageSize,
        indexSize,
        compressionRatio,
        duplicatesRemoved: 0, // Would be tracked during runtime
        entriesPruned: 0, // Would be tracked during runtime
        performanceGain: 0, // Would be calculated based on before/after metrics
        lastOptimization: new Date(),
      };
    }
  • Supporting method getPruningRecommendations() that generates optimization recommendations based on current metrics, matching the tool's includeRecommendations option.
    async getPruningRecommendations(): Promise<{
      shouldPrune: boolean;
      reasons: string[];
      estimatedSavings: number;
      recommendedPolicy: Partial<PruningPolicy>;
    }> {
      const metrics = await this.getOptimizationMetrics();
      const reasons: string[] = [];
      let shouldPrune = false;
      let estimatedSavings = 0;
    
      // Check storage size
      if (metrics.storageSize > this.defaultPolicy.maxSize * 0.8) {
        shouldPrune = true;
        reasons.push(
          `Storage size (${metrics.storageSize.toFixed(2)}MB) approaching limit`,
        );
        estimatedSavings += metrics.storageSize * 0.2;
      }
    
      // Check entry count
      if (metrics.totalEntries > this.defaultPolicy.maxEntries * 0.8) {
        shouldPrune = true;
        reasons.push(`Entry count (${metrics.totalEntries}) approaching limit`);
      }
    
      // Check compression ratio
      if (metrics.compressionRatio < 0.3) {
        reasons.push("Low compression ratio indicates optimization opportunity");
        estimatedSavings += metrics.storageSize * 0.15;
      }
    
      // Time-based recommendation
      const daysSinceLastOptimization =
        (Date.now() - metrics.lastOptimization.getTime()) / (24 * 60 * 60 * 1000);
      if (daysSinceLastOptimization > 7) {
        shouldPrune = true;
        reasons.push("Regular maintenance window (weekly optimization)");
      }
    
      return {
        shouldPrune,
        reasons,
        estimatedSavings,
        recommendedPolicy: {
          maxAge: Math.max(30, this.defaultPolicy.maxAge - 30), // More aggressive if needed
          compressionThreshold: Math.max(
            7,
            this.defaultPolicy.compressionThreshold - 7,
          ),
        },
      };
    }
  • TypeScript interface defining the structure of OptimizationMetrics returned by the tool implementation.
    export interface OptimizationMetrics {
      totalEntries: number;
      storageSize: number;
      indexSize: number;
      compressionRatio: number;
      duplicatesRemoved: number;
      entriesPruned: number;
      performanceGain: number;
      lastOptimization: Date;
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool 'gets' metrics and recommendations, implying a read-only operation, but doesn't cover aspects like authentication needs, rate limits, side effects, or response format. For a tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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 that front-loads the core purpose ('Get comprehensive optimization metrics and recommendations'). There's no wasted text, making it appropriately concise for its content, though it could benefit from more detail given the lack of annotations and schema coverage.

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 complexity (2 parameters with 0% schema coverage, no annotations, no output schema, and nested objects), the description is incomplete. It doesn't explain what 'optimization metrics' entail, how recommendations are generated, the structure of the 'timeRange' object, or the return format. For a tool with rich sibling context and no structured support, this is inadequate.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It mentions 'comprehensive optimization metrics and recommendations', which hints at the 'includeRecommendations' parameter but doesn't explain the 'timeRange' object or provide any details on parameter usage, formats, or defaults. The description adds minimal value beyond the schema.

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 'Get comprehensive optimization metrics and recommendations' clearly states the action (get) and target (optimization metrics and recommendations), but it's somewhat vague about what 'comprehensive' entails and doesn't differentiate from sibling tools like 'memory_insights' or 'memory_intelligent_analysis'. It avoids tautology but lacks specificity about the optimization domain.

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. With many sibling tools related to memory and analysis (e.g., 'memory_insights', 'memory_intelligent_analysis'), there's no indication of context, prerequisites, or exclusions. Usage is implied only by the tool name, not described.

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/tosin2013/documcp'

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