Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: use LLMServerError to distinguish provider errors (#2859)
cthomas33bee28d0877
diff --git a/letta/llm_api/anthropic_client.py b/letta/llm_api/anthropic_client.pyindex d83c25c5d..a6d274f34 100644--- a/letta/llm_api/anthropic_client.py+++ b/letta/llm_api/anthropic_client.py@@ -497,7 +497,7 @@ class AnthropicClient(LLMClientBase):try:args_json = json.loads(arguments)if not isinstance(args_json, dict):- raise ValueError("Expected parseable json object for arguments")+ raise LLMServerError("Expected parseable json object for arguments")except:arguments = str(tool_input["function"]["arguments"])else:@@ -854,7 +854,7 @@ def remap_finish_reason(stop_reason: str) -> str:elif stop_reason == "tool_use":return "function_call"else:- raise ValueError(f"Unexpected stop_reason: {stop_reason}")+ raise LLMServerError(f"Unexpected stop_reason: {stop_reason}")def strip_xml_tags(string: str, tag: Optional[str]) -> str:diff --git a/letta/llm_api/google_vertex_client.py b/letta/llm_api/google_vertex_client.pyindex 957f08c58..551dfc55d 100644--- a/letta/llm_api/google_vertex_client.py+++ b/letta/llm_api/google_vertex_client.py@@ -379,11 +379,10 @@ class GoogleVertexClient(LLMClientBase):if content is None or content.role is None or content.parts is None:# This means the response is malformed like MALFORMED_FUNCTION_CALL- # NOTE: must be a ValueError to trigger a retryif candidate.finish_reason == "MALFORMED_FUNCTION_CALL":- raise ValueError(f"Error in response data from LLM: {candidate.finish_reason}")+ raise LLMServerError(f"Malformed response from Google Vertex: {candidate.finish_reason}")else:- raise ValueError(f"Error in response data from LLM: {candidate.model_dump()}")+ raise LLMServerError(f"Invalid response data from Google Vertex: {candidate.model_dump()}")role = content.roleassert role == "model", f"Unknown role in response: {role}"@@ -477,7 +476,7 @@ class GoogleVertexClient(LLMClientBase):except json.decoder.JSONDecodeError:if candidate.finish_reason == "MAX_TOKENS":- raise ValueError("Could not parse response data from LLM: exceeded max token limit")+ raise LLMServerError("Could not parse response data from LLM: exceeded max token limit")# Inner thoughts are the content by defaultinner_thoughts = response_message.text@@ -506,7 +505,7 @@ class GoogleVertexClient(LLMClientBase):elif finish_reason == "RECITATION":openai_finish_reason = "content_filter"else:- raise ValueError(f"Unrecognized finish reason in Google AI response: {finish_reason}")+ raise LLMServerError(f"Unrecognized finish reason in Google AI response: {finish_reason}")choices.append(Choice(