Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
chore: bug fixes (#2391)
Charles Packeraab8e171d00d
diff --git a/letta/agent.py b/letta/agent.pyindex ebcc118c9..4fa9f761e 100644--- a/letta/agent.py+++ b/letta/agent.py@@ -466,7 +466,10 @@ class Agent(BaseAgent):if isinstance(heartbeat_request, str) and heartbeat_request.lower().strip() == "true":heartbeat_request = True- if not isinstance(heartbeat_request, bool) or heartbeat_request is None:+ if heartbeat_request is None:+ heartbeat_request = False++ if not isinstance(heartbeat_request, bool):self.logger.warning(f"{CLI_WARNING_PREFIX}'request_heartbeat' arg parsed was not a bool or None, type={type(heartbeat_request)}, value={heartbeat_request}")diff --git a/letta/cli/cli_config.py b/letta/cli/cli_config.pyindex 87e43567c..12c039485 100644--- a/letta/cli/cli_config.py+++ b/letta/cli/cli_config.py@@ -135,7 +135,7 @@ def add_tool(func = eval(func_def.name)# 4. Add or update the tool- tool = client.create_or_update_tool(func=func, name=name, tags=tags, update=update)+ tool = client.create_or_update_tool(func=func, tags=tags, update=update)print(f"Tool {tool.name} added successfully")diff --git a/letta/client/client.py b/letta/client/client.pyindex 000c0a74d..38c5143f4 100644--- a/letta/client/client.py+++ b/letta/client/client.py@@ -185,20 +185,15 @@ class AbstractClient(object):def load_composio_tool(self, action: "ActionType") -> Tool:raise NotImplementedError- def create_tool(- self, func, name: Optional[str] = None, tags: Optional[List[str]] = None, return_char_limit: int = FUNCTION_RETURN_CHAR_LIMIT- ) -> Tool:+ def create_tool(self, func, tags: Optional[List[str]] = None, return_char_limit: int = FUNCTION_RETURN_CHAR_LIMIT) -> Tool:raise NotImplementedError- def create_or_update_tool(- self, func, name: Optional[str] = None, tags: Optional[List[str]] = None, return_char_limit: int = FUNCTION_RETURN_CHAR_LIMIT- ) -> Tool:+ def create_or_update_tool(self, func, tags: Optional[List[str]] = None, return_char_limit: int = FUNCTION_RETURN_CHAR_LIMIT) -> Tool:raise NotImplementedErrordef update_tool(self,id: str,- name: Optional[str] = None,description: Optional[str] = None,func: Optional[Callable] = None,tags: Optional[List[str]] = None,@@ -1546,7 +1541,6 @@ class RESTClient(AbstractClient):def create_tool(self,func: Callable,- name: Optional[str] = None,tags: Optional[List[str]] = None,return_char_limit: int = FUNCTION_RETURN_CHAR_LIMIT,) -> Tool:@@ -1566,7 +1560,7 @@ class RESTClient(AbstractClient):source_type = "python"# call server function- request = ToolCreate(source_type=source_type, source_code=source_code, name=name, return_char_limit=return_char_limit)+ request = ToolCreate(source_type=source_type, source_code=source_code, return_char_limit=return_char_limit)if tags:request.tags = tagsresponse = requests.post(f"{self.base_url}/{self.api_prefix}/tools", json=request.model_dump(), headers=self.headers)@@ -1577,7 +1571,6 @@ class RESTClient(AbstractClient):def create_or_update_tool(self,func: Callable,- name: Optional[str] = None,tags: Optional[List[str]] = None,return_char_limit: int = FUNCTION_RETURN_CHAR_LIMIT,) -> Tool:@@ -1597,7 +1590,7 @@ class RESTClient(AbstractClient):source_type = "python"# call server function- request = ToolCreate(source_type=source_type, source_code=source_code, name=name, return_char_limit=return_char_limit)+ request = ToolCreate(source_type=source_type, source_code=source_code, return_char_limit=return_char_limit)if tags:request.tags = tagsresponse = requests.put(f"{self.base_url}/{self.api_prefix}/tools", json=request.model_dump(), headers=self.headers)@@ -1608,7 +1601,6 @@ class RESTClient(AbstractClient):def update_tool(self,id: str,- name: Optional[str] = None,description: Optional[str] = None,func: Optional[Callable] = None,tags: Optional[List[str]] = None,@@ -1639,7 +1631,6 @@ class RESTClient(AbstractClient):source_type=source_type,source_code=source_code,tags=tags,- name=name,return_char_limit=return_char_limit,)response = requests.patch(f"{self.base_url}/{self.api_prefix}/tools/{id}", json=request.model_dump(), headers=self.headers)@@ -2976,7 +2967,6 @@ class LocalClient(AbstractClient):def create_tool(self,func,- name: Optional[str] = None,tags: Optional[List[str]] = None,description: Optional[str] = None,return_char_limit: int = FUNCTION_RETURN_CHAR_LIMIT,@@ -3018,7 +3008,6 @@ class LocalClient(AbstractClient):def create_or_update_tool(self,func,- name: Optional[str] = None,tags: Optional[List[str]] = None,description: Optional[str] = None,return_char_limit: int = FUNCTION_RETURN_CHAR_LIMIT,@@ -3028,7 +3017,6 @@ class LocalClient(AbstractClient):Args:func (callable): The function to create a tool for.- name: (str): Name of the tool (must be unique per-user.)tags (Optional[List[str]], optional): Tags for the tool. Defaults to None.description (str, optional): The description.return_char_limit (int): The character limit for the tool's return value. Defaults to FUNCTION_RETURN_CHAR_LIMIT.@@ -3046,7 +3034,6 @@ class LocalClient(AbstractClient):Tool(source_type=source_type,source_code=source_code,- name=name,tags=tags,description=description,return_char_limit=return_char_limit,@@ -3057,7 +3044,6 @@ class LocalClient(AbstractClient):def update_tool(self,id: str,- name: Optional[str] = None,description: Optional[str] = None,func: Optional[Callable] = None,tags: Optional[List[str]] = None,@@ -3068,7 +3054,6 @@ class LocalClient(AbstractClient):Args:id (str): ID of the tool- name (str): Name of the toolfunc (callable): Function to wrap in a tooltags (List[str]): Tags for the toolreturn_char_limit (int): The character limit for the tool's return value. Defaults to FUNCTION_RETURN_CHAR_LIMIT.@@ -3080,7 +3065,6 @@ class LocalClient(AbstractClient):"source_type": "python", # Always include source_type"source_code": parse_source_code(func) if func else None,"tags": tags,- "name": name,"description": description,"return_char_limit": return_char_limit,}diff --git a/letta/functions/schema_generator.py b/letta/functions/schema_generator.pyindex 7c2764ae1..3b1560e8c 100644--- a/letta/functions/schema_generator.py+++ b/letta/functions/schema_generator.py@@ -437,6 +437,7 @@ def generate_tool_schema_for_composio(name: str,description: str,append_heartbeat: bool = True,+ strict: bool = False,) -> Dict[str, Any]:properties_json = {}required_fields = parameters_model.required or []@@ -473,14 +474,26 @@ def generate_tool_schema_for_composio(required_fields.append("request_heartbeat")# Return the final schema- return {- "name": name,- "description": description,- "strict": True,- "parameters": {- "type": "object",- "properties": properties_json,- "additionalProperties": False,- "required": required_fields,- },- }+ if strict:+ # https://platform.openai.com/docs/guides/function-calling#strict-mode+ return {+ "name": name,+ "description": description,+ "strict": True, # NOTE+ "parameters": {+ "type": "object",+ "properties": properties_json,+ "additionalProperties": False, # NOTE+ "required": required_fields,+ },+ }+ else:+ return {+ "name": name,+ "description": description,+ "parameters": {+ "type": "object",+ "properties": properties_json,+ "required": required_fields,+ },+ }diff --git a/letta/llm_api/openai.py b/letta/llm_api/openai.pyindex ee084947e..ee4e79542 100644--- a/letta/llm_api/openai.py+++ b/letta/llm_api/openai.py@@ -30,7 +30,7 @@ OPENAI_SSE_DONE = "[DONE]"def openai_get_model_list(- url: str, api_key: Union[str, None], fix_url: Optional[bool] = False, extra_params: Optional[dict] = None+ url: str, api_key: Optional[str] = None, fix_url: Optional[bool] = False, extra_params: Optional[dict] = None) -> dict:"""https://platform.openai.com/docs/api-reference/models/list"""from letta.utils import printddiff --git a/letta/schemas/providers.py b/letta/schemas/providers.pyindex b3e40a7d7..8d38ad4c3 100644--- a/letta/schemas/providers.py+++ b/letta/schemas/providers.py@@ -1,3 +1,4 @@+import warningsfrom datetime import datetimefrom typing import List, Optional@@ -210,6 +211,130 @@ class OpenAIProvider(Provider):return None+class LMStudioOpenAIProvider(OpenAIProvider):+ name: str = "lmstudio-openai"+ base_url: str = Field(..., description="Base URL for the LMStudio OpenAI API.")+ api_key: Optional[str] = Field(None, description="API key for the LMStudio API.")++ def list_llm_models(self) -> List[LLMConfig]:+ from letta.llm_api.openai import openai_get_model_list++ # For LMStudio, we want to hit 'GET /api/v0/models' instead of 'GET /v1/models'+ MODEL_ENDPOINT_URL = f"{self.base_url.strip('/v1')}/api/v0"+ response = openai_get_model_list(MODEL_ENDPOINT_URL)++ """+ Example response:++ {+ "object": "list",+ "data": [+ {+ "id": "qwen2-vl-7b-instruct",+ "object": "model",+ "type": "vlm",+ "publisher": "mlx-community",+ "arch": "qwen2_vl",+ "compatibility_type": "mlx",+ "quantization": "4bit",+ "state": "not-loaded",+ "max_context_length": 32768+ },+ ...+ """+ if "data" not in response:+ warnings.warn(f"LMStudio OpenAI model query response missing 'data' field: {response}")+ return []++ configs = []+ for model in response["data"]:+ assert "id" in model, f"Model missing 'id' field: {model}"+ model_name = model["id"]++ if "type" not in model:+ warnings.warn(f"LMStudio OpenAI model missing 'type' field: {model}")+ continue+ elif model["type"] not in ["vlm", "llm"]:+ continue++ if "max_context_length" in model:+ context_window_size = model["max_context_length"]+ else:+ warnings.warn(f"LMStudio OpenAI model missing 'max_context_length' field: {model}")+ continue++ configs.append(+ LLMConfig(+ model=model_name,+ model_endpoint_type="openai",+ model_endpoint=self.base_url,+ context_window=context_window_size,+ handle=self.get_handle(model_name),+ )+ )++ return configs++ def list_embedding_models(self) -> List[EmbeddingConfig]:+ from letta.llm_api.openai import openai_get_model_list++ # For LMStudio, we want to hit 'GET /api/v0/models' instead of 'GET /v1/models'+ MODEL_ENDPOINT_URL = f"{self.base_url}/api/v0"+ response = openai_get_model_list(MODEL_ENDPOINT_URL)++ """+ Example response:+ {+ "object": "list",+ "data": [+ {+ "id": "text-embedding-nomic-embed-text-v1.5",+ "object": "model",+ "type": "embeddings",+ "publisher": "nomic-ai",+ "arch": "nomic-bert",+ "compatibility_type": "gguf",+ "quantization": "Q4_0",+ "state": "not-loaded",+ "max_context_length": 2048+ }+ ...+ """+ if "data" not in response:+ warnings.warn(f"LMStudio OpenAI model query response missing 'data' field: {response}")+ return []++ configs = []+ for model in response["data"]:+ assert "id" in model, f"Model missing 'id' field: {model}"+ model_name = model["id"]++ if "type" not in model:+ warnings.warn(f"LMStudio OpenAI model missing 'type' field: {model}")+ continue+ elif model["type"] not in ["embeddings"]:+ continue++ if "max_context_length" in model:+ context_window_size = model["max_context_length"]+ else:+ warnings.warn(f"LMStudio OpenAI model missing 'max_context_length' field: {model}")+ continue++ configs.append(+ EmbeddingConfig(+ embedding_model=model_name,+ embedding_endpoint_type="openai",+ embedding_endpoint=self.base_url,+ embedding_dim=context_window_size,+ embedding_chunk_size=300,+ handle=self.get_handle(model_name),+ ),+ )++ return configs++class AnthropicProvider(Provider):name: str = "anthropic"api_key: str = Field(..., description="API key for the Anthropic API.")diff --git a/letta/schemas/tool.py b/letta/schemas/tool.pyindex 0296f0906..ab4736e60 100644--- a/letta/schemas/tool.py+++ b/letta/schemas/tool.py@@ -112,7 +112,6 @@ class Tool(BaseTool):class ToolCreate(LettaBase):- name: Optional[str] = Field(None, description="The name of the function (auto-generated from source_code if not provided).")description: Optional[str] = Field(None, description="The description of the tool.")tags: List[str] = Field([], description="Metadata tags.")source_code: str = Field(..., description="The source code of the function.")@@ -155,7 +154,6 @@ class ToolCreate(LettaBase):json_schema = generate_tool_schema_for_composio(composio_action_schema.parameters, name=wrapper_func_name, description=description)return cls(- name=wrapper_func_name,description=description,source_type=source_type,tags=tags,@@ -187,7 +185,6 @@ class ToolCreate(LettaBase):json_schema = generate_schema_from_args_schema_v2(langchain_tool.args_schema, name=wrapper_func_name, description=description)return cls(- name=wrapper_func_name,description=description,source_type=source_type,tags=tags,@@ -198,7 +195,6 @@ class ToolCreate(LettaBase):class ToolUpdate(LettaBase):description: Optional[str] = Field(None, description="The description of the tool.")- name: Optional[str] = Field(None, description="The name of the function.")tags: Optional[List[str]] = Field(None, description="Metadata tags.")source_code: Optional[str] = Field(None, description="The source code of the function.")source_type: Optional[str] = Field(None, description="The type of the source code.")diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.pyindex e34b5400b..50a9f1b3a 100644--- a/letta/server/rest_api/routers/v1/agents.py+++ b/letta/server/rest_api/routers/v1/agents.py@@ -408,6 +408,7 @@ AgentMessagesResponse = Annotated[def list_messages(agent_id: str,server: "SyncServer" = Depends(get_letta_server),+ after: Optional[str] = Query(None, description="Message after which to retrieve the returned messages."),before: Optional[str] = Query(None, description="Message before which to retrieve the returned messages."),limit: int = Query(10, description="Maximum number of messages to retrieve."),msg_object: bool = Query(False, description="If true, returns Message objects. If false, return LettaMessage objects."),@@ -430,6 +431,7 @@ def list_messages(return server.get_agent_recall(user_id=actor.id,agent_id=agent_id,+ after=after,before=before,limit=limit,reverse=True,diff --git a/letta/server/rest_api/routers/v1/tools.py b/letta/server/rest_api/routers/v1/tools.pyindex 14a9dc14b..73c0db0ce 100644--- a/letta/server/rest_api/routers/v1/tools.py+++ b/letta/server/rest_api/routers/v1/tools.py@@ -83,7 +83,7 @@ def create_tool(except UniqueConstraintViolationError as e:# Log or print the full exception here for debuggingprint(f"Error occurred: {e}")- clean_error_message = f"Tool with name {request.name} already exists."+ clean_error_message = f"Tool with this name already exists."raise HTTPException(status_code=409, detail=clean_error_message)except LettaToolCreateError as e:# HTTP 400 == Bad Requestdiff --git a/letta/server/server.py b/letta/server/server.pyindex 48e18d862..21143a034 100644--- a/letta/server/server.py+++ b/letta/server/server.py@@ -49,6 +49,7 @@ from letta.schemas.providers import (GoogleAIProvider,GroqProvider,LettaProvider,+ LMStudioOpenAIProvider,OllamaProvider,OpenAIProvider,Provider,@@ -186,8 +187,8 @@ def db_error_handler():exit(1)-print("Creating engine", settings.letta_pg_uri)if settings.letta_pg_uri_no_default:+ print("Creating postgres engine", settings.letta_pg_uri)config.recall_storage_type = "postgres"config.recall_storage_uri = settings.letta_pg_uri_no_defaultconfig.archival_storage_type = "postgres"@@ -204,7 +205,10 @@ if settings.letta_pg_uri_no_default:)else:# TODO: don't rely on config storage- engine = create_engine("sqlite:///" + os.path.join(config.recall_storage_path, "sqlite.db"))+ engine_path = "sqlite:///" + os.path.join(config.recall_storage_path, "sqlite.db")+ print("Creating sqlite engine", engine_path)++ engine = create_engine(engine_path)# Store the original connect methodoriginal_connect = engine.connect@@ -391,6 +395,13 @@ class SyncServer(Server):aws_region=model_settings.aws_region,))+ # Attempt to enable LM Studio by default+ if model_settings.lmstudio_base_url:+ self._enabled_providers.append(+ LMStudioOpenAIProvider(+ base_url=model_settings.lmstudio_base_url,+ )+ )def load_agent(self, agent_id: str, actor: User, interface: Union[AgentInterface, None] = None) -> Agent:"""Updated method to load agents from persisted storage"""diff --git a/letta/services/helpers/agent_manager_helper.py b/letta/services/helpers/agent_manager_helper.pyindex 7e4cd7c1b..95053cd67 100644--- a/letta/services/helpers/agent_manager_helper.py+++ b/letta/services/helpers/agent_manager_helper.py@@ -118,6 +118,27 @@ def compile_memory_metadata_block(return memory_metadata_block+class PreserveMapping(dict):+ """Used to preserve (do not modify) undefined variables in the system prompt"""++ def __missing__(self, key):+ return "{" + key + "}"+++def safe_format(template: str, variables: dict) -> str:+ """+ Safely formats a template string, preserving empty {} and {unknown_vars}+ while substituting known variables.++ If we simply use {} in format_map, it'll be treated as a positional field+ """+ # First escape any empty {} by doubling them+ escaped = template.replace("{}", "{{}}")++ # Now use format_map with our custom mapping+ return escaped.format_map(PreserveMapping(variables))++def compile_system_message(system_prompt: str,in_context_memory: Memory,@@ -169,7 +190,7 @@ def compile_system_message(# render the variables using the built-in templatertry:- formatted_prompt = system_prompt.format_map(variables)+ formatted_prompt = safe_format(system_prompt, variables)except Exception as e:raise ValueError(f"Failed to format system prompt - {str(e)}. System prompt value:\n{system_prompt}")diff --git a/letta/services/tool_manager.py b/letta/services/tool_manager.pyindex 5ea0b6b44..01e4c8557 100644--- a/letta/services/tool_manager.py+++ b/letta/services/tool_manager.py@@ -122,6 +122,7 @@ class ToolManager:new_schema = derive_openai_json_schema(source_code=pydantic_tool.source_code)tool.json_schema = new_schema+ tool.name = new_schema["name"]# Save the updated tool to the databasereturn tool.update(db_session=session, actor=actor).to_pydantic()diff --git a/letta/settings.py b/letta/settings.pyindex 1c5f5bfe6..4ef280213 100644--- a/letta/settings.py+++ b/letta/settings.py@@ -92,6 +92,9 @@ class ModelSettings(BaseSettings):# vLLMvllm_api_base: Optional[str] = None+ # lmstudio+ lmstudio_base_url: Optional[str] = None+# openllmopenllm_auth_type: Optional[str] = Noneopenllm_api_key: Optional[str] = Nonediff --git a/poetry.lock b/poetry.lockindex 7d3d164b3..d25f2ecb6 100644--- a/poetry.lock+++ b/poetry.lock@@ -1,4 +1,4 @@-# This file is automatically @generated by Poetry 1.8.5 and should not be changed by hand.+# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand.[[package]]name = "aiohappyeyeballs"@@ -859,7 +859,6 @@ files = [{file = "cryptography-44.0.0-cp37-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:761817a3377ef15ac23cd7834715081791d4ec77f9297ee694ca1ee9c2c7e5eb"},{file = "cryptography-44.0.0-cp37-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:3c672a53c0fb4725a29c303be906d3c1fa99c32f58abe008a82705f9ee96f40b"},{file = "cryptography-44.0.0-cp37-abi3-manylinux_2_34_aarch64.whl", hash = "sha256:4ac4c9f37eba52cb6fbeaf5b59c152ea976726b865bd4cf87883a7e7006cc543"},- {file = "cryptography-44.0.0-cp37-abi3-manylinux_2_34_x86_64.whl", hash = "sha256:60eb32934076fa07e4316b7b2742fa52cbb190b42c2df2863dbc4230a0a9b385"},{file = "cryptography-44.0.0-cp37-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:ed3534eb1090483c96178fcb0f8893719d96d5274dfde98aa6add34614e97c8e"},{file = "cryptography-44.0.0-cp37-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:f3f6fdfa89ee2d9d496e2c087cebef9d4fcbb0ad63c40e821b39f74bf48d9c5e"},{file = "cryptography-44.0.0-cp37-abi3-win32.whl", hash = "sha256:eb33480f1bad5b78233b0ad3e1b0be21e8ef1da745d8d2aecbb20671658b9053"},@@ -870,7 +869,6 @@ files = [{file = "cryptography-44.0.0-cp39-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:c5eb858beed7835e5ad1faba59e865109f3e52b3783b9ac21e7e47dc5554e289"},{file = "cryptography-44.0.0-cp39-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:f53c2c87e0fb4b0c00fa9571082a057e37690a8f12233306161c8f4b819960b7"},{file = "cryptography-44.0.0-cp39-abi3-manylinux_2_34_aarch64.whl", hash = "sha256:9e6fc8a08e116fb7c7dd1f040074c9d7b51d74a8ea40d4df2fc7aa08b76b9e6c"},- {file = "cryptography-44.0.0-cp39-abi3-manylinux_2_34_x86_64.whl", hash = "sha256:9abcc2e083cbe8dde89124a47e5e53ec38751f0d7dfd36801008f316a127d7ba"},{file = "cryptography-44.0.0-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:d2436114e46b36d00f8b72ff57e598978b37399d2786fd39793c36c6d5cb1c64"},{file = "cryptography-44.0.0-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:a01956ddfa0a6790d594f5b34fc1bfa6098aca434696a03cfdbe469b8ed79285"},{file = "cryptography-44.0.0-cp39-abi3-win32.whl", hash = "sha256:eca27345e1214d1b9f9490d200f9db5a874479be914199194e746c893788d417"},@@ -2537,13 +2535,13 @@ pytest = ["pytest (>=7.0.0)", "rich (>=13.9.4,<14.0.0)"][[package]]name = "letta-client"-version = "0.1.19"+version = "0.1.22"description = ""optional = falsepython-versions = "<4.0,>=3.8"files = [- {file = "letta_client-0.1.19-py3-none-any.whl", hash = "sha256:45cdfff85a19c7cab676f27a99fd268ec535d79adde0ea828dce9d305fac2e55"},- {file = "letta_client-0.1.19.tar.gz", hash = "sha256:053fda535063ede4a74c2eff2af635524a19e10f4fca48b2649e85e3a6d19393"},+ {file = "letta_client-0.1.22-py3-none-any.whl", hash = "sha256:6a108ac6d4cb1c79870a1defffcb6eb1ea6eca6da071f0b730f044a96d482c01"},+ {file = "letta_client-0.1.22.tar.gz", hash = "sha256:75483fc41fb3baf1170b11c44c25b45d62c439b8b9a9720601446a9b83ee636e"},][package.dependencies]diff --git a/pyproject.toml b/pyproject.tomlindex d4928e31e..54016df42 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -82,7 +82,6 @@ openai = "^1.60.0"colorama = "^0.4.6"-[tool.poetry.extras]postgres = ["pgvector", "pg8000", "psycopg2-binary", "psycopg2"]dev = ["pytest", "pytest-asyncio", "pexpect", "black", "pre-commit", "datasets", "pyright", "pytest-order", "autoflake", "isort", "locust"]diff --git a/tests/integration_test_agent_tool_graph.py b/tests/integration_test_agent_tool_graph.pyindex 61db6dfbd..3a24e29bd 100644--- a/tests/integration_test_agent_tool_graph.py+++ b/tests/integration_test_agent_tool_graph.py@@ -194,8 +194,8 @@ def test_check_tool_rules_with_different_models(mock_e2b_api_key_none):# Create two test toolst1_name = "first_secret_word"t2_name = "second_secret_word"- t1 = client.create_or_update_tool(first_secret_word, name=t1_name)- t2 = client.create_or_update_tool(second_secret_word, name=t2_name)+ t1 = client.create_or_update_tool(first_secret_word)+ t2 = client.create_or_update_tool(second_secret_word)tool_rules = [InitToolRule(tool_name=t1_name), InitToolRule(tool_name=t2_name)]tools = [t1, t2]@@ -217,7 +217,7 @@ def test_check_tool_rules_with_different_models(mock_e2b_api_key_none):# Create tool rule with single initial toolt3_name = "third_secret_word"- t3 = client.create_or_update_tool(third_secret_word, name=t3_name)+ t3 = client.create_or_update_tool(third_secret_word)tool_rules = [InitToolRule(tool_name=t3_name)]tools = [t3]for config_file in config_files:@@ -237,8 +237,8 @@ def test_claude_initial_tool_rule_enforced(mock_e2b_api_key_none):# Create tool rules that require tool_a to be called firstt1_name = "first_secret_word"t2_name = "second_secret_word"- t1 = client.create_or_update_tool(first_secret_word, name=t1_name)- t2 = client.create_or_update_tool(second_secret_word, name=t2_name)+ t1 = client.create_or_update_tool(first_secret_word)+ t2 = client.create_or_update_tool(second_secret_word)tool_rules = [InitToolRule(tool_name=t1_name),ChildToolRule(tool_name=t1_name, children=[t2_name]),@@ -366,8 +366,8 @@ def test_agent_conditional_tool_easy(mock_e2b_api_key_none):coin_flip_name = "flip_coin"secret_word_tool = "fourth_secret_word"- flip_coin_tool = client.create_or_update_tool(flip_coin, name=coin_flip_name)- reveal_secret = client.create_or_update_tool(fourth_secret_word, name=secret_word_tool)+ flip_coin_tool = client.create_or_update_tool(flip_coin)+ reveal_secret = client.create_or_update_tool(fourth_secret_word)# Make tool rulestool_rules = [@@ -435,9 +435,9 @@ def test_agent_conditional_tool_hard(mock_e2b_api_key_none):play_game = "can_play_game"coin_flip_name = "flip_coin_hard"final_tool = "fourth_secret_word"- play_game_tool = client.create_or_update_tool(can_play_game, name=play_game)- flip_coin_tool = client.create_or_update_tool(flip_coin_hard, name=coin_flip_name)- reveal_secret = client.create_or_update_tool(fourth_secret_word, name=final_tool)+ play_game_tool = client.create_or_update_tool(can_play_game)+ flip_coin_tool = client.create_or_update_tool(flip_coin_hard)+ reveal_secret = client.create_or_update_tool(fourth_secret_word)# Make tool rules - chain them together with conditional rulestool_rules = [@@ -507,8 +507,8 @@ def test_agent_conditional_tool_without_default_child(mock_e2b_api_key_none):# Create tools - we'll make several available to the agenttool_name = "return_none"- tool = client.create_or_update_tool(return_none, name=tool_name)- secret_word = client.create_or_update_tool(first_secret_word, name="first_secret_word")+ tool = client.create_or_update_tool(return_none)+ secret_word = client.create_or_update_tool(first_secret_word)# Make tool rules - only map one output, let others be free choicetool_rules = [@@ -568,8 +568,8 @@ def test_agent_reload_remembers_function_response(mock_e2b_api_key_none):# Create toolsflip_coin_name = "flip_coin"secret_word = "fourth_secret_word"- flip_coin_tool = client.create_or_update_tool(flip_coin, name=flip_coin_name)- secret_word_tool = client.create_or_update_tool(fourth_secret_word, name=secret_word)+ flip_coin_tool = client.create_or_update_tool(flip_coin)+ secret_word_tool = client.create_or_update_tool(fourth_secret_word)# Make tool rules - map coin flip to fourth_secret_wordtool_rules = [@@ -622,13 +622,12 @@ def test_simple_tool_rule(mock_e2b_api_key_none):# Create toolsflip_coin_name = "flip_coin"- another_secret_word = "first_secret_word"secret_word = "fourth_secret_word"random_tool = "can_play_game"- flip_coin_tool = client.create_or_update_tool(flip_coin, name=flip_coin_name)- secret_word_tool = client.create_or_update_tool(fourth_secret_word, name=secret_word)- another_secret_word_tool = client.create_or_update_tool(first_secret_word, name=another_secret_word)- random_tool = client.create_or_update_tool(can_play_game, name=random_tool)+ flip_coin_tool = client.create_or_update_tool(flip_coin)+ secret_word_tool = client.create_or_update_tool(fourth_secret_word)+ another_secret_word_tool = client.create_or_update_tool(first_secret_word)+ random_tool = client.create_or_update_tool(can_play_game)tools = [flip_coin_tool, secret_word_tool, another_secret_word_tool, random_tool]# Create tool rule: after flip_coin, must call fourth_secret_worddiff --git a/tests/test_client.py b/tests/test_client.pyindex 2294c62fd..721a293fb 100644--- a/tests/test_client.py+++ b/tests/test_client.py@@ -506,7 +506,7 @@ def test_attach_detach_agent_tool(client: Union[LocalClient, RESTClient], agent:"""return x * 2- tool = client.create_or_update_tool(func=example_tool, name="test_tool")+ tool = client.create_or_update_tool(func=example_tool)# Initially tool should not be attachedinitial_tools = client.list_attached_tools(agent_id=agent.id)@@ -688,8 +688,8 @@ def test_agent_creation(client: Union[LocalClient, RESTClient]):"""Another test tool."""return "Hello from another test tool!"- tool1 = client.create_or_update_tool(func=test_tool, name="test_tool", tags=["test"])- tool2 = client.create_or_update_tool(func=another_test_tool, name="another_test_tool", tags=["test"])+ tool1 = client.create_or_update_tool(func=test_tool, tags=["test"])+ tool2 = client.create_or_update_tool(func=another_test_tool, tags=["test"])# Create test blocksoffline_persona_block = client.create_block(label="persona", value="persona description", limit=5000)diff --git a/tests/test_local_client.py b/tests/test_local_client.pyindex f3d6945ef..7ea1c74d2 100644--- a/tests/test_local_client.py+++ b/tests/test_local_client.py@@ -311,7 +311,7 @@ def test_tools(client: LocalClient):assert client.get_tool(tool.id).tags == extras2# update tool: source code- client.update_tool(tool.id, name="print_tool2", func=print_tool2)+ client.update_tool(tool.id, func=print_tool2)assert client.get_tool(tool.id).name == "print_tool2"diff --git a/tests/test_managers.py b/tests/test_managers.pyindex c9ac4e0a9..d50808432 100644--- a/tests/test_managers.py+++ b/tests/test_managers.py@@ -1732,7 +1732,7 @@ def test_update_tool_source_code_refreshes_schema_only(server: SyncServer, printname = "counter_tool"# Create a ToolUpdate object to modify the tool's source_code- tool_update = ToolUpdate(name=name, source_code=source_code)+ tool_update = ToolUpdate(source_code=source_code)# Update the tool using the manager methodserver.tool_manager.update_tool_by_id(print_tool.id, tool_update, actor=default_user)diff --git a/tests/test_sdk_client.py b/tests/test_sdk_client.pyindex 536b250e5..917cdafd9 100644--- a/tests/test_sdk_client.py+++ b/tests/test_sdk_client.py@@ -10,7 +10,7 @@ from letta_client import CreateBlockfrom letta_client import Letta as LettaSDKClientfrom letta_client import MessageCreatefrom letta_client.core import ApiError-from letta_client.types import LettaMessageUnion_ToolCallMessage, LettaMessageUnion_ToolReturnMessage, LettaRequestConfig+from letta_client.types import AgentState, LettaRequestConfig, ToolCallMessage, ToolReturnMessage# ConstantsSERVER_PORT = 8283@@ -26,7 +26,7 @@ def run_server():@pytest.fixture(scope="module")-def client():+def client() -> LettaSDKClient:# Get URL from environment or start serverserver_url = os.getenv("LETTA_SERVER_URL", f"http://localhost:{SERVER_PORT}")if not os.getenv("LETTA_SERVER_URL"):@@ -40,7 +40,7 @@ def client():@pytest.fixture(scope="module")-def agent(client):+def agent(client: LettaSDKClient):agent_state = client.agents.create(memory_blocks=[CreateBlock(@@ -48,7 +48,7 @@ def agent(client):value="username: sarah",),],- llm="openai/gpt-4",+ model="openai/gpt-4",embedding="openai/text-embedding-ada-002",)yield agent_state@@ -57,7 +57,7 @@ def agent(client):client.agents.delete(agent_id=agent_state.id)-def test_shared_blocks(client):+def test_shared_blocks(client: LettaSDKClient):# create a blockblock = client.blocks.create(label="human",@@ -74,7 +74,7 @@ def test_shared_blocks(client):),],block_ids=[block.id],- llm="openai/gpt-4",+ model="openai/gpt-4",embedding="openai/text-embedding-ada-002",)agent_state2 = client.agents.create(@@ -86,12 +86,12 @@ def test_shared_blocks(client):),],block_ids=[block.id],- llm="openai/gpt-4",+ model="openai/gpt-4",embedding="openai/text-embedding-ada-002",)# update memory- client.agents.messages.send(+ client.agents.messages.create(agent_id=agent_state1.id,messages=[MessageCreate(@@ -102,9 +102,11 @@ def test_shared_blocks(client):)# check agent 2 memory- assert "charles" in client.blocks.get(block_id=block.id).value.lower(), f"Shared block update failed {client.get_block(block.id).value}"+ assert (+ "charles" in client.blocks.retrieve(block_id=block.id).value.lower()+ ), f"Shared block update failed {client.retrieve_block(block.id).value}"- client.agents.messages.send(+ client.agents.messages.create(agent_id=agent_state2.id,messages=[MessageCreate(@@ -114,15 +116,15 @@ def test_shared_blocks(client):],)assert (- "charles" in client.agents.core_memory.get_block(agent_id=agent_state2.id, block_label="human").value.lower()- ), f"Shared block update failed {client.agents.core_memory.get_block(agent_id=agent_state2.id, block_label="human").value}"+ "charles" in client.agents.core_memory.retrieve_block(agent_id=agent_state2.id, block_label="human").value.lower()+ ), f"Shared block update failed {client.agents.core_memory.retrieve_block(agent_id=agent_state2.id, block_label="human").value}"# cleanupclient.agents.delete(agent_state1.id)client.agents.delete(agent_state2.id)-def test_add_and_manage_tags_for_agent(client):+def test_add_and_manage_tags_for_agent(client: LettaSDKClient):"""Comprehensive happy path test for adding, retrieving, and managing tags on an agent."""@@ -136,16 +138,16 @@ def test_add_and_manage_tags_for_agent(client):value="username: sarah",),],- llm="openai/gpt-4",+ model="openai/gpt-4",embedding="openai/text-embedding-ada-002",)assert len(agent.tags) == 0# Step 1: Add multiple tags to the agent- client.agents.update(agent_id=agent.id, tags=tags_to_add)+ client.agents.modify(agent_id=agent.id, tags=tags_to_add)# Step 2: Retrieve tags for the agent and verify they match the added tags- retrieved_tags = client.agents.get(agent_id=agent.id).tags+ retrieved_tags = client.agents.retrieve(agent_id=agent.id).tagsassert set(retrieved_tags) == set(tags_to_add), f"Expected tags {tags_to_add}, but got {retrieved_tags}"# Step 3: Retrieve agents by each tag to ensure the agent is associated correctly@@ -155,25 +157,25 @@ def test_add_and_manage_tags_for_agent(client):# Step 4: Delete a specific tag from the agent and verify its removaltag_to_delete = tags_to_add.pop()- client.agents.update(agent_id=agent.id, tags=tags_to_add)+ client.agents.modify(agent_id=agent.id, tags=tags_to_add)# Verify the tag is removed from the agent's tags- remaining_tags = client.agents.get(agent_id=agent.id).tags+ remaining_tags = client.agents.retrieve(agent_id=agent.id).tagsassert tag_to_delete not in remaining_tags, f"Tag '{tag_to_delete}' was not removed as expected"assert set(remaining_tags) == set(tags_to_add), f"Expected remaining tags to be {tags_to_add[1:]}, but got {remaining_tags}"# Step 5: Delete all remaining tags from the agent- client.agents.update(agent_id=agent.id, tags=[])+ client.agents.modify(agent_id=agent.id, tags=[])# Verify all tags are removed- final_tags = client.agents.get(agent_id=agent.id).tags+ final_tags = client.agents.retrieve(agent_id=agent.id).tagsassert len(final_tags) == 0, f"Expected no tags, but found {final_tags}"# Remove agentclient.agents.delete(agent.id)-def test_agent_tags(client):+def test_agent_tags(client: LettaSDKClient):"""Test creating agents with tags and retrieving tags via the API."""# Clear all agentsall_agents = client.agents.list()@@ -187,7 +189,7 @@ def test_agent_tags(client):value="username: sarah",),],- llm="openai/gpt-4",+ model="openai/gpt-4",embedding="openai/text-embedding-ada-002",tags=["test", "agent1", "production"],)@@ -199,7 +201,7 @@ def test_agent_tags(client):value="username: sarah",),],- llm="openai/gpt-4",+ model="openai/gpt-4",embedding="openai/text-embedding-ada-002",tags=["test", "agent2", "development"],)@@ -211,7 +213,7 @@ def test_agent_tags(client):value="username: sarah",),],- llm="openai/gpt-4",+ model="openai/gpt-4",embedding="openai/text-embedding-ada-002",tags=["test", "agent3", "production"],)@@ -228,7 +230,7 @@ def test_agent_tags(client):assert paginated_tags[1] == "agent2"# Test pagination with cursor- next_page_tags = client.tag.list_tags(cursor="agent2", limit=2)+ next_page_tags = client.tag.list_tags(after="agent2", limit=2)assert len(next_page_tags) == 2assert next_page_tags[0] == "agent3"assert next_page_tags[1] == "development"@@ -249,26 +251,26 @@ def test_agent_tags(client):client.agents.delete(agent3.id)-def test_update_agent_memory_label(client, agent):+def test_update_agent_memory_label(client: LettaSDKClient, agent: AgentState):"""Test that we can update the label of a block in an agent's memory"""- current_labels = [block.label for block in client.agents.core_memory.get_blocks(agent_id=agent.id)]+ current_labels = [block.label for block in client.agents.core_memory.list_blocks(agent_id=agent.id)]example_label = current_labels[0]example_new_label = "example_new_label"assert example_new_label not in current_labels- client.agents.core_memory.update_block(+ client.agents.core_memory.modify_block(agent_id=agent.id,block_label=example_label,label=example_new_label,)- updated_block = client.agents.core_memory.get_block(agent_id=agent.id, block_label=example_new_label)+ updated_block = client.agents.core_memory.retrieve_block(agent_id=agent.id, block_label=example_new_label)assert updated_block.label == example_new_label-def test_add_remove_agent_memory_block(client, agent):+def test_add_remove_agent_memory_block(client: LettaSDKClient, agent: AgentState):"""Test that we can add and remove a block from an agent's memory"""- current_labels = [block.label for block in client.agents.core_memory.get_blocks(agent_id=agent.id)]+ current_labels = [block.label for block in client.agents.core_memory.list_blocks(agent_id=agent.id)]example_new_label = current_labels[0] + "_v2"example_new_value = "example value"assert example_new_label not in current_labels@@ -279,42 +281,42 @@ def test_add_remove_agent_memory_block(client, agent):value=example_new_value,limit=1000,)- client.blocks.link_agent_memory_block(+ client.agents.core_memory.attach_block(agent_id=agent.id,block_id=block.id,)- updated_block = client.agents.core_memory.get_block(+ updated_block = client.agents.core_memory.retrieve_block(agent_id=agent.id,block_label=example_new_label,)assert updated_block.value == example_new_value# Now unlink the block- client.blocks.unlink_agent_memory_block(+ client.agents.core_memory.detach_block(agent_id=agent.id,block_id=block.id,)- current_labels = [block.label for block in client.agents.core_memory.get_blocks(agent_id=agent.id)]+ current_labels = [block.label for block in client.agents.core_memory.list_blocks(agent_id=agent.id)]assert example_new_label not in current_labels-def test_update_agent_memory_limit(client, agent):+def test_update_agent_memory_limit(client: LettaSDKClient, agent: AgentState):"""Test that we can update the limit of a block in an agent's memory"""- current_labels = [block.label for block in client.agents.core_memory.get_blocks(agent_id=agent.id)]+ current_labels = [block.label for block in client.agents.core_memory.list_blocks(agent_id=agent.id)]example_label = current_labels[0]example_new_limit = 1- current_block = client.agents.core_memory.get_block(agent_id=agent.id, block_label=example_label)+ current_block = client.agents.core_memory.retrieve_block(agent_id=agent.id, block_label=example_label)current_block_length = len(current_block.value)- assert example_new_limit != client.agents.core_memory.get_block(agent_id=agent.id, block_label=example_label).limit+ assert example_new_limit != client.agents.core_memory.retrieve_block(agent_id=agent.id, block_label=example_label).limitassert example_new_limit < current_block_length# We expect this to throw a value errorwith pytest.raises(ApiError):- client.agents.core_memory.update_block(+ client.agents.core_memory.modify_block(agent_id=agent.id,block_label=example_label,limit=example_new_limit,@@ -323,17 +325,17 @@ def test_update_agent_memory_limit(client, agent):# Now try the same thing with a higher limitexample_new_limit = current_block_length + 10000assert example_new_limit > current_block_length- client.agents.core_memory.update_block(+ client.agents.core_memory.modify_block(agent_id=agent.id,block_label=example_label,limit=example_new_limit,)- assert example_new_limit == client.agents.core_memory.get_block(agent_id=agent.id, block_label=example_label).limit+ assert example_new_limit == client.agents.core_memory.retrieve_block(agent_id=agent.id, block_label=example_label).limit-def test_messages(client, agent):- send_message_response = client.agents.messages.send(+def test_messages(client: LettaSDKClient, agent: AgentState):+ send_message_response = client.agents.messages.create(agent_id=agent.id,messages=[MessageCreate(@@ -351,9 +353,9 @@ def test_messages(client, agent):assert len(messages_response) > 0, "Retrieving messages failed"-def test_send_system_message(client, agent):+def test_send_system_message(client: LettaSDKClient, agent: AgentState):"""Important unit test since the Letta API exposes sending system messages, but some backends don't natively support it (eg Anthropic)"""- send_system_message_response = client.agents.messages.send(+ send_system_message_response = client.agents.messages.create(agent_id=agent.id,messages=[MessageCreate(@@ -365,7 +367,7 @@ def test_send_system_message(client, agent):assert send_system_message_response, "Sending message failed"-def test_function_return_limit(client, agent):+def test_function_return_limit(client: LettaSDKClient, agent: AgentState):"""Test to see if the function return limit works"""def big_return():@@ -377,12 +379,12 @@ def test_function_return_limit(client, agent):"""return "x" * 100000- tool = client.tools.upsert_from_function(func=big_return, name="big_return", return_char_limit=1000)+ tool = client.tools.upsert_from_function(func=big_return, return_char_limit=1000)- client.agents.tools.add(agent_id=agent.id, tool_id=tool.id)+ client.agents.tools.attach(agent_id=agent.id, tool_id=tool.id)# get function response- response = client.agents.messages.send(+ response = client.agents.messages.create(agent_id=agent.id,messages=[MessageCreate(@@ -395,7 +397,7 @@ def test_function_return_limit(client, agent):response_message = Nonefor message in response.messages:- if isinstance(message, LettaMessageUnion_ToolReturnMessage):+ if isinstance(message, ToolReturnMessage):response_message = messagebreak@@ -404,7 +406,7 @@ def test_function_return_limit(client, agent):assert "function output was truncated " in res-def test_function_always_error(client, agent):+def test_function_always_error(client: LettaSDKClient, agent: AgentState):"""Test to see if function that errors works correctly"""def always_error():@@ -413,12 +415,12 @@ def test_function_always_error(client, agent):"""return 5 / 0- tool = client.tools.upsert_from_function(func=always_error, name="always_error", return_char_limit=1000)+ tool = client.tools.upsert_from_function(func=always_error, return_char_limit=1000)- client.agents.tools.add(agent_id=agent.id, tool_id=tool.id)+ client.agents.tools.attach(agent_id=agent.id, tool_id=tool.id)# get function response- response = client.agents.messages.send(+ response = client.agents.messages.create(agent_id=agent.id,messages=[MessageCreate(@@ -431,7 +433,7 @@ def test_function_always_error(client, agent):response_message = Nonefor message in response.messages:- if isinstance(message, LettaMessageUnion_ToolReturnMessage):+ if isinstance(message, ToolReturnMessage):response_message = messagebreak@@ -441,7 +443,7 @@ def test_function_always_error(client, agent):@pytest.mark.asyncio-async def test_send_message_parallel(client, agent):+async def test_send_message_parallel(client: LettaSDKClient, agent: AgentState):"""Test that sending two messages in parallel does not error."""@@ -449,7 +451,7 @@ async def test_send_message_parallel(client, agent):# Define a coroutine for sending a message using asyncio.to_thread for synchronous callsasync def send_message_task(message: str):response = await asyncio.to_thread(- client.agents.messages.send,+ client.agents.messages.create,agent_id=agent.id,messages=[MessageCreate(@@ -479,12 +481,12 @@ async def test_send_message_parallel(client, agent):assert len(responses) == len(messages), "Not all messages were processed"-def test_send_message_async(client, agent):+def test_send_message_async(client: LettaSDKClient, agent: AgentState):"""Test that we can send a message asynchronously and retrieve the messages, along with usage statistics"""test_message = "This is a test message, respond to the user with a sentence."- run = client.agents.messages.send_async(+ run = client.agents.messages.create_async(agent_id=agent.id,messages=[MessageCreate(@@ -501,7 +503,7 @@ def test_send_message_async(client, agent):start_time = time.time()while run.status == "created":time.sleep(1)- run = client.runs.get_run(run_id=run.id)+ run = client.runs.retrieve_run(run_id=run.id)print(f"Run status: {run.status}")if time.time() - start_time > 10:pytest.fail("Run took too long to complete")@@ -510,30 +512,28 @@ def test_send_message_async(client, agent):assert run.status == "completed"# Get messages for the job- messages = client.runs.get_run_messages(run_id=run.id)+ messages = client.runs.list_run_messages(run_id=run.id)assert len(messages) >= 2 # At least assistant response# Check filters- assistant_messages = client.runs.get_run_messages(run_id=run.id, role="assistant")+ assistant_messages = client.runs.list_run_messages(run_id=run.id, role="assistant")assert len(assistant_messages) > 0- tool_messages = client.runs.get_run_messages(run_id=run.id, role="tool")+ tool_messages = client.runs.list_run_messages(run_id=run.id, role="tool")assert len(tool_messages) > 0- specific_tool_messages = [- message for message in client.runs.get_run_messages(run_id=run.id) if isinstance(message, LettaMessageUnion_ToolCallMessage)- ]+ specific_tool_messages = [message for message in client.runs.list_run_messages(run_id=run.id) if isinstance(message, ToolCallMessage)]assert specific_tool_messages[0].tool_call.name == "send_message"assert len(specific_tool_messages) > 0# Get and verify usage statistics- usage = client.runs.get_run_usage(run_id=run.id)+ usage = client.runs.retrieve_run_usage(run_id=run.id)assert usage.completion_tokens >= 0assert usage.prompt_tokens >= 0assert usage.total_tokens >= 0assert usage.total_tokens == usage.completion_tokens + usage.prompt_tokens-def test_agent_creation(client):+def test_agent_creation(client: LettaSDKClient):"""Test that block IDs are properly attached when creating an agent."""offline_memory_agent_system = """You are a helpful agent. You will be provided with a list of memory blocks and a user preferences block.@@ -557,8 +557,8 @@ def test_agent_creation(client):"""Another test tool."""return "Hello from another test tool!"- tool1 = client.tools.upsert_from_function(func=test_tool, name="test_tool", tags=["test"])- tool2 = client.tools.upsert_from_function(func=another_test_tool, name="another_test_tool", tags=["test"])+ tool1 = client.tools.upsert_from_function(func=test_tool, tags=["test"])+ tool2 = client.tools.upsert_from_function(func=another_test_tool, tags=["test"])# Create test blocksoffline_persona_block = client.blocks.create(label="persona", value="persona description", limit=5000)@@ -568,7 +568,7 @@ def test_agent_creation(client):agent = client.agents.create(name=f"test_agent_{str(uuid.uuid4())}",memory_blocks=[offline_persona_block, mindy_block],- llm="openai/gpt-4",+ model="openai/gpt-4",embedding="openai/text-embedding-ada-002",tool_ids=[tool1.id, tool2.id],include_base_tools=False,@@ -582,7 +582,7 @@ def test_agent_creation(client):# Verify all memory blocks are properly attachedfor block in [offline_persona_block, mindy_block, user_preferences_block]:- agent_block = client.agents.core_memory.get_block(agent_id=agent.id, block_label=block.label)+ agent_block = client.agents.core_memory.retrieve_block(agent_id=agent.id, block_label=block.label)assert block.value == agent_block.value and block.limit == agent_block.limit# Verify the tools are properly attacheddiff --git a/tests/test_system_prompt_compiler.py b/tests/test_system_prompt_compiler.pynew file mode 100644index 000000000..d74236035--- /dev/null+++ b/tests/test_system_prompt_compiler.py@@ -0,0 +1,59 @@+from letta.services.helpers.agent_manager_helper import safe_format++CORE_MEMORY_VAR = "My core memory is that I like to eat bananas"+VARS_DICT = {"CORE_MEMORY": CORE_MEMORY_VAR}+++def test_formatter():++ # Example system prompt that has no vars+ NO_VARS = """+ THIS IS A SYSTEM PROMPT WITH NO VARS+ """++ assert NO_VARS == safe_format(NO_VARS, VARS_DICT)++ # Example system prompt that has {CORE_MEMORY}+ CORE_MEMORY_VAR = """+ THIS IS A SYSTEM PROMPT WITH NO VARS+ {CORE_MEMORY}+ """++ CORE_MEMORY_VAR_SOL = """+ THIS IS A SYSTEM PROMPT WITH NO VARS+ My core memory is that I like to eat bananas+ """++ assert CORE_MEMORY_VAR_SOL == safe_format(CORE_MEMORY_VAR, VARS_DICT)++ # Example system prompt that has {CORE_MEMORY} and {USER_MEMORY} (latter doesn't exist)+ UNUSED_VAR = """+ THIS IS A SYSTEM PROMPT WITH NO VARS+ {USER_MEMORY}+ {CORE_MEMORY}+ """++ UNUSED_VAR_SOL = """+ THIS IS A SYSTEM PROMPT WITH NO VARS+ {USER_MEMORY}+ My core memory is that I like to eat bananas+ """++ assert UNUSED_VAR_SOL == safe_format(UNUSED_VAR, VARS_DICT)++ # Example system prompt that has {CORE_MEMORY} and {USER_MEMORY} (latter doesn't exist), AND an empty {}+ UNUSED_AND_EMPRY_VAR = """+ THIS IS A SYSTEM PROMPT WITH NO VARS+ {}+ {USER_MEMORY}+ {CORE_MEMORY}+ """++ UNUSED_AND_EMPRY_VAR_SOL = """+ THIS IS A SYSTEM PROMPT WITH NO VARS+ {}+ {USER_MEMORY}+ My core memory is that I like to eat bananas+ """++ assert UNUSED_AND_EMPRY_VAR_SOL == safe_format(UNUSED_AND_EMPRY_VAR, VARS_DICT)diff --git a/tests/test_v1_routes.py b/tests/test_v1_routes.pyindex ad21c7713..4a0d027bc 100644--- a/tests/test_v1_routes.py+++ b/tests/test_v1_routes.py@@ -48,7 +48,6 @@ def add_integers_tool():@pytest.fixturedef create_integers_tool(add_integers_tool):tool_create = ToolCreate(- name=add_integers_tool.name,description=add_integers_tool.description,tags=add_integers_tool.tags,source_code=add_integers_tool.source_code,@@ -61,7 +60,6 @@ def create_integers_tool(add_integers_tool):@pytest.fixturedef update_integers_tool(add_integers_tool):tool_update = ToolUpdate(- name=add_integers_tool.name,description=add_integers_tool.description,tags=add_integers_tool.tags,source_code=add_integers_tool.source_code,@@ -291,7 +289,6 @@ def test_add_composio_tool(client, mock_sync_server, add_integers_tool):# Mock ToolCreate.from_composio to return the expected ToolCreate objectwith patch("letta.schemas.tool.ToolCreate.from_composio") as mock_from_composio:mock_from_composio.return_value = ToolCreate(- name=add_integers_tool.name,source_code=add_integers_tool.source_code,json_schema=add_integers_tool.json_schema,)