Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

fix: boost default char limit to 5k for core memory blocks (#2089)

Charles Packer44df28417f44
diff --git a/letta/constants.py b/letta/constants.py
index 0cafeb14b..c16e24156 100644
--- a/letta/constants.py
+++ b/letta/constants.py
@@ -128,8 +128,9 @@ MESSAGE_SUMMARY_REQUEST_ACK = "Understood, I will respond with a summary of the
MESSAGE_SUMMARY_TRUNC_KEEP_N_LAST = 3
# Default memory limits
-CORE_MEMORY_PERSONA_CHAR_LIMIT = 2000
-CORE_MEMORY_HUMAN_CHAR_LIMIT = 2000
+CORE_MEMORY_PERSONA_CHAR_LIMIT: int = 5000
+CORE_MEMORY_HUMAN_CHAR_LIMIT: int = 5000
+CORE_MEMORY_BLOCK_CHAR_LIMIT: int = 5000
# Function return limits
FUNCTION_RETURN_CHAR_LIMIT = 6000 # ~300 words
@@ -149,9 +150,5 @@ FUNC_FAILED_HEARTBEAT_MESSAGE = f"{NON_USER_MSG_PREFIX}Function call failed, ret
RETRIEVAL_QUERY_DEFAULT_PAGE_SIZE = 5
-# TODO Is this config or constant?
-CORE_MEMORY_PERSONA_CHAR_LIMIT: int = 2000
-CORE_MEMORY_HUMAN_CHAR_LIMIT: int = 2000
-
MAX_FILENAME_LENGTH = 255
RESERVED_FILENAMES = {"CON", "PRN", "AUX", "NUL", "COM1", "COM2", "LPT1", "LPT2"}
diff --git a/letta/orm/block.py b/letta/orm/block.py
index f91b4ba78..dddb5631c 100644
--- a/letta/orm/block.py
+++ b/letta/orm/block.py
@@ -3,6 +3,7 @@ from typing import TYPE_CHECKING, Optional, Type
from sqlalchemy import JSON, BigInteger, Integer
from sqlalchemy.orm import Mapped, mapped_column, relationship
+from letta.constants import CORE_MEMORY_BLOCK_CHAR_LIMIT
from letta.orm.mixins import OrganizationMixin
from letta.orm.sqlalchemy_base import SqlalchemyBase
from letta.schemas.block import Block as PydanticBlock
@@ -27,7 +28,7 @@ class Block(OrganizationMixin, SqlalchemyBase):
doc="whether the block is a template (e.g. saved human/persona options as baselines for other templates)", default=False
)
value: Mapped[str] = mapped_column(doc="Text content of the block for the respective section of core memory.")
- limit: Mapped[BigInteger] = mapped_column(Integer, default=2000, doc="Character limit of the block.")
+ limit: Mapped[BigInteger] = mapped_column(Integer, default=CORE_MEMORY_BLOCK_CHAR_LIMIT, doc="Character limit of the block.")
metadata_: Mapped[Optional[dict]] = mapped_column(JSON, default={}, doc="arbitrary information related to the block.")
# relationships
diff --git a/letta/schemas/memory.py b/letta/schemas/memory.py
index 183380556..f38a18fac 100644
--- a/letta/schemas/memory.py
+++ b/letta/schemas/memory.py
@@ -7,6 +7,7 @@ from pydantic import BaseModel, Field
if TYPE_CHECKING:
pass
+from letta.constants import CORE_MEMORY_BLOCK_CHAR_LIMIT
from letta.schemas.block import Block
from letta.schemas.message import Message
from letta.schemas.openai.chat_completion_request import Tool
@@ -270,7 +271,7 @@ class ChatMemory(BasicBlockMemory):
ChatMemory initializes a BaseChatMemory with two default blocks, `human` and `persona`.
"""
- def __init__(self, persona: str, human: str, limit: int = 2000):
+ def __init__(self, persona: str, human: str, limit: int = CORE_MEMORY_BLOCK_CHAR_LIMIT):
"""
Initialize the ChatMemory object with a persona and human string.
diff --git a/tests/test_memory.py b/tests/test_memory.py
index d8f2cc796..ba00c9833 100644
--- a/tests/test_memory.py
+++ b/tests/test_memory.py
@@ -37,10 +37,10 @@ def test_load_memory_from_json(sample_memory: Memory):
def test_memory_limit_validation(sample_memory: Memory):
"""Test exceeding memory limit"""
with pytest.raises(ValueError):
- ChatMemory(persona="x" * 3000, human="y" * 3000)
+ ChatMemory(persona="x " * 10000, human="y " * 10000)
with pytest.raises(ValueError):
- sample_memory.get_block("persona").value = "x" * 3000
+ sample_memory.get_block("persona").value = "x " * 10000
def test_memory_jinja2_template_load(sample_memory: Memory):