Skip to main content
Glama

Read Memory

read_memory
Read-only

Retrieve stored information from memory files to support current tasks. Access relevant data by analyzing file names and reading content once per conversation.

Instructions

Read the content of a memory file. This tool should only be used if the information is relevant to the current task. You can infer whether the information is relevant from the memory file name. You should not read the same memory file multiple times in the same conversation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
memory_file_nameYes
max_answer_charsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The ReadMemoryTool class implements the 'read_memory' tool. Its apply method is the handler that loads the specified memory using the project's memories_manager and returns its content.
    class ReadMemoryTool(Tool):
        """
        Reads the memory with the given name from Serena's project-specific memory store.
        """
    
        def apply(self, memory_file_name: str, max_answer_chars: int = -1) -> str:
            """
            Read the content of a memory file. This tool should only be used if the information
            is relevant to the current task. You can infer whether the information
            is relevant from the memory file name.
            You should not read the same memory file multiple times in the same conversation.
            """
            return self.memories_manager.load_memory(memory_file_name)
  • Input schema defined by type hints on the apply method: memory_file_name (str, required), max_answer_chars (int, optional default -1). Output: str (memory content). Used by MCP for validation.
    def apply(self, memory_file_name: str, max_answer_chars: int = -1) -> str:
        """
        Read the content of a memory file. This tool should only be used if the information
        is relevant to the current task. You can infer whether the information
        is relevant from the memory file name.
        You should not read the same memory file multiple times in the same conversation.
        """
        return self.memories_manager.load_memory(memory_file_name)
  • ToolRegistry discovers ReadMemoryTool via subclass scanning of Tool in serena.tools packages and registers it with name 'read_memory' derived from class name.
    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 derives the MCP tool name 'read_memory' from the ReadMemoryTool class 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()
  • Import of memory_tools makes ReadMemoryTool available for subclass scanning by ToolRegistry.
    from .memory_tools import *
Behavior3/5

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

Annotations already declare readOnlyHint=true and destructiveHint=false, indicating this is a safe read operation. The description adds valuable behavioral context beyond annotations: it specifies relevance criteria (based on file name) and a usage constraint (no repeated reads in same conversation). However, it doesn't disclose other potential behaviors like error handling, response format, or performance characteristics.

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 efficiently structured in three sentences: the first states the core purpose, the second provides usage criteria, and the third adds a behavioral constraint. Every sentence adds value without redundancy, and it's front-loaded with the essential action. No wasted words 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 moderate complexity (a read operation with relevance filtering), annotations cover safety (read-only, non-destructive), and an output schema exists (so return values needn't be described), the description is reasonably complete. It adds useful context like relevance criteria and usage limits, though it lacks parameter explanations and doesn't fully address sibling tool differentiation.

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?

Schema description coverage is 0%, so the schema provides no parameter documentation. The description doesn't explain either parameter's semantics—it mentions 'memory file name' but doesn't clarify its format or source, and omits 'max_answer_chars' entirely. Since parameters are few (2) and one has a default, the baseline is 3, but the description fails to compensate for the coverage gap.

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 verb ('Read') and resource ('content of a memory file'), making the purpose unambiguous. It distinguishes this tool from siblings like 'list_memories' (which lists files) and 'write_memory' (which writes content). However, it doesn't explicitly contrast with 'read_file' (which reads general files), leaving some sibling differentiation incomplete.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use this tool ('if the information is relevant to the current task') and when not to use it ('should not read the same memory file multiple times in the same conversation'). It also implies alternatives by referencing the memory file name for relevance inference, though it doesn't name specific sibling tools like 'list_memories' for discovery.

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