Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: add validation for per_file_view_window_char_limit to prevent int32 overflow (#8937)
github-actions[bot]81398118dd68
diff --git a/letta/constants.py b/letta/constants.pyindex a6b53c6da..81f77df6a 100644--- a/letta/constants.py+++ b/letta/constants.py@@ -461,6 +461,10 @@ CONVERSATION_LOCK_TTL_SECONDS = 300 # 5 minutes# File based controlsDEFAULT_MAX_FILES_OPEN = 5DEFAULT_CORE_MEMORY_SOURCE_CHAR_LIMIT: int = 50000+# Max values for file controls (int32 limit to match database INTEGER type)+MAX_INT32: int = 2147483647+MAX_PER_FILE_VIEW_WINDOW_CHAR_LIMIT: int = MAX_INT32+MAX_FILES_OPEN_LIMIT: int = 1000 # Practical limit - no agent needs 1000+ files openGET_PROVIDERS_TIMEOUT_SECONDS = 10diff --git a/letta/schemas/agent.py b/letta/schemas/agent.pyindex 64cb313b8..0e40f1fe1 100644--- a/letta/schemas/agent.py+++ b/letta/schemas/agent.py@@ -4,7 +4,12 @@ from typing import Dict, List, Literal, Optionalfrom pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator-from letta.constants import CORE_MEMORY_LINE_NUMBER_WARNING, DEFAULT_EMBEDDING_CHUNK_SIZE+from letta.constants import (+ CORE_MEMORY_LINE_NUMBER_WARNING,+ DEFAULT_EMBEDDING_CHUNK_SIZE,+ MAX_FILES_OPEN_LIMIT,+ MAX_PER_FILE_VIEW_WINDOW_CHAR_LIMIT,+)from letta.errors import AgentExportProcessingError, LettaInvalidArgumentErrorfrom letta.schemas.block import Block, CreateBlockfrom letta.schemas.embedding_config import EmbeddingConfig@@ -394,6 +399,28 @@ class CreateAgent(BaseModel, validate_assignment=True): #return embedding+ @field_validator("max_files_open")+ @classmethod+ def validate_max_files_open(cls, value: Optional[int]) -> Optional[int]:+ """Validate max_files_open is within acceptable range."""+ if value is not None and value > MAX_FILES_OPEN_LIMIT:+ raise LettaInvalidArgumentError(+ f"max_files_open cannot exceed {MAX_FILES_OPEN_LIMIT}. Got: {value}",+ argument_name="max_files_open",+ )+ return value++ @field_validator("per_file_view_window_char_limit")+ @classmethod+ def validate_per_file_view_window_char_limit(cls, value: Optional[int]) -> Optional[int]:+ """Validate per_file_view_window_char_limit is within int32 range for database compatibility."""+ if value is not None and value > MAX_PER_FILE_VIEW_WINDOW_CHAR_LIMIT:+ raise LettaInvalidArgumentError(+ f"per_file_view_window_char_limit cannot exceed {MAX_PER_FILE_VIEW_WINDOW_CHAR_LIMIT}. Got: {value}",+ argument_name="per_file_view_window_char_limit",+ )+ return value+@model_validator(mode="after")def validate_sleeptime_for_agent_type(self) -> "CreateAgent":"""Validate that enable_sleeptime is True when agent_type is a specific value"""@@ -497,6 +524,28 @@ class UpdateAgent(BaseModel):model_config = ConfigDict(extra="ignore") # Ignores extra fields+ @field_validator("max_files_open")+ @classmethod+ def validate_max_files_open(cls, value: Optional[int]) -> Optional[int]:+ """Validate max_files_open is within acceptable range."""+ if value is not None and value > MAX_FILES_OPEN_LIMIT:+ raise LettaInvalidArgumentError(+ f"max_files_open cannot exceed {MAX_FILES_OPEN_LIMIT}. Got: {value}",+ argument_name="max_files_open",+ )+ return value++ @field_validator("per_file_view_window_char_limit")+ @classmethod+ def validate_per_file_view_window_char_limit(cls, value: Optional[int]) -> Optional[int]:+ """Validate per_file_view_window_char_limit is within int32 range for database compatibility."""+ if value is not None and value > MAX_PER_FILE_VIEW_WINDOW_CHAR_LIMIT:+ raise LettaInvalidArgumentError(+ f"per_file_view_window_char_limit cannot exceed {MAX_PER_FILE_VIEW_WINDOW_CHAR_LIMIT}. Got: {value}",+ argument_name="per_file_view_window_char_limit",+ )+ return value+class AgentStepResponse(BaseModel):messages: List[Message] = Field(..., description="The messages generated during the agent's step.")