Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: re-raise LLMError before wrapping with handle_llm_error (#9482)
jnjpnge3eafb1977a8
diff --git a/letta/adapters/simple_llm_request_adapter.py b/letta/adapters/simple_llm_request_adapter.pyindex a2818f506..f67e7dc9f 100644--- a/letta/adapters/simple_llm_request_adapter.py+++ b/letta/adapters/simple_llm_request_adapter.py@@ -1,6 +1,7 @@from typing import AsyncGeneratorfrom letta.adapters.letta_llm_request_adapter import LettaLLMRequestAdapter+from letta.errors import LLMErrorfrom letta.helpers.datetime_helpers import get_utc_timestamp_nsfrom letta.schemas.enums import LLMCallTypefrom letta.schemas.letta_message import LettaMessage@@ -54,6 +55,8 @@ class SimpleLLMRequestAdapter(LettaLLMRequestAdapter):try:self.response_data = await self.llm_client.request_async_with_telemetry(request_data, self.llm_config)except Exception as e:+ if isinstance(e, LLMError):+ raiseraise self.llm_client.handle_llm_error(e, llm_config=self.llm_config)self.llm_request_finish_timestamp_ns = get_utc_timestamp_ns()diff --git a/letta/adapters/simple_llm_stream_adapter.py b/letta/adapters/simple_llm_stream_adapter.pyindex 80da0a641..f09fcaea8 100644--- a/letta/adapters/simple_llm_stream_adapter.py+++ b/letta/adapters/simple_llm_stream_adapter.py@@ -2,6 +2,7 @@ import jsonfrom typing import AsyncGenerator, Listfrom letta.adapters.letta_llm_stream_adapter import LettaLLMStreamAdapter+from letta.errors import LLMErrorfrom letta.log import get_loggerlogger = get_logger(__name__)@@ -151,6 +152,8 @@ class SimpleLLMStreamAdapter(LettaLLMStreamAdapter):error_msg=str(e),error_type=type(e).__name__,)+ if isinstance(e, LLMError):+ raiseraise self.llm_client.handle_llm_error(e, llm_config=self.llm_config)# Process the stream and yield chunks immediately for TTFT@@ -169,6 +172,8 @@ class SimpleLLMStreamAdapter(LettaLLMStreamAdapter):error_msg=str(e),error_type=type(e).__name__,)+ if isinstance(e, LLMError):+ raiseraise self.llm_client.handle_llm_error(e, llm_config=self.llm_config)# After streaming completes, extract the accumulated datadiff --git a/letta/agents/letta_agent.py b/letta/agents/letta_agent.pyindex 219762e77..0001e59ac 100644--- a/letta/agents/letta_agent.py+++ b/letta/agents/letta_agent.py@@ -20,7 +20,7 @@ from letta.agents.helpers import (generate_step_id,)from letta.constants import DEFAULT_MAX_STEPS, NON_USER_MSG_PREFIX, REQUEST_HEARTBEAT_PARAM-from letta.errors import ContextWindowExceededError+from letta.errors import ContextWindowExceededError, LLMErrorfrom letta.helpers import ToolRulesSolverfrom letta.helpers.datetime_helpers import AsyncTimer, get_utc_time, get_utc_timestamp_ns, ns_to_msfrom letta.helpers.reasoning_helper import scrub_inner_thoughts_from_messages@@ -1546,6 +1546,8 @@ class LettaAgent(BaseAgent):run_id=run_id,step_id=step_id,)+ elif isinstance(e, LLMError):+ raiseelse:raise llm_client.handle_llm_error(e, llm_config=llm_config)