From 9542dd2fd983947f72d41cf808cb4f0710d2d3a7 Mon Sep 17 00:00:00 2001 From: cthomas Date: Mon, 19 May 2025 16:19:27 -0700 Subject: [PATCH] feat: configure retries on anthropic client (#2254) --- letta/llm_api/anthropic_client.py | 13 +++++++++++-- letta/settings.py | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/letta/llm_api/anthropic_client.py b/letta/llm_api/anthropic_client.py index ca010d68..d56bb87f 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 a638a594..19c4adc9 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