Skip to main content
Glama

Configure Memory Optimization

configure_memory_optimization

Configure memory file path, toggle auto-optimization, and adjust token growth threshold to control memory optimization behavior.

Instructions

Configure memory optimization settings for auto-optimization behavior.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
memory_fileNo
auto_optimizeNo
token_growth_thresholdNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'configure_memory_optimization' tool. It updates memory file frontmatter settings (autoOptimize, tokenGrowthThreshold), removes deprecated fields, and writes a backup.
    def configure_memory_optimization(
        memory_file: Annotated[Optional[str], "Path to memory file to configure"] = None,
        auto_optimize: Annotated[Optional[bool], "Enable/disable auto-optimization"] = None,
        token_growth_threshold: Annotated[Optional[float], "Token growth threshold (e.g., 1.20 = 20% growth)"] = None,
    ) -> str:
        """Configure memory optimization settings."""
        if read_only:
            return "Error: Server is running in read-only mode"
    
        try:
            # Determine which file to configure
            if memory_file:
                file_path = Path(memory_file)
                if not file_path.exists():
                    return f"Error: Memory file not found: {memory_file}"
            else:
                # Use default user memory file
                user_memory_path = instruction_manager.get_memory_file_path()
                if not user_memory_path.exists():
                    return "Error: No user memory file found to configure"
                file_path = user_memory_path
    
            # Read current frontmatter
            from ..simple_file_ops import parse_frontmatter_file, write_frontmatter_file
    
            frontmatter, content = parse_frontmatter_file(file_path)
    
            # Update settings
            updated_settings = []
            if auto_optimize is not None:
                frontmatter["autoOptimize"] = auto_optimize
                updated_settings.append(f"auto_optimize: {auto_optimize}")
    
            if token_growth_threshold is not None:
                if token_growth_threshold < 1.0:
                    return "Error: token_growth_threshold must be >= 1.0 (e.g., 1.20 = 20% growth)"
                frontmatter["tokenGrowthThreshold"] = token_growth_threshold
                growth_percent = int((token_growth_threshold - 1.0) * 100)
                updated_settings.append(f"token_growth_threshold: {token_growth_threshold} ({growth_percent}% growth)")
    
            # Remove deprecated fields if they exist
            deprecated_removed = []
            for old_field in ["sizeThreshold", "entryThreshold", "timeThreshold"]:
                if old_field in frontmatter:
                    frontmatter.pop(old_field)
                    deprecated_removed.append(old_field)
    
            if not updated_settings and not deprecated_removed:
                return "No settings provided to update. Available options: auto_optimize, token_growth_threshold"
    
            # Write updated frontmatter
            success = write_frontmatter_file(file_path, frontmatter, content, create_backup=True)
    
            if success:
                message = "āœ… Memory optimization settings updated:\n"
                for setting in updated_settings:
                    message += f"• {setting}\n"
                if deprecated_removed:
                    message += "\n🧹 Removed deprecated settings: " + ", ".join(deprecated_removed) + "\n"
                message += "\nšŸ’¾ Backup created for safety"
                return message
            else:
                return "āŒ Failed to update memory optimization settings"
    
        except Exception as e:
            return f"Error configuring memory optimization: {str(e)}"
  • Registration decorator for the tool via @app.tool, defining name, description, tags, annotations (parameters, title), and metadata.
    @app.tool(
        name="configure_memory_optimization",
        description="Configure memory optimization settings for auto-optimization behavior.",
        tags={"public", "memory"},
        annotations={
            "idempotentHint": False,
            "readOnlyHint": False,
            "title": "Configure Memory Optimization",
            "parameters": {
                "memory_file": "Optional path to specific memory file. If not provided, will configure the user's main memory file.",
                "auto_optimize": "Enable or disable automatic optimization. True/False.",
                "token_growth_threshold": "Token growth multiplier for triggering optimization (e.g., 1.20 = 20% growth). Must be >= 1.0.",
            },
            "returns": "Returns confirmation of updated settings.",
        },
        meta={
            "category": "memory",
        },
    )
  • The register_memory_tools() function that retrieves the server registry and app instance used to register tools.
    def register_memory_tools() -> None:
        """Register all memory optimization tools with the server."""
        registry = get_server_registry()
        app = registry.app
        instruction_manager = registry.instruction_manager
        read_only = registry.read_only
  • The parse_frontmatter_file helper used within the handler to read and parse YAML frontmatter from memory files.
    def parse_frontmatter_file(file_path: Union[str, Path]) -> Tuple[Dict[str, Any], str]:
        """
        Parse a file with YAML frontmatter.
    
        Args:
            file_path: Path to the file
    
        Returns:
            Tuple of (frontmatter_dict, content_string)
    
        Raises:
            FileOperationError: If file cannot be parsed
        """
        try:
            with open(file_path, "r", encoding="utf-8") as f:
                content = f.read()
        except Exception as e:
            raise FileOperationError(f"Could not read file {file_path}: {e}")
    
        return parse_frontmatter(content)
Behavior2/5

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

Annotations already indicate mutation (readOnlyHint=false) and non-idempotency. Description adds no additional behavioral details such as side effects, permissions, or state changes.

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

Conciseness2/5

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

Extremely concise at 6 words, but under-specification for a tool with 3 parameters and no schema descriptions. Conciseness sacrifices necessary detail.

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

Completeness1/5

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

Given zero parameter descriptions and missing output schema explanation, the description is insufficient for correct tool invocation. Lacks parameter meanings and usage scenarios.

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

Parameters1/5

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

Schema description coverage is 0% and description does not explain any of the three parameters (memory_file, auto_optimize, token_growth_threshold). Agent has no semantic guidance for input values.

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?

Description clearly states the tool configures memory optimization settings for auto-optimization behavior. It distinguishes from sibling 'optimize_memory' by focusing on configuration rather than execution.

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 provided on when to use this tool versus alternatives like 'optimize_memory' or 'memory_stats'. Agent must infer context from tool names.

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/NiclasOlofsson/mode-manager-mcp'

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