Skip to main content
Glama

gc

Remove or archive low-scoring memories that have fallen below the forget threshold to prevent database growth and maintain memory efficiency.

Instructions

Perform garbage collection on low-scoring memories.

Removes or archives memories whose decay score has fallen below the
forget threshold. This prevents the database from growing indefinitely
with unused memories.

Args:
    dry_run: Preview what would be removed without actually removing.
    archive_instead: Archive memories instead of deleting.
    limit: Maximum number of memories to process.

Returns:
    Statistics about removed/archived memories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
archive_insteadNo
dry_runNo
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'gc' MCP tool. It performs garbage collection on low-scoring memories, with options for dry-run, archiving instead of deletion, and limiting the number processed. Decorated with @mcp.tool() to register it.
    @mcp.tool()
    def gc(
        dry_run: bool = True,
        archive_instead: bool = False,
        limit: int | None = None,
    ) -> dict[str, Any]:
        """
        Perform garbage collection on low-scoring memories.
    
        Removes or archives memories whose decay score has fallen below the
        forget threshold. This prevents the database from growing indefinitely
        with unused memories.
    
        Args:
            dry_run: Preview what would be removed without actually removing.
            archive_instead: Archive memories instead of deleting.
            limit: Maximum number of memories to process (1-10,000).
    
        Returns:
            Statistics about removed/archived memories.
    
        Raises:
            ValueError: If limit is out of valid range.
        """
        # Input validation
        if limit is not None:
            limit = validate_positive_int(limit, "limit", min_value=1, max_value=10000)
    
        config = get_config()
        now = int(time.time())
    
        memories = db.list_memories(status=MemoryStatus.ACTIVE)
    
        to_remove = []
        total_score_removed = 0.0
        for memory in memories:
            should_delete, score = should_forget(memory, now)
            if should_delete:
                to_remove.append((memory, score))
                total_score_removed += score
    
        to_remove.sort(key=lambda x: x[1])
    
        if limit and len(to_remove) > limit:
            to_remove = to_remove[:limit]
            total_score_removed = sum(score for _, score in to_remove)
    
        removed_count = 0
        archived_count = 0
        memory_ids = []
    
        if not dry_run:
            for memory, _score in to_remove:
                memory_ids.append(memory.id)
                if archive_instead:
                    db.update_memory(memory_id=memory.id, status=MemoryStatus.ARCHIVED)
                    archived_count += 1
                else:
                    db.delete_memory(memory.id)
                    removed_count += 1
        else:
            memory_ids = [memory.id for memory, _ in to_remove]
            if archive_instead:
                archived_count = len(to_remove)
            else:
                removed_count = len(to_remove)
    
        result = GarbageCollectionResult(
            removed_count=removed_count,
            archived_count=archived_count,
            freed_score_sum=total_score_removed,
            memory_ids=memory_ids,
        )
    
        return {
            "success": True,
            "dry_run": dry_run,
            "removed_count": result.removed_count,
            "archived_count": result.archived_count,
            "freed_score_sum": round(result.freed_score_sum, 4),
            "memory_ids": result.memory_ids[:10],
            "total_affected": len(result.memory_ids),
            "message": (
                f"{'Would remove' if dry_run else 'Removed'} {len(result.memory_ids)} "
                f"low-scoring memories (threshold: {config.forget_threshold})"
            ),
        }
  • Import statement in the MCP server entry point that imports the 'gc' tool (along with others), triggering its registration via the @mcp.tool() decorator when the server initializes.
    from .tools import (
        analyze_for_recall,
        analyze_message,
        auto_recall_tool,
        cluster,
        consolidate,
        create_relation,
        gc,
        open_memories,
        performance,
        promote,
        read_graph,
        save,
        search,
        search_unified,
        touch,
    )
  • The tools/__init__.py exposes the 'gc' tool via import, facilitating its use and registration when importing from the tools package.
    from . import (
        analyze_for_recall,
        analyze_message,
        auto_recall_tool,
        backfill_embeddings,
        cluster,
        consolidate,
        create_relation,
        gc,
        open_memories,
        promote,
        read_graph,
        save,
        search,
        search_unified,
        touch,
    )
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 of behavioral disclosure. It explains that the tool 'Removes or archives memories' based on decay scores, which clarifies it's a destructive operation (though with safe options like dry_run and archive_instead). However, it doesn't mention potential side effects, rate limits, or authentication requirements, 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 well-structured and appropriately sized. It starts with the core purpose, explains the rationale, lists parameters with clear explanations, and states the return value. Every sentence earns its place with no wasted words, and information is front-loaded effectively.

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

Completeness4/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 operation with 3 parameters) and the presence of an output schema (which covers return values), the description is mostly complete. It explains the tool's purpose, parameters, and behavior adequately. The main gap is lack of explicit warnings about destructive nature or prerequisites, though the dry_run parameter provides some safety context.

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

Parameters5/5

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

The description adds significant semantic value beyond the input schema, which has 0% description coverage. It explains each parameter's purpose: 'dry_run: Preview what would be removed without actually removing,' 'archive_instead: Archive memories instead of deleting,' and 'limit: Maximum number of memories to process.' This fully compensates for the schema's lack of descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/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: 'Perform garbage collection on low-scoring memories' with specific verb ('Perform garbage collection') and resource ('low-scoring memories'). It distinguishes from siblings like 'cluster_memories' or 'consolidate_memories' by focusing on removal/archiving based on decay scores.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool: when memories have 'fallen below the forget threshold' to 'prevent the database from growing indefinitely with unused memories.' However, it doesn't explicitly state when NOT to use it or mention alternatives among siblings, though the purpose implies it's for cleanup rather than other memory operations.

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/prefrontal-systems/mnemex'

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