Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

feat: add more trace methods (#2471)

Sarah Wooders4cc075f1fcc1
diff --git a/letta/llm_api/anthropic_client.py b/letta/llm_api/anthropic_client.py
index b81967d42..eefee9651 100644
--- a/letta/llm_api/anthropic_client.py
+++ b/letta/llm_api/anthropic_client.py
@@ -288,6 +288,7 @@ class AnthropicClient(LLMClientBase):
token_count -= 8
return token_count
+ @trace_method
def handle_llm_error(self, e: Exception) -> Exception:
if isinstance(e, anthropic.APIConnectionError):
logger.warning(f"[Anthropic] API connection error: {e.__cause__}")
diff --git a/letta/llm_api/openai_client.py b/letta/llm_api/openai_client.py
index d0633238d..919120941 100644
--- a/letta/llm_api/openai_client.py
+++ b/letta/llm_api/openai_client.py
@@ -279,6 +279,7 @@ class OpenAIClient(LLMClientBase):
return chat_completion_response
+ @trace_method
async def stream_async(self, request_data: dict, llm_config: LLMConfig) -> AsyncStream[ChatCompletionChunk]:
"""
Performs underlying asynchronous streaming request to OpenAI and returns the async stream iterator.
@@ -290,6 +291,7 @@ class OpenAIClient(LLMClientBase):
)
return response_stream
+ @trace_method
def handle_llm_error(self, e: Exception) -> Exception:
"""
Maps OpenAI-specific errors to common LLMError types.