oraios/serena · error · ValueError
Content for {memory_name} is too long. Max length is {max_ch
Error message
Content for {memory_name} is too long. Max length is {max_chars} characters. Please make the content shorter. What it means
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.
Source
Thrown at src/serena/tools/memory_tools.py:31
"""
def apply(self, memory_name: str, content: str, max_chars: int = -1) -> str:
"""
Write information about this project that can be useful for future tasks in md format.
The name should be meaningful and can include "/" to organize into topics.
If explicitly instructed, use the "global/" prefix for writing a memory that is shared across projects.
References to other memories should be inside backticks and prefixed with mem:,
e.g., `mem:auth`.
:param memory_name: memory name
:param content: memory content, utf8-encoded
:param max_chars: see other tools
"""
# NOTE: utf-8 encoding is configured in the MemoriesManager
if max_chars == -1:
max_chars = self.agent.serena_config.default_max_tool_answer_chars
if len(content) > max_chars:
raise ValueError(
f"Content for {memory_name} is too long. Max length is {max_chars} characters. " + "Please make the content shorter."
)
return self.memory_manager.save_memory(memory_name, content, is_tool_context=True)
class ReadMemoryTool(Tool):
"""
Reads the content of a memory file.
"""
def apply(self, memory_name: str) -> str:
"""
Use to read a memory that is likely to be relevant to the current task, inferring relevance e.g. from the name.
"""
return self.memory_manager.load_memory(memory_name)
View on GitHub (pinned to 7fcbca7e62)
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
Example fix
// before create_memory.apply(memory_name='notes', content=whole_file_text) # 200k chars // ValueError: Content too long... // after summary = summarize(whole_file_text)[:max_chars] create_memory.apply(memory_name='notes', content=summary) # or create_memory.apply(memory_name='notes', content=whole_file_text, max_chars=500000)
Defensive patterns
Strategy: validation
Validate before calling
MAX = max_chars if max_chars != -1 else agent.serena_config.default_max_tool_answer_chars
if len(content) > MAX:
content = content[:MAX] # or split/summarize
memory_tool.apply(memory_name=name, content=content) Try / catch
try:
memory_tool.apply(memory_name=name, content=content)
except ValueError as e:
if 'too long' in str(e):
memory_tool.apply(memory_name=name, content=summarize(content))
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Bare "{self.GLOBAL_TOPIC}" is not a valid memory name. Use "
- Must be positive or the default (-1), got: {max_answer_chars
- Cannot use both fixed_tools and excluded_tools/included_opti
- Unknown language backend '{backend_str}': valid values are {
- Invalid line_ending: {value!r}. Valid values are: {valid}
AI-assisted analysis of oraios/serena@7fcbca7e62 (2026-08-29).
Data as JSON: /api/errors/979ff9e0c895681f.
Report an issue: GitHub.