{"record":{"id":"979ff9e0c895681f","repo":"oraios/serena","slug":"content-for-memory-name-is-too-long-max-length","errorCode":null,"errorMessage":"Content for {memory_name} is too long. Max length is {max_chars} characters. Please make the content shorter.","messagePattern":"Content for (.+?) is too long\\. Max length is (.+?) characters\\. Please make the content shorter\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/serena/tools/memory_tools.py","lineNumber":31,"sourceCode":"    \"\"\"\n\n    def apply(self, memory_name: str, content: str, max_chars: int = -1) -> str:\n        \"\"\"\n        Write information about this project that can be useful for future tasks in md format.\n        The name should be meaningful and can include \"/\" to organize into topics.\n        If explicitly instructed, use the \"global/\" prefix for writing a memory that is shared across projects.\n        References to other memories should be inside backticks and prefixed with mem:,\n        e.g., `mem:auth`.\n\n        :param memory_name: memory name\n        :param content: memory content, utf8-encoded\n        :param max_chars: see other tools\n        \"\"\"\n        # NOTE: utf-8 encoding is configured in the MemoriesManager\n        if max_chars == -1:\n            max_chars = self.agent.serena_config.default_max_tool_answer_chars\n        if len(content) > max_chars:\n            raise ValueError(\n                f\"Content for {memory_name} is too long. Max length is {max_chars} characters. \" + \"Please make the content shorter.\"\n            )\n\n        return self.memory_manager.save_memory(memory_name, content, is_tool_context=True)\n\n\nclass ReadMemoryTool(Tool):\n    \"\"\"\n    Reads the content of a memory file.\n    \"\"\"\n\n    def apply(self, memory_name: str) -> str:\n        \"\"\"\n        Use to read a memory that is likely to be relevant to the current task, inferring relevance e.g. from the name.\n        \"\"\"\n        return self.memory_manager.load_memory(memory_name)\n\n","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/oraios/serena/blob/7fcbca7e62555ec2287ddb2f083caee805848ea6/src/serena/tools/memory_tools.py#L13-L49","documentation":"The create_memory tool enforces a maximum character length on memory content before persisting it via MemoriesManager. If the content exceeds max_chars (or the configured default_max_tool_answer_chars when max_chars=-1), it refuses to save and asks for shorter content.","triggerScenarios":"Calling the memory-creation tool with content whose len(content) exceeds max_chars; passing max_chars=-1 while the content is longer than serena_config.default_max_tool_answer_chars.","commonSituations":"An agent tries to save a whole file dump or a long analysis as a memory; default answer-length limit is low and the caller never raised it; content grew after a refactor and silently crossed the cap.","solutions":["Shorten/summarize the content below max_chars before saving","Split the content into multiple smaller memories","Pass a larger explicit max_chars value in the tool call","Raise serena_config.default_max_tool_answer_chars if -1 default is the binding limit"],"exampleFix":"// before\ncreate_memory.apply(memory_name='notes', content=whole_file_text)  # 200k chars\n// ValueError: Content too long...\n\n// after\nsummary = summarize(whole_file_text)[:max_chars]\ncreate_memory.apply(memory_name='notes', content=summary)\n# or\ncreate_memory.apply(memory_name='notes', content=whole_file_text, max_chars=500000)","handlingStrategy":"validation","validationCode":"MAX = max_chars if max_chars != -1 else agent.serena_config.default_max_tool_answer_chars\nif len(content) > MAX:\n    content = content[:MAX]  # or split/summarize\nmemory_tool.apply(memory_name=name, content=content)","typeGuard":null,"tryCatchPattern":"try:\n    memory_tool.apply(memory_name=name, content=content)\nexcept ValueError as e:\n    if 'too long' in str(e):\n        memory_tool.apply(memory_name=name, content=summarize(content))\n    else:\n        raise","preventionTips":["Pre-truncate or summarize long content before saving memories","Split large content into multiple memories","Raise default_max_tool_answer_chars if you routinely store long notes"],"tags":["python","validation","memory","limit-exceeded"],"backgroundTag":"payload-too-large","analyzedSha":"7fcbca7e62555ec2287ddb2f083caee805848ea6","analyzedAt":"2026-08-29T00:04:09.619Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}