Skip to main content
Glama

Write Memory

write_memory
Destructive

Store project information in markdown format for future reference. Create meaningful memory files to retain useful data across tasks.

Instructions

Write some information (utf-8-encoded) about this project that can be useful for future tasks to a memory in md format. The memory name should be meaningful.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
memory_file_nameYes
contentYes
max_answer_charsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The WriteMemoryTool class provides the core handler logic for the 'write_memory' tool. Its 'apply' method validates input length and saves the content to a project-specific memory file using the agent's memories_manager.
    class WriteMemoryTool(Tool, ToolMarkerCanEdit):
        """
        Writes a named memory (for future reference) to Serena's project-specific memory store.
        """
    
        def apply(self, memory_file_name: str, content: str, max_answer_chars: int = -1) -> str:
            """
            Write some information (utf-8-encoded) about this project that can be useful for future tasks to a memory in md format.
            The memory name should be meaningful.
            """
            # NOTE: utf-8 encoding is configured in the MemoriesManager
            if max_answer_chars == -1:
                max_answer_chars = self.agent.serena_config.default_max_tool_answer_chars
            if len(content) > max_answer_chars:
                raise ValueError(
                    f"Content for {memory_file_name} is too long. Max length is {max_answer_chars} characters. "
                    + "Please make the content shorter."
                )
    
            return self.memories_manager.save_memory(memory_file_name, content)
  • ToolRegistry automatically discovers and registers all subclasses of Tool (including WriteMemoryTool) from the 'serena.tools' package, mapping them to tool names like 'write_memory'.
    class ToolRegistry:
        def __init__(self) -> None:
            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)
  • The get_name_from_cls method in the Tool base class derives the tool name 'write_memory' from the class name 'WriteMemoryTool' by removing 'Tool' suffix and converting to snake_case.
    @classmethod
    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
  • Import of memory_tools.py in tools/__init__.py ensures WriteMemoryTool is discoverable by ToolRegistry via module scanning.
    from .memory_tools import *
  • The 'apply' method signature and docstring define the input schema (parameters: memory_file_name:str, content:str, max_answer_chars:int=-1) and output (str) for the write_memory tool, used for validation and MCP tool description.
    def apply(self, memory_file_name: str, content: str, max_answer_chars: int = -1) -> str:
        """
        Write some information (utf-8-encoded) about this project that can be useful for future tasks to a memory in md format.
        The memory name should be meaningful.
        """
        # NOTE: utf-8 encoding is configured in the MemoriesManager
        if max_answer_chars == -1:
            max_answer_chars = self.agent.serena_config.default_max_tool_answer_chars
        if len(content) > max_answer_chars:
            raise ValueError(
                f"Content for {memory_file_name} is too long. Max length is {max_answer_chars} characters. "
                + "Please make the content shorter."
            )
    
        return self.memories_manager.save_memory(memory_file_name, content)
Behavior4/5

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

Annotations indicate destructiveHint=true and readOnlyHint=false, which the description aligns with by implying a write operation. The description adds valuable context beyond annotations: it specifies the memory is stored in markdown format and should have a meaningful name, which helps the agent understand behavioral expectations. No contradiction with annotations.

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 two concise sentences that front-load the core purpose and key requirements. Every word adds value: the first sentence covers action, content, format, and purpose; the second emphasizes naming quality. No wasted words or redundancy.

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 a destructive tool with 3 parameters (0% schema coverage) and an output schema, the description adequately covers the purpose and format but lacks parameter details and behavioral nuances like error handling or idempotency. The output schema may help with return values, but the description doesn't fully compensate for the low parameter coverage.

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. It mentions 'memory name should be meaningful' (hinting at memory_file_name) and 'information... to a memory' (hinting at content), but doesn't explain max_answer_chars or provide details on parameter formats, constraints, or interactions. This leaves significant gaps in parameter understanding.

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 ('Write some information') and resource ('to a memory'), specifying the format ('md format') and encoding ('utf-8-encoded'). It distinguishes from siblings like 'read_memory' and 'edit_memory' by focusing on creation, but doesn't explicitly differentiate from 'create_text_file' which might have overlapping functionality.

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 context ('about this project', 'useful for future tasks'), suggesting when to use it for project documentation. However, it lacks explicit guidance on when to choose this over alternatives like 'create_text_file' or 'edit_memory', and doesn't 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/oraios/serena'

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