Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: anthropic system message parse (#1467)
cthomasdf899ee05b5c
diff --git a/letta/errors.py b/letta/errors.pyindex d5d832b08..a79d5bdf1 100644--- a/letta/errors.py+++ b/letta/errors.py@@ -70,6 +70,14 @@ class LLMRateLimitError(LLMError):"""Error when rate limited by LLM service"""+class LLMBadRequestError(LLMError):+ """Error when LLM service cannot process request"""+++class LLMAuthenticationError(LLMError):+ """Error when authentication fails with LLM service"""++class LLMPermissionDeniedError(LLMError):"""Error when permission is denied by LLM service"""@@ -82,6 +90,10 @@ class LLMUnprocessableEntityError(LLMError):"""Error when request is well-formed but semantically invalid"""+class LLMServerError(LLMError):+ """Error when LLM service encounters an internal error"""++class BedrockPermissionError(LettaError):"""Exception raised for errors in the Bedrock permission process."""diff --git a/letta/llm_api/anthropic_client.py b/letta/llm_api/anthropic_client.pyindex c0f7a39b6..a96a3d294 100644--- a/letta/llm_api/anthropic_client.py+++ b/letta/llm_api/anthropic_client.py@@ -5,6 +5,17 @@ from typing import List, Optional, Unionimport anthropicfrom anthropic.types import Message as AnthropicMessage+from letta.errors import (+ ErrorCode,+ LLMAuthenticationError,+ LLMBadRequestError,+ LLMConnectionError,+ LLMNotFoundError,+ LLMPermissionDeniedError,+ LLMRateLimitError,+ LLMServerError,+ LLMUnprocessableEntityError,+)from letta.helpers.datetime_helpers import get_utc_timefrom letta.llm_api.helpers import add_inner_thoughts_to_functions, unpack_all_inner_thoughts_from_kwargsfrom letta.llm_api.llm_client_base import LLMClientBase@@ -104,7 +115,7 @@ class AnthropicClient(LLMClientBase):data["messages"] = [m.to_anthropic_dict(inner_thoughts_xml_tag=inner_thoughts_xml_tag,- put_inner_thoughts_in_kwargs=self.llm_config.put_inner_thoughts_in_kwargs,+ put_inner_thoughts_in_kwargs=bool(self.llm_config.put_inner_thoughts_in_kwargs),)for m in messages]@@ -241,7 +252,7 @@ class AnthropicClient(LLMClientBase):response = AnthropicMessage(**response_data)prompt_tokens = response.usage.input_tokenscompletion_tokens = response.usage.output_tokens- finish_reason = remap_finish_reason(response.stop_reason)+ finish_reason = remap_finish_reason(str(response.stop_reason))content = Nonereasoning_content = Nonediff --git a/letta/llm_api/llm_client_base.py b/letta/llm_api/llm_client_base.pyindex 66cbf244d..31f68ef87 100644--- a/letta/llm_api/llm_client_base.py+++ b/letta/llm_api/llm_client_base.py@@ -4,6 +4,7 @@ from typing import List, Optional, Unionfrom openai import AsyncStream, Streamfrom openai.types.chat.chat_completion_chunk import ChatCompletionChunk+from letta.errors import LLMErrorfrom letta.schemas.llm_config import LLMConfigfrom letta.schemas.message import Messagefrom letta.schemas.openai.chat_completion_response import ChatCompletionResponsediff --git a/letta/schemas/message.py b/letta/schemas/message.pyindex 65e5d84be..503a40720 100644--- a/letta/schemas/message.py+++ b/letta/schemas/message.py@@ -681,7 +681,7 @@ class Message(BaseMessage):user_system_event = add_xml_tag(string=f"SYSTEM ALERT: {text_content}", xml_tag="event")anthropic_message = {"content": user_system_event,- "role": "user",+ "role": "system",}elif self.role == "user":