letta-nightly 0.6.1.dev20241208192034__py3-none-any.whl → 0.6.1.dev20241209104258__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of letta-nightly might be problematic. Click here for more details.

letta/client/client.py CHANGED
@@ -2836,7 +2836,7 @@ class LocalClient(AbstractClient):
2836
2836
  id (str): ID of the tool (`None` if not found)
2837
2837
  """
2838
2838
  tool = self.server.tool_manager.get_tool_by_name(tool_name=name, actor=self.user)
2839
- return tool.id
2839
+ return tool.id if tool else None
2840
2840
 
2841
2841
  def load_data(self, connector: DataConnector, source_name: str):
2842
2842
  """
letta/errors.py CHANGED
@@ -22,6 +22,30 @@ class LettaToolCreateError(LettaError):
22
22
  super().__init__(self.message)
23
23
 
24
24
 
25
+ class LettaConfigurationError(LettaError):
26
+ """Error raised when there are configuration-related issues."""
27
+
28
+ def __init__(self, message: str, missing_fields: Optional[List[str]] = None):
29
+ self.missing_fields = missing_fields or []
30
+ super().__init__(message)
31
+
32
+
33
+ class LettaAgentNotFoundError(LettaError):
34
+ """Error raised when an agent is not found."""
35
+
36
+ def __init__(self, message: str):
37
+ self.message = message
38
+ super().__init__(self.message)
39
+
40
+
41
+ class LettaUserNotFoundError(LettaError):
42
+ """Error raised when a user is not found."""
43
+
44
+ def __init__(self, message: str):
45
+ self.message = message
46
+ super().__init__(self.message)
47
+
48
+
25
49
  class LLMError(LettaError):
26
50
  pass
27
51
 
@@ -5,6 +5,7 @@ from typing import List, Optional, Union
5
5
  import requests
6
6
 
7
7
  from letta.constants import CLI_WARNING_PREFIX
8
+ from letta.errors import LettaConfigurationError
8
9
  from letta.llm_api.anthropic import anthropic_chat_completions_request
9
10
  from letta.llm_api.azure_openai import azure_openai_chat_completions_request
