Skip to main content
Glama

Edit Memory

edit_memory
Destructive

Replace content in memory files using literal strings or regex patterns to update stored information.

Instructions

Replaces content matching a regular expression in a memory.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
memory_file_nameYesThe name of the memory.
needleYesThe string or regex pattern to search for. If `mode` is "literal", this string will be matched exactly. If `mode` is "regex", this string will be treated as a regular expression (syntax of Python's `re` module, with flags DOTALL and MULTILINE enabled).
replYesThe replacement string (verbatim).
modeYesEither "literal" or "regex", specifying how the `needle` parameter is to be interpreted.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The EditMemoryTool class provides the core handler logic for the 'edit_memory' tool. It replaces content in a project memory file using literal string or regex replacement by delegating to ReplaceContentTool.
    class EditMemoryTool(Tool, ToolMarkerCanEdit):
        def apply(
            self,
            memory_file_name: str,
            needle: str,
            repl: str,
            mode: Literal["literal", "regex"],
        ) -> str:
            r"""
            Replaces content matching a regular expression in a memory.
    
            :param memory_file_name: the name of the memory
            :param needle: the string or regex pattern to search for.
                If `mode` is "literal", this string will be matched exactly.
                If `mode` is "regex", this string will be treated as a regular expression (syntax of Python's `re` module,
                with flags DOTALL and MULTILINE enabled).
            :param repl: the replacement string (verbatim).
            :param mode: either "literal" or "regex", specifying how the `needle` parameter is to be interpreted.
            """
            replace_content_tool = self.agent.get_tool(ReplaceContentTool)
            rel_path = self.memories_manager.get_memory_file_path(memory_file_name).relative_to(self.get_project_root())
            return replace_content_tool.replace_content(str(rel_path), needle, repl, mode=mode, require_not_ignored=False)
  • ToolRegistry discovers all Tool subclasses (including EditMemoryTool) via iter_subclasses and registers them by their snake_case name (EditMemoryTool -> 'edit_memory'). This makes the tool available to the agent.
    self._tool_dict: dict[str, RegisteredTool] = {}
    for cls in iter_subclasses(Tool):
        if not any(cls.__module__.startswith(pkg) for pkg in tool_packages):
            continue
        is_optional = issubclass(cls, ToolMarkerOptional)
        name = cls.get_name_from_cls()
        if name in self._tool_dict:
            raise ValueError(f"Duplicate tool name found: {name}. Tool classes must have unique names.")
        self._tool_dict[name] = RegisteredTool(tool_class=cls, is_optional=is_optional, tool_name=name)
  • Defines the tool naming convention used by Tool subclasses and registry: converts 'EditMemoryTool' to 'edit_memory', which is the MCP-exposed name.
    def get_name_from_cls(cls) -> str:
        name = cls.__name__
        if name.endswith("Tool"):
            name = name[:-4]
        # convert to snake_case
        name = "".join(["_" + c.lower() if c.isupper() else c for c in name]).lstrip("_")
        return name
    
    def get_name(self) -> str:
        return self.get_name_from_cls()
Behavior3/5

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

Annotations already declare readOnlyHint=false and destructiveHint=true, indicating this is a mutation tool with destructive potential. The description adds useful context about regex matching behavior (Python re module with DOTALL/MULTILINE flags) and the replacement being verbatim, which goes beyond annotations. However, it doesn't mention error conditions, side effects, or what happens when no match is found.

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 functionality ('Replaces content matching a regular expression in a memory'). Every word earns its place with no redundancy or unnecessary elaboration.

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 (regex editing with destructive potential), the description provides adequate context when combined with rich annotations and a complete input schema. However, it could benefit from mentioning the existence of an output schema (which handles return values) and providing more behavioral context about edge cases. The combination of description, annotations, and schema is mostly complete.

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?

With 100% schema description coverage, all parameters are well-documented in the schema itself. The description doesn't add significant semantic information beyond what's already in the parameter descriptions, which thoroughly explain memory_file_name, needle (with mode-specific behavior), repl, and mode. The baseline of 3 is appropriate when the schema does the heavy lifting.

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 specific action ('Replaces content') on a specific resource ('in a memory') using a specific method ('matching a regular expression'). It distinguishes from siblings like 'replace_content' (general file replacement) and 'write_memory' (full overwrite) by specifying regex-based partial editing of memory files.

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 implies usage for regex-based editing of memory content, but doesn't explicitly state when to use this vs alternatives like 'replace_content' for non-memory files or 'write_memory' for complete overwrites. It provides clear context about the operation type but lacks explicit exclusion guidance.

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/oraios/serena'

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