read_memory
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
| Name | Required | Description | Default |
|---|---|---|---|
| memory_file_name | Yes | ||
| max_answer_chars | No |
Implementation Reference
- src/serena/tools/memory_tools.py:28-41 (handler)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)
- src/serena/tools/tools_base.py:359-367 (registration)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)
- src/serena/tools/tools_base.py:119-129 (registration)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()
- src/serena/tools/__init__.py:5-5 (helper)Import of memory_tools makes ReadMemoryTool available for subclass scanning by ToolRegistry.from .memory_tools import *