10
11
  from letta.llm_api.google_ai import (
@@ -148,7 +149,7 @@ def create(
148
149
  if llm_config.model_endpoint_type == "openai":
149
150
  if model_settings.openai_api_key is None and llm_config.model_endpoint == "https://api.openai.com/v1":
150
151
  # only is a problem if we are *not* using an openai proxy
151
- raise ValueError(f"OpenAI key is missing from letta config file")
152
+ raise LettaConfigurationError(message="OpenAI key is missing from letta config file", missing_fields=["openai_api_key"])
152
153
 
153
154
  data = build_openai_chat_completions_request(llm_config, messages, user_id, functions, function_call, use_tool_naming, max_tokens)
154
155
  if stream: # Client requested token streaming
@@ -187,13 +188,19 @@ def create(
187
188
  raise NotImplementedError(f"Streaming not yet implemented for {llm_config.model_endpoint_type}")
188
189
 
189
190
  if model_settings.azure_api_key is None:
190
- raise ValueError(f"Azure API key is missing. Did you set AZURE_API_KEY in your env?")
191
+ raise LettaConfigurationError(
192
+ message="Azure API key is missing. Did you set AZURE_API_KEY in your env?", missing_fields=["azure_api_key"]
193
+ )
191
194
 
192
195
  if model_settings.azure_base_url is None:
193
- raise ValueError(f"Azure base url is missing. Did you set AZURE_BASE_URL in your env?")
196
+ raise LettaConfigurationError(
197
+ message="Azure base url is missing. Did you set AZURE_BASE_URL in your env?", missing_fields=["azure_base_url"]
198
+ )
194
199
 
195
200
  if model_settings.azure_api_version is None:
196
- raise ValueError(f"Azure API version is missing. Did you set AZURE_API_VERSION in your env?")
201
+ raise LettaConfigurationError(
202
+ message="Azure API version is missing. Did you set AZURE_API_VERSION in your env?", missing_fields=["azure_api_version"]
203
+ )
197
204
 
198
205
  # Set the llm config model_endpoint from model_settings
199
206
  # For Azure, this model_endpoint is required to be configured via env variable, so users don't need to provide it in the LLM config
@@ -291,7 +298,7 @@ def create(
291
298
  raise NotImplementedError(f"Streaming not yet implemented for Groq.")
292
299
 
293
300
  if model_settings.groq_api_key is None and llm_config.model_endpoint == "https://api.groq.com/openai/v1/chat/completions":
294
- raise ValueError(f"Groq key is missing from letta config file")
301
+ raise LettaConfigurationError(message="Groq key is missing from letta config file", missing_fields=["groq_api_key"])
295
302
 
296
303
  # force to true for groq, since they don't support 'content' is non-null
297
304
  if llm_config.put_inner_thoughts_in_kwargs:
@@ -344,7 +351,7 @@ def create(
344
351
  raise NotImplementedError(f"Streaming not yet implemented for TogetherAI (via the /completions endpoint).")
345
352
 
346
353
  if model_settings.together_api_key is None and llm_config.model_endpoint == "https://api.together.ai/v1/completions":
347
- raise ValueError(f"TogetherAI key is missing from letta config file")
354
+ raise LettaConfigurationError(message="TogetherAI key is missing from letta config file", missing_fields=["together_api_key"])
348
355
 
349
356
  return get_chat_completion(
350
357
  model=llm_config.model,
@@ -187,7 +187,7 @@ class SqlalchemyBase(CommonSqlalchemyMetaMixins, Base):
187
187
  logger.exception(f"Failed to hard delete {self.__class__.__name__} with ID {self.id}")
188
188
  raise ValueError(f"Failed to hard delete {self.__class__.__name__} with ID {self.id}: {e}")
189
189
  else:
190
- logger.info(f"{self.__class__.__name__} with ID {self.id} successfully hard deleted")
190
+ logger.debug(f"{self.__class__.__name__} with ID {self.id} successfully hard deleted")
191
191
 
192
192
  def update(self, db_session: "Session", actor: Optional["User"] = None) -> Type["SqlalchemyBase"]:
193
193
  logger.debug(f"Updating {self.__class__.__name__} with ID: {self.id} with actor={actor}")
letta/schemas/message.py CHANGED
@@ -481,7 +481,20 @@ class Message(BaseMessage):
481
481
  return f"<{xml_tag}>{string}</{xml_tag}" if xml_tag else string
482
482
 
483
483
  if self.role == "system":
484
- raise ValueError(f"Anthropic 'system' role not supported")
484
+ # NOTE: this is not for system instructions, but instead system "events"
485
+
486
+ assert all([v is not None for v in [self.text, self.role]]), vars(self)
487
+ # Two options here, we would use system.package_system_message,
488
+ # or use a more Anthropic-specific packaging ie xml tags
489
+ user_system_event = add_xml_tag(string=f"SYSTEM ALERT: {self.text}", xml_tag="event")
490
+ anthropic_message = {
491
+ "content": user_system_event,
492
+ "role": "user",
493
+ }
494
+
495
+ # Optional field, do not include if null
496
+ if self.name is not None:
497
+ anthropic_message["name"] = self.name
485
498
 
486
499
  elif self.role == "user":
487
500
  assert all([v is not None for v in [self.text, self.role]]), vars(self)
@@ -13,6 +13,7 @@ from starlette.middleware.cors import CORSMiddleware
13
13
 
14
14
  from letta.__init__ import __version__
15
15
  from letta.constants import ADMIN_PREFIX, API_PREFIX, OPENAI_API_PREFIX
16
+ from letta.errors import LettaAgentNotFoundError, LettaUserNotFoundError
16
17
  from letta.schemas.letta_response import LettaResponse
17
18
  from letta.server.constants import REST_DEFAULT_PORT
18
19
 
@@ -144,6 +145,31 @@ def create_application() -> "FastAPI":
144
145
  debug=True,
145
146
  )
146
147
 
148
+ @app.exception_handler(Exception)
149
+ async def generic_error_handler(request, exc):
150
+ # Log the actual error for debugging
151
+ log.error(f"Unhandled error: {exc}", exc_info=True)
152
+
153
+ # Print the stack trace
154
+ print(f"Stack trace: {exc.__traceback__}")
155
+
156
+ return JSONResponse(
157
+ status_code=500,
158
+ content={
159
+ "detail": "An internal server error occurred",
160
+ # Only include error details in debug/development mode
161
+ # "debug_info": str(exc) if settings.debug else None
162
+ },
163
+ )
164
+
165
+ @app.exception_handler(LettaAgentNotFoundError)
166
+ async def agent_not_found_handler(request, exc):
167
+ return JSONResponse(status_code=404, content={"detail": "Agent not found"})
168
+
169
+ @app.exception_handler(LettaUserNotFoundError)
170
+ async def user_not_found_handler(request, exc):
171
+ return JSONResponse(status_code=404, content={"detail": "User not found"})
172
+
147
173
  settings.cors_origins.append("https://app.letta.com")
148
174
  print(f"▶ View using ADE at: https://app.letta.com/development-servers/local/dashboard")
149
175
 
letta/server/server.py CHANGED
@@ -21,6 +21,7 @@ from letta.agent_store.storage import StorageConnector, TableType
21
21
  from letta.chat_only_agent import ChatOnlyAgent
22
22
  from letta.credentials import LettaCredentials
23
23
  from letta.data_sources.connectors import DataConnector, load_data
24
+ from letta.errors import LettaAgentNotFoundError, LettaUserNotFoundError
24
25
 
25
26
  # TODO use custom interface
26
27
  from letta.interface import AgentInterface # abstract
@@ -397,7 +398,7 @@ class SyncServer(Server):
397
398
  with agent_lock:
398
399
  agent_state = self.get_agent(agent_id=agent_id)
399
400
  if agent_state is None:
400
- raise ValueError(f"Agent (agent_id={agent_id}) does not exist")
401
+ raise LettaAgentNotFoundError(f"Agent (agent_id={agent_id}) does not exist")
401
402
  elif agent_state.user_id is None:
402
403
  raise ValueError(f"Agent (agent_id={agent_id}) does not have a user_id")
403
404
  actor = self.user_manager.get_user_by_id(user_id=agent_state.user_id)
@@ -1249,9 +1250,9 @@ class SyncServer(Server):
1249
1250
  reverse: Optional[bool] = False,
1250
1251
  ) -> List[Passage]:
1251
1252
  if self.user_manager.get_user_by_id(user_id=user_id) is None:
1252
- raise ValueError(f"User user_id={user_id} does not exist")
1253
+ raise LettaUserNotFoundError(f"User user_id={user_id} does not exist")
1253
1254
  if self.ms.get_agent(agent_id=agent_id, user_id=user_id) is None:
1254
- raise ValueError(f"Agent agent_id={agent_id} does not exist")
1255
+ raise LettaAgentNotFoundError(f"Agent agent_id={agent_id} does not exist")
1255
1256
 
1256
1257
  # Get the agent object (loaded in memory)
1257
1258
  letta_agent = self.load_agent(agent_id=agent_id)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: letta-nightly
3
- Version: 0.6.1.dev20241208192034
3
+ Version: 0.6.1.dev20241209104258
4
4
  Summary: Create LLM agents with long-term memory and custom tools
5
5
  License: Apache License
6
6
  Author: Letta Team
@@ -13,7 +13,7 @@ letta/cli/cli.py,sha256=5spd3RZxZ5JukPvyBvGmat8fS97Eb01S58w8MF_3Ybs,16735
13
13
  letta/cli/cli_config.py,sha256=tB0Wgz3O9j6KiCsU1HWfsKmhNM9RqLsAxzxEDFQFGnM,8565
14
14
  letta/cli/cli_load.py,sha256=x4L8s15GwIW13xrhKYFWHo_y-IVGtoPDHWWKcHDRP10,4587
15
15
  letta/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
- letta/client/client.py,sha256=lMqOkJxbYHtMPI-2nml4OOilfBXPidNlIjwM7u4xA3c,124171
16
+ letta/client/client.py,sha256=yUshRIkYmNCZdMkAeh179RPQG1Jcgp-iWSbbTWNDsQY,124189
17
17
  letta/client/streaming.py,sha256=Hh5pjlyrdCuO2V75ZCxSSOCPd3BmHdKFGaIUJC6fBp0,4775
18
18
  letta/client/utils.py,sha256=OJlAKWrldc4I6M1WpcTWNtPJ4wfxlzlZqWLfCozkFtI,2872
19
19
  letta/config.py,sha256=AF4XY6grcu87OLjrWXh1ufnyKWsCL0qER-_9jQCAlU0,18947
@@ -22,7 +22,7 @@ letta/credentials.py,sha256=D9mlcPsdDWlIIXQQD8wSPE9M_QvsRrb0p3LB5i9OF5Q,5806
22
22
  letta/data_sources/connectors.py,sha256=5VKxfeV-QyUlK1wexLlpgar99dGm6PHxFaEbSeByo_U,9923
23
23
  letta/data_sources/connectors_helper.py,sha256=2TQjCt74fCgT5sw1AP8PalDEk06jPBbhrPG4HVr-WLs,3371
24
24
  letta/embeddings.py,sha256=3vJaQ8RMLLp6yiYZGsthq6Xsu4keb9gp7DYN_2GPBFU,8459
25
- letta/errors.py,sha256=mFeTpZP37otDMr68s9hyGOnafJPrWeblQOI79cgP4nQ,3209
25
+ letta/errors.py,sha256=Voy_BP0W_M816-vWudKLBlgydRufPPA-Q2PNd-SvZYc,3897
26
26
  letta/functions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  letta/functions/function_sets/base.py,sha256=anK6XJQlmTu9eC33700Eh7NWxQ0NTLUC2Vxpn6ihvnY,9034
28
28
  letta/functions/function_sets/extras.py,sha256=Jik3UiDqYTm4Lam1XPTvuVjvgUHwIAhopsnbmVhGMBg,4732
@@ -42,7 +42,7 @@ letta/llm_api/azure_openai_constants.py,sha256=oXtKrgBFHf744gyt5l1thILXgyi8NDNUr
42
42
  letta/llm_api/cohere.py,sha256=vDRd-SUGp1t_JUIdwC3RkIhwMl0OY7n-tAU9uPORYkY,14826
43
43
  letta/llm_api/google_ai.py,sha256=xKz9JDZs3m6yzSfcgCAAUD_rjI20BBIINoiSvlcnOw0,17621
44
44
  letta/llm_api/helpers.py,sha256=F8xZDZgDojWX5v-0vakyeUQyCyBr1HmzmsITRdOsmVg,13457
45
- letta/llm_api/llm_api_tools.py,sha256=h2eudFygI6yFIOaA5Q9GmhiwMPq2mHQyhoSHbn57CCE,16866
45
+ letta/llm_api/llm_api_tools.py,sha256=TfRBesbYkIoQRhntKaZkCY9uYk0efBIOJBEdjcQA8g4,17337
46
46
  letta/llm_api/mistral.py,sha256=fHdfD9ug-rQIk2qn8tRKay1U6w9maF11ryhKi91FfXM,1593
47
47
  letta/llm_api/openai.py,sha256=4GEGROTv4vLawSgODnAHCI-DeIWDqrhuxtKrqYzHvso,24160
48
48
  letta/local_llm/README.md,sha256=hFJyw5B0TU2jrh9nb0zGZMgdH-Ei1dSRfhvPQG_NSoU,168
@@ -105,7 +105,7 @@ letta/orm/mixins.py,sha256=TpP5dFAcGu2VvHZQSt8ymc0UjQhcVp5-Fc2C4v_nUTM,1508
105
105
  letta/orm/organization.py,sha256=ZoHow3Tpdh9TXDvB4VZbArbUCgbErFTSQMriYAzulqA,2397
106
106
  letta/orm/sandbox_config.py,sha256=PCMHE-eJPzBT-90OYtXjEMRF4f9JB8AJIGETE7bu-f0,2870
107
107
  letta/orm/source.py,sha256=Ib0XHCMt345RjBSC30A398rZ21W5mA4PXX00XNXyd24,2021
108
- letta/orm/sqlalchemy_base.py,sha256=_uix_6bCC_rZYbTKL_OpldjTgrEv-9l6FL3ysKsgUZU,13877
108
+ letta/orm/sqlalchemy_base.py,sha256=Wgmy9QAiLW1sS7jm3rtow8HWtdwkPLvRJpDEp1VN4LE,13878
109
109
  letta/orm/tool.py,sha256=R1I3FGjt8xlW7DPkwV9zlliOcAB3vpphAZTQTsvDBXs,2982
110
110
  letta/orm/tools_agents.py,sha256=mBMGQsTEx_ckfhZb2-2nqbxHBEMhvDXim6w6tFHHWBQ,1195
111
111
  letta/orm/user.py,sha256=bUZzyBQXfR0w7mZAkThPAQE6kKx6W--Rw6uAiPEUW3s,1133
@@ -153,7 +153,7 @@ letta/schemas/letta_request.py,sha256=E6OwKiceNffpdGdQMI1qc0jEfpL_e7O9BTzklOkbt6
153
153
  letta/schemas/letta_response.py,sha256=vQV5uqe-kq9fc4wCo-sVB_PJt5yUk8DB2zOgHsrmN-k,6189
154
154
  letta/schemas/llm_config.py,sha256=RbgnCaqYd_yl-Xs7t-DEI1NhpKD8WiVWjxcwq5mZd5M,4467
155
155
  letta/schemas/memory.py,sha256=80Y7gqWQQndhNkJ-0j38d2m619gTlfes_qJNA6_ant8,10040
156
- letta/schemas/message.py,sha256=e6Zwq_2iL81OrdaculzpdNyYtV6iL0R6gU76_ma7efo,33540
156
+ letta/schemas/message.py,sha256=GFuHcfPU5kgRXgu70osF9H03Mv0JcO5nbURTYR3XXDg,34154
157
157
  letta/schemas/openai/chat_completion_request.py,sha256=AOIwgbN3CZKVqkuXeMHeSa53u4h0wVq69t3T_LJ0vIE,3389
158
158
  letta/schemas/openai/chat_completion_response.py,sha256=ub-oVSyLpuJd-5_yzCSIRR8tD3GM83IeDO1c1uAATa4,3970
159
159
  letta/schemas/openai/chat_completions.py,sha256=V0ZPIIk-ds3O6MAkNHMz8zh1hqMFSPrTcYr88WDYzWE,3588
@@ -172,7 +172,7 @@ letta/server/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
172
172
  letta/server/constants.py,sha256=yAdGbLkzlOU_dLTx0lKDmAnj0ZgRXCEaIcPJWO69eaE,92
173
173
  letta/server/generate_openapi_schema.sh,sha256=0OtBhkC1g6CobVmNEd_m2B6sTdppjbJLXaM95icejvE,371
174
174
  letta/server/rest_api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
175
- letta/server/rest_api/app.py,sha256=A1BtotZbnqEHpjoNq8U6FtCL27Sk643lPMaHFnciCUo,7951
175
+ letta/server/rest_api/app.py,sha256=Plf21olyMT6a6q8cq8-HNoGx6IcJdo3acZefop6AP0s,8989
176
176
  letta/server/rest_api/auth/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
177
177
  letta/server/rest_api/auth/index.py,sha256=fQBGyVylGSRfEMLQ17cZzrHd5Y1xiVylvPqH5Rl-lXQ,1378
178
178
  letta/server/rest_api/auth_token.py,sha256=725EFEIiNj4dh70hrSd94UysmFD8vcJLrTRfNHkzxDo,774
@@ -198,7 +198,7 @@ letta/server/rest_api/routers/v1/tools.py,sha256=ajYUo_cgUBDfm4Ja_EufxSdhBWoAb5N
198
198
  letta/server/rest_api/routers/v1/users.py,sha256=M1wEr2IyHzuRwINYxLXTkrbAH3osLe_cWjzrWrzR1aw,3729
199
199
  letta/server/rest_api/static_files.py,sha256=NG8sN4Z5EJ8JVQdj19tkFa9iQ1kBPTab9f_CUxd_u4Q,3143
200
200
  letta/server/rest_api/utils.py,sha256=6Z0T0kHIwDAgTIFh38Q1JQ_nhANgdqXcSlsuY41pL6M,3158
201
- letta/server/server.py,sha256=ti7Q7QwkdJR9idxoriDMwWyzT3iI8QaOPc5H0qgv6u8,81811
201
+ letta/server/server.py,sha256=3sgoeetKRww5gPZyWiKhbMkvhyWPLAnI6A1NYBoW-YI,81922
202
202
  letta/server/startup.sh,sha256=wTOQOJJZw_Iec57WIu0UW0AVflk0ZMWYZWg8D3T_gSQ,698
203
203
  letta/server/static_files/assets/index-43ab4d62.css,sha256=Q6tNYu7XNRgkTZau1dVwCQTT4YpLGLF7VgTNzLcMaQI,7613
204
204
  letta/server/static_files/assets/index-4848e3d7.js,sha256=XkoX-NW0x1Hb7uTWslfpuPP73MnNDthOdJLHLID9EhM,146806
@@ -231,8 +231,8 @@ letta/streaming_interface.py,sha256=_FPUWy58j50evHcpXyd7zB1wWqeCc71NCFeWh_TBvnw,
231
231
  letta/streaming_utils.py,sha256=329fsvj1ZN0r0LpQtmMPZ2vSxkDBIUUwvGHZFkjm2I8,11745
232
232
  letta/system.py,sha256=buKYPqG5n2x41hVmWpu6JUpyd7vTWED9Km2_M7dLrvk,6960
233
233
  letta/utils.py,sha256=7FGZYp8JCEtP0PBSfV03Zj4kW3pwV7qpNki4AOU3a94,32913
234
- letta_nightly-0.6.1.dev20241208192034.dist-info/LICENSE,sha256=mExtuZ_GYJgDEI38GWdiEYZizZS4KkVt2SF1g_GPNhI,10759
235
- letta_nightly-0.6.1.dev20241208192034.dist-info/METADATA,sha256=fsauFBpRSwLI3DzsG2M8lrGAZY4j4wS17oBW4ucwfkU,11459
236
- letta_nightly-0.6.1.dev20241208192034.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
237
- letta_nightly-0.6.1.dev20241208192034.dist-info/entry_points.txt,sha256=2zdiyGNEZGV5oYBuS-y2nAAgjDgcC9yM_mHJBFSRt5U,40
238
- letta_nightly-0.6.1.dev20241208192034.dist-info/RECORD,,
234
+ letta_nightly-0.6.1.dev20241209104258.dist-info/LICENSE,sha256=mExtuZ_GYJgDEI38GWdiEYZizZS4KkVt2SF1g_GPNhI,10759
235
+ letta_nightly-0.6.1.dev20241209104258.dist-info/METADATA,sha256=fBv_MvuPJjnYKDn-qPDlLLcAFrdH43ay8CEoRNo6hMA,11459
236
+ letta_nightly-0.6.1.dev20241209104258.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
237
+ letta_nightly-0.6.1.dev20241209104258.dist-info/entry_points.txt,sha256=2zdiyGNEZGV5oYBuS-y2nAAgjDgcC9yM_mHJBFSRt5U,40
238
+ letta_nightly-0.6.1.dev20241209104258.dist-info/RECORD,,