Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
chore: add new primitive types and replace id_prefixes everywhere (#5749)
Kian Jones3f78c93be59d
diff --git a/letta/schemas/agent_file.py b/letta/schemas/agent_file.pyindex 5d90250b4..ccbdd7f9b 100644--- a/letta/schemas/agent_file.py+++ b/letta/schemas/agent_file.py@@ -7,7 +7,7 @@ from pydantic import BaseModel, Fieldfrom letta.helpers.datetime_helpers import get_utc_timefrom letta.schemas.agent import AgentState, CreateAgentfrom letta.schemas.block import Block, CreateBlock-from letta.schemas.enums import MessageRole+from letta.schemas.enums import MessageRole, PrimitiveTypefrom letta.schemas.file import FileAgent, FileAgentBase, FileMetadata, FileMetadataBasefrom letta.schemas.group import Group, GroupCreatefrom letta.schemas.letta_message import ApprovalReturn@@ -42,7 +42,7 @@ class ImportResult:class MessageSchema(MessageCreate):"""Message with human-readable ID for agent file"""- __id_prefix__ = "message"+ __id_prefix__ = PrimitiveType.MESSAGE.valueid: str = Field(..., description="Human-readable identifier for this message in the file")# Override the role field to accept all message roles, not just user/system/assistant@@ -96,7 +96,7 @@ class MessageSchema(MessageCreate):class FileAgentSchema(FileAgentBase):"""File-Agent relationship with human-readable ID for agent file"""- __id_prefix__ = "file_agent"+ __id_prefix__ = PrimitiveType.FILE_AGENT.valueid: str = Field(..., description="Human-readable identifier for this file-agent relationship in the file")@classmethod@@ -120,7 +120,7 @@ class FileAgentSchema(FileAgentBase):class AgentSchema(CreateAgent):"""Agent with human-readable ID for agent file"""- __id_prefix__ = "agent"+ __id_prefix__ = PrimitiveType.AGENT.valueid: str = Field(..., description="Human-readable identifier for this agent in the file")in_context_message_ids: List[str] = Field(default_factory=list, description="List of message IDs that are currently in the agent's context"@@ -198,7 +198,7 @@ class AgentSchema(CreateAgent):class GroupSchema(GroupCreate):"""Group with human-readable ID for agent file"""- __id_prefix__ = "group"+ __id_prefix__ = PrimitiveType.GROUP.valueid: str = Field(..., description="Human-readable identifier for this group in the file")@classmethod@@ -220,7 +220,7 @@ class GroupSchema(GroupCreate):class BlockSchema(CreateBlock):"""Block with human-readable ID for agent file"""- __id_prefix__ = "block"+ __id_prefix__ = PrimitiveType.BLOCK.valueid: str = Field(..., description="Human-readable identifier for this block in the file")@classmethod@@ -246,7 +246,7 @@ class BlockSchema(CreateBlock):class FileSchema(FileMetadataBase):"""File with human-readable ID for agent file"""- __id_prefix__ = "file"+ __id_prefix__ = PrimitiveType.FILE.valueid: str = Field(..., description="Human-readable identifier for this file in the file")@classmethod@@ -276,7 +276,7 @@ class FileSchema(FileMetadataBase):class SourceSchema(SourceCreate):"""Source with human-readable ID for agent file"""- __id_prefix__ = "source"+ __id_prefix__ = PrimitiveType.SOURCE.valueid: str = Field(..., description="Human-readable identifier for this source in the file")@classmethod@@ -299,7 +299,7 @@ class SourceSchema(SourceCreate):class ToolSchema(Tool):"""Tool with human-readable ID for agent file"""- __id_prefix__ = "tool"+ __id_prefix__ = PrimitiveType.TOOL.valueid: str = Field(..., description="Human-readable identifier for this tool in the file")@classmethod@@ -311,7 +311,7 @@ class ToolSchema(Tool):class MCPServerSchema(BaseModel):"""MCP server schema for agent files with remapped ID."""- __id_prefix__ = "mcp_server"+ __id_prefix__ = PrimitiveType.MCP_SERVER.valueid: str = Field(..., description="Human-readable MCP server ID")server_type: strdiff --git a/letta/schemas/enums.py b/letta/schemas/enums.pyindex 2ac0db12b..6cb3ba2ff 100644--- a/letta/schemas/enums.py+++ b/letta/schemas/enums.py@@ -26,6 +26,27 @@ class PrimitiveType(str, Enum):STEP = "step"IDENTITY = "identity"+ # Infrastructure types+ MCP_SERVER = "mcp_server"+ MCP_OAUTH = "mcp-oauth"+ FILE_AGENT = "file_agent"++ # Configuration types+ SANDBOX_ENV = "sandbox-env"+ AGENT_ENV = "agent-env"++ # Core entity types+ USER = "user"+ ORGANIZATION = "org"+ TOOL_RULE = "tool_rule"++ # Batch processing types+ BATCH_ITEM = "batch_item"+ BATCH_REQUEST = "batch_req"++ # Telemetry types+ PROVIDER_TRACE = "provider_trace"+class ProviderType(str, Enum):anthropic = "anthropic"diff --git a/letta/schemas/environment_variables.py b/letta/schemas/environment_variables.pyindex 0a0e53c7a..9485bcb95 100644--- a/letta/schemas/environment_variables.py+++ b/letta/schemas/environment_variables.py@@ -2,6 +2,7 @@ from typing import Optionalfrom pydantic import Field+from letta.schemas.enums import PrimitiveTypefrom letta.schemas.letta_base import LettaBase, OrmMetadataBasefrom letta.schemas.secret import Secretfrom letta.settings import settings@@ -52,7 +53,7 @@ class EnvironmentVariableUpdateBase(LettaBase):# Environment Variableclass SandboxEnvironmentVariableBase(EnvironmentVariableBase):- __id_prefix__ = "sandbox-env"+ __id_prefix__ = PrimitiveType.SANDBOX_ENV.valuesandbox_config_id: str = Field(..., description="The ID of the sandbox config this environment variable belongs to.")@@ -70,7 +71,7 @@ class SandboxEnvironmentVariableUpdate(EnvironmentVariableUpdateBase):# Agent-Specific Environment Variableclass AgentEnvironmentVariableBase(EnvironmentVariableBase):- __id_prefix__ = "agent-env"+ __id_prefix__ = PrimitiveType.AGENT_ENV.valueagent_id: str = Field(..., description="The ID of the agent this environment variable belongs to.")diff --git a/letta/schemas/llm_batch_job.py b/letta/schemas/llm_batch_job.pyindex e07e148ec..a69ee3902 100644--- a/letta/schemas/llm_batch_job.py+++ b/letta/schemas/llm_batch_job.py@@ -5,7 +5,7 @@ from anthropic.types.beta.messages import BetaMessageBatch, BetaMessageBatchIndifrom pydantic import BaseModel, Fieldfrom letta.helpers import ToolRulesSolver-from letta.schemas.enums import AgentStepStatus, JobStatus, ProviderType+from letta.schemas.enums import AgentStepStatus, JobStatus, PrimitiveType, ProviderTypefrom letta.schemas.letta_base import OrmMetadataBasefrom letta.schemas.llm_config import LLMConfig@@ -16,7 +16,7 @@ class AgentStepState(BaseModel):class LLMBatchItemBase(OrmMetadataBase, validate_assignment=True):- __id_prefix__ = "batch_item"+ __id_prefix__ = PrimitiveType.BATCH_ITEM.valueclass LLMBatchItem(LLMBatchItemBase, validate_assignment=True):@@ -47,7 +47,7 @@ class LLMBatchJob(OrmMetadataBase, validate_assignment=True):Each job corresponds to one API call that sends multiple messages to the LLM provider, and aggregates responses across all agent submissions."""- __id_prefix__ = "batch_req"+ __id_prefix__ = PrimitiveType.BATCH_REQUEST.valueid: Optional[str] = Field(None, description="The id of the batch job. Assigned by the database.")status: JobStatus = Field(..., description="The current status of the batch (e.g., created, in_progress, done).")diff --git a/letta/schemas/mcp.py b/letta/schemas/mcp.pyindex 92996344b..d40f9865b 100644--- a/letta/schemas/mcp.py+++ b/letta/schemas/mcp.py@@ -13,13 +13,14 @@ from letta.functions.mcp_client.types import (StreamableHTTPServerConfig,)from letta.orm.mcp_oauth import OAuthSessionStatus+from letta.schemas.enums import PrimitiveTypefrom letta.schemas.letta_base import LettaBasefrom letta.schemas.secret import Secretfrom letta.settings import settingsclass BaseMCPServer(LettaBase):- __id_prefix__ = "mcp_server"+ __id_prefix__ = PrimitiveType.MCP_SERVER.valueclass MCPServer(BaseMCPServer):@@ -178,7 +179,7 @@ UpdateMCPServer = Union[UpdateSSEMCPServer, UpdateStdioMCPServer, UpdateStreamab# OAuth-related schemasclass BaseMCPOAuth(LettaBase):- __id_prefix__ = "mcp-oauth"+ __id_prefix__ = PrimitiveType.MCP_OAUTH.valueclass MCPOAuthSession(BaseMCPOAuth):diff --git a/letta/schemas/mcp_server.py b/letta/schemas/mcp_server.pyindex 5b495c5af..d0364a5f9 100644--- a/letta/schemas/mcp_server.py+++ b/letta/schemas/mcp_server.py@@ -13,12 +13,13 @@ from letta.functions.mcp_client.types import (StreamableHTTPServerConfig,)from letta.orm.mcp_oauth import OAuthSessionStatus+from letta.schemas.enums import PrimitiveTypefrom letta.schemas.letta_base import LettaBasefrom letta.schemas.secret import Secretclass BaseMCPServer(LettaBase):- __id_prefix__ = "mcp_server"+ __id_prefix__ = PrimitiveType.MCP_SERVER.value# Create Schemas (for POST requests)@@ -101,7 +102,7 @@ UpdateMCPServerUnion = Union[UpdateStdioMCPServer, UpdateSSEMCPServer, UpdateStr# OAuth-related schemasclass BaseMCPOAuth(LettaBase):- __id_prefix__ = "mcp-oauth"+ __id_prefix__ = PrimitiveType.MCP_OAUTH.valueclass MCPOAuthSession(BaseMCPOAuth):diff --git a/letta/schemas/organization.py b/letta/schemas/organization.pyindex 9af86a143..e3d0f7c53 100644--- a/letta/schemas/organization.py+++ b/letta/schemas/organization.py@@ -4,12 +4,13 @@ from typing import Optionalfrom pydantic import Fieldfrom letta.helpers.datetime_helpers import get_utc_time+from letta.schemas.enums import PrimitiveTypefrom letta.schemas.letta_base import LettaBasefrom letta.utils import create_random_usernameclass OrganizationBase(LettaBase):- __id_prefix__ = "org"+ __id_prefix__ = PrimitiveType.ORGANIZATION.valueclass Organization(OrganizationBase):diff --git a/letta/schemas/passage.py b/letta/schemas/passage.pyindex fdaac2f2a..5396fbf36 100644--- a/letta/schemas/passage.py+++ b/letta/schemas/passage.py@@ -6,11 +6,12 @@ from pydantic import Field, field_validatorfrom letta.constants import MAX_EMBEDDING_DIMfrom letta.helpers.datetime_helpers import get_utc_timefrom letta.schemas.embedding_config import EmbeddingConfig+from letta.schemas.enums import PrimitiveTypefrom letta.schemas.letta_base import OrmMetadataBaseclass PassageBase(OrmMetadataBase):- __id_prefix__ = "passage"+ __id_prefix__ = PrimitiveType.PASSAGE.valueis_deleted: bool = Field(False, description="Whether this passage is deleted or not.")diff --git a/letta/schemas/provider_trace.py b/letta/schemas/provider_trace.pyindex 382f4b8f0..0e75d6253 100644--- a/letta/schemas/provider_trace.py+++ b/letta/schemas/provider_trace.py@@ -6,11 +6,12 @@ from typing import Any, Dict, Optionalfrom pydantic import BaseModel, Fieldfrom letta.helpers.datetime_helpers import get_utc_time+from letta.schemas.enums import PrimitiveTypefrom letta.schemas.letta_base import OrmMetadataBaseclass BaseProviderTrace(OrmMetadataBase):- __id_prefix__ = "provider_trace"+ __id_prefix__ = PrimitiveType.PROVIDER_TRACE.valueclass ProviderTraceCreate(BaseModel):diff --git a/letta/schemas/run_metrics.py b/letta/schemas/run_metrics.pyindex 458a1cad7..e7d21f2a4 100644--- a/letta/schemas/run_metrics.py+++ b/letta/schemas/run_metrics.py@@ -2,11 +2,12 @@ from typing import List, Optionalfrom pydantic import Field+from letta.schemas.enums import PrimitiveTypefrom letta.schemas.letta_base import LettaBaseclass RunMetricsBase(LettaBase):- __id_prefix__ = "run"+ __id_prefix__ = PrimitiveType.RUN.valueclass RunMetrics(RunMetricsBase):diff --git a/letta/schemas/step_metrics.py b/letta/schemas/step_metrics.pyindex fb791fc0b..321bd1784 100644--- a/letta/schemas/step_metrics.py+++ b/letta/schemas/step_metrics.py@@ -2,11 +2,12 @@ from typing import Optionalfrom pydantic import Field+from letta.schemas.enums import PrimitiveTypefrom letta.schemas.letta_base import LettaBaseclass StepMetricsBase(LettaBase):- __id_prefix__ = "step"+ __id_prefix__ = PrimitiveType.STEP.valueclass StepMetrics(StepMetricsBase):diff --git a/letta/schemas/tool_rule.py b/letta/schemas/tool_rule.pyindex e633749c9..feba39e8e 100644--- a/letta/schemas/tool_rule.py+++ b/letta/schemas/tool_rule.py@@ -4,14 +4,14 @@ from typing import Annotated, Any, Dict, List, Literal, Optional, Set, Unionfrom pydantic import BaseModel, Field, field_validator, model_validator-from letta.schemas.enums import ToolRuleType+from letta.schemas.enums import PrimitiveType, ToolRuleTypefrom letta.schemas.letta_base import LettaBaselogger = logging.getLogger(__name__)class BaseToolRule(LettaBase):- __id_prefix__ = "tool_rule"+ __id_prefix__ = PrimitiveType.TOOL_RULE.valuetool_name: str = Field(..., description="The name of the tool. Must exist in the database for the user's organization.")type: ToolRuleType = Field(..., description="The type of the message.")prompt_template: Optional[str] = Field(diff --git a/letta/schemas/user.py b/letta/schemas/user.pyindex 1b92058e0..1a657af46 100644--- a/letta/schemas/user.py+++ b/letta/schemas/user.py@@ -4,11 +4,12 @@ from typing import Optionalfrom pydantic import Fieldfrom letta.constants import DEFAULT_ORG_ID+from letta.schemas.enums import PrimitiveTypefrom letta.schemas.letta_base import LettaBaseclass UserBase(LettaBase):- __id_prefix__ = "user"+ __id_prefix__ = PrimitiveType.USER.valueclass User(UserBase):diff --git a/letta/validators.py b/letta/validators.pyindex 42726f5b7..ed738ebaa 100644--- a/letta/validators.py+++ b/letta/validators.py@@ -63,6 +63,27 @@ SandboxConfigId = Annotated[str, PATH_VALIDATORS[PrimitiveType.SANDBOX_CONFIG.vaStepId = Annotated[str, PATH_VALIDATORS[PrimitiveType.STEP.value]()]IdentityId = Annotated[str, PATH_VALIDATORS[PrimitiveType.IDENTITY.value]()]+# Infrastructure types+McpServerId = Annotated[str, PATH_VALIDATORS[PrimitiveType.MCP_SERVER.value]()]+McpOAuthId = Annotated[str, PATH_VALIDATORS[PrimitiveType.MCP_OAUTH.value]()]+FileAgentId = Annotated[str, PATH_VALIDATORS[PrimitiveType.FILE_AGENT.value]()]++# Configuration types+SandboxEnvId = Annotated[str, PATH_VALIDATORS[PrimitiveType.SANDBOX_ENV.value]()]+AgentEnvId = Annotated[str, PATH_VALIDATORS[PrimitiveType.AGENT_ENV.value]()]++# Core entity types+UserId = Annotated[str, PATH_VALIDATORS[PrimitiveType.USER.value]()]+OrganizationId = Annotated[str, PATH_VALIDATORS[PrimitiveType.ORGANIZATION.value]()]+ToolRuleId = Annotated[str, PATH_VALIDATORS[PrimitiveType.TOOL_RULE.value]()]++# Batch processing types+BatchItemId = Annotated[str, PATH_VALIDATORS[PrimitiveType.BATCH_ITEM.value]()]+BatchRequestId = Annotated[str, PATH_VALIDATORS[PrimitiveType.BATCH_REQUEST.value]()]++# Telemetry types+ProviderTraceId = Annotated[str, PATH_VALIDATORS[PrimitiveType.PROVIDER_TRACE.value]()]+def raise_on_invalid_id(param_name: str, expected_prefix: PrimitiveType):"""