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: configure retries on anthropic client (#2254)

cthomas9542dd2fd983
diff --git a/letta/llm_api/anthropic_client.py b/letta/llm_api/anthropic_client.py
index ca010d689..d56bb87f7 100644
--- a/letta/llm_api/anthropic_client.py
+++ b/letta/llm_api/anthropic_client.py
@@ -35,6 +35,7 @@ from letta.schemas.openai.chat_completion_response import ChatCompletionResponse
from letta.schemas.openai.chat_completion_response import Message as ChoiceMessage
from letta.schemas.openai.chat_completion_response import ToolCall, UsageStatistics
from letta.services.provider_manager import ProviderManager
+from letta.settings import model_settings
from letta.tracing import trace_method
DUMMY_FIRST_USER_MESSAGE = "User initializing bootup sequence."
@@ -120,8 +121,16 @@ class AnthropicClient(LLMClientBase):
override_key = ProviderManager().get_override_key(llm_config.provider_name, actor=self.actor)
if async_client:
- return anthropic.AsyncAnthropic(api_key=override_key) if override_key else anthropic.AsyncAnthropic()
- return anthropic.Anthropic(api_key=override_key) if override_key else anthropic.Anthropic()
+ return (
+ anthropic.AsyncAnthropic(api_key=override_key, max_retries=model_settings.anthropic_max_retries)
+ if override_key
+ else anthropic.AsyncAnthropic(max_retries=model_settings.anthropic_max_retries)
+ )
+ return (
+ anthropic.Anthropic(api_key=override_key, max_retries=model_settings.anthropic_max_retries)
+ if override_key
+ else anthropic.Anthropic(max_retries=model_settings.anthropic_max_retries)
+ )
@trace_method
def build_request_data(
diff --git a/letta/settings.py b/letta/settings.py
index a638a5948..19c4adc98 100644
--- a/letta/settings.py
+++ b/letta/settings.py
@@ -95,6 +95,7 @@ class ModelSettings(BaseSettings):
# anthropic
anthropic_api_key: Optional[str] = None
+ anthropic_max_retries: int = 3
# ollama
ollama_base_url: Optional[str] = None