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.

feat: add new blocks field to agent model and deprecate memory field [LET-4424] (#5613)

cthomasbeaeddf54d8f
diff --git a/fern/openapi.json b/fern/openapi.json
index 5781b1918..91ec4d5d1 100644
--- a/fern/openapi.json
+++ b/fern/openapi.json
@@ -16629,6 +16629,410 @@
},
"required": ["blocks"]
},
+ "blocks": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "value": {
+ "type": "string"
+ },
+ "limit": {
+ "oneOf": [
+ {
+ "type": "number"
+ },
+ {}
+ ]
+ },
+ "project_id": {
+ "oneOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ },
+ {
+ "type": "array",
+ "items": {
+ "oneOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ }
+ ],
+ "nullable": true
+ }
+ },
+ {}
+ ],
+ "nullable": true
+ },
+ "name": {
+ "oneOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ },
+ {
+ "type": "array",
+ "items": {
+ "oneOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ }
+ ],
+ "nullable": true
+ }
+ },
+ {}
+ ],
+ "nullable": true
+ },
+ "is_template": {
+ "oneOf": [
+ {
+ "type": "boolean"
+ },
+ {}
+ ]
+ },
+ "base_template_id": {
+ "oneOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ },
+ {
+ "type": "array",
+ "items": {
+ "oneOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ }
+ ],
+ "nullable": true
+ }
+ },
+ {}
+ ],
+ "nullable": true
+ },
+ "deployment_id": {
+ "oneOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ },
+ {
+ "type": "array",
+ "items": {
+ "oneOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ }
+ ],
+ "nullable": true
+ }
+ },
+ {}
+ ],
+ "nullable": true
+ },
+ "entity_id": {
+ "oneOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ },
+ {
+ "type": "array",
+ "items": {
+ "oneOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ }
+ ],
+ "nullable": true
+ }
+ },
+ {}
+ ],
+ "nullable": true
+ },
+ "preserve_on_migration": {
+ "oneOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ },
+ {
+ "type": "array",
+ "items": {
+ "oneOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ }
+ ],
+ "nullable": true
+ }
+ },
+ {}
+ ],
+ "nullable": true
+ },
+ "label": {
+ "oneOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ },
+ {
+ "type": "array",
+ "items": {
+ "oneOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ }
+ ],
+ "nullable": true
+ }
+ },
+ {}
+ ],
+ "nullable": true
+ },
+ "read_only": {
+ "oneOf": [
+ {
+ "type": "boolean"
+ },
+ {}
+ ]
+ },
+ "description": {
+ "oneOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ },
+ {
+ "type": "array",
+ "items": {
+ "oneOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ }
+ ],
+ "nullable": true
+ }
+ },
+ {}
+ ],
+ "nullable": true
+ },
+ "metadata": {
+ "oneOf": [
+ {
+ "nullable": true
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ },
+ {
+ "type": "array",
+ "items": {
+ "oneOf": [
+ {
+ "nullable": true
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ }
+ ],
+ "nullable": true
+ }
+ },
+ {}
+ ],
+ "nullable": true
+ },
+ "hidden": {
+ "oneOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ },
+ {
+ "type": "array",
+ "items": {
+ "oneOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ }
+ ],
+ "nullable": true
+ }
+ },
+ {}
+ ],
+ "nullable": true
+ },
+ "id": {
+ "oneOf": [
+ {
+ "type": "string"
+ },
+ {}
+ ]
+ },
+ "created_by_id": {
+ "oneOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ },
+ {
+ "type": "array",
+ "items": {
+ "oneOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ }
+ ],
+ "nullable": true
+ }
+ },
+ {}
+ ],
+ "nullable": true
+ },
+ "last_updated_by_id": {
+ "oneOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ },
+ {
+ "type": "array",
+ "items": {
+ "oneOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "string",
+ "format": "null",
+ "nullable": true
+ }
+ ],
+ "nullable": true
+ }
+ },
+ {}
+ ],
+ "nullable": true
+ }
+ },
+ "required": ["value"]
+ }
+ },
"tools": {
"type": "array",
"items": {
@@ -19485,6 +19889,7 @@
"llm_config",
"embedding_config",
"memory",
+ "blocks",
"tools",
"sources",
"tags"
@@ -22737,7 +23142,16 @@
},
"memory": {
"$ref": "#/components/schemas/Memory",
- "description": "The in-context memory of the agent."
+ "description": "The in-context memory of the agent.",
+ "deprecated": true
+ },
+ "blocks": {
+ "items": {
+ "$ref": "#/components/schemas/Block"
+ },
+ "type": "array",
+ "title": "Blocks",
+ "description": "The memory blocks used by the agent."
},
"tools": {
"items": {
@@ -22962,6 +23376,7 @@
"llm_config",
"embedding_config",
"memory",
+ "blocks",
"tools",
"sources",
"tags"
diff --git a/letta/orm/agent.py b/letta/orm/agent.py
index 782066ab7..8b4499aea 100644
--- a/letta/orm/agent.py
+++ b/letta/orm/agent.py
@@ -241,6 +241,7 @@ class Agent(SqlalchemyBase, OrganizationMixin, ProjectMixin, TemplateEntityMixin
"tools": [],
"sources": [],
"memory": Memory(blocks=[]),
+ "blocks": [],
"identity_ids": [],
"multi_agent_group": None,
"tool_exec_environment_variables": [],
@@ -262,6 +263,7 @@ class Agent(SqlalchemyBase, OrganizationMixin, ProjectMixin, TemplateEntityMixin
],
agent_type=self.agent_type,
),
+ "blocks": lambda: [b.to_pydantic() for b in self.core_memory],
"identity_ids": lambda: [i.id for i in self.identities],
"multi_agent_group": lambda: self.multi_agent_group,
"tool_exec_environment_variables": lambda: self.tool_exec_environment_variables,
@@ -334,6 +336,7 @@ class Agent(SqlalchemyBase, OrganizationMixin, ProjectMixin, TemplateEntityMixin
"tools": [],
"sources": [],
"memory": Memory(blocks=[]),
+ "blocks": [],
"identity_ids": [],
"multi_agent_group": None,
"tool_exec_environment_variables": [],
@@ -379,6 +382,7 @@ class Agent(SqlalchemyBase, OrganizationMixin, ProjectMixin, TemplateEntityMixin
],
agent_type=self.agent_type,
)
+ state["blocks"] = [m.to_pydantic() for m in memory]
state["identity_ids"] = [i.id for i in identities]
state["multi_agent_group"] = multi_agent_group
state["tool_exec_environment_variables"] = tool_exec_environment_variables
diff --git a/letta/schemas/agent.py b/letta/schemas/agent.py
index 04a1e0134..3662ecf66 100644
--- a/letta/schemas/agent.py
+++ b/letta/schemas/agent.py
@@ -6,7 +6,7 @@ from pydantic import BaseModel, ConfigDict, Field, field_validator, model_valida
from letta.constants import CORE_MEMORY_LINE_NUMBER_WARNING, DEFAULT_EMBEDDING_CHUNK_SIZE
from letta.errors import AgentExportProcessingError
-from letta.schemas.block import CreateBlock
+from letta.schemas.block import Block, CreateBlock
from letta.schemas.embedding_config import EmbeddingConfig
from letta.schemas.environment_variables import AgentEnvironmentVariable
from letta.schemas.file import FileStatus
@@ -85,7 +85,8 @@ class AgentState(OrmMetadataBase, validate_assignment=True):
description: Optional[str] = Field(None, description="The description of the agent.")
metadata: Optional[Dict] = Field(None, description="The metadata of the agent.")
- memory: Memory = Field(..., description="The in-context memory of the agent.")
+ memory: Memory = Field(..., description="The in-context memory of the agent.", deprecated=True)
+ blocks: List[Block] = Field(..., description="The memory blocks used by the agent.")
tools: List[Tool] = Field(..., description="The tools used by the agent.")
sources: List[Source] = Field(..., description="The sources used by the agent.")
tags: List[str] = Field(..., description="The tags associated with the agent.")