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 in `claude-3-7-sonnet-20250219` (#1102)

Sarah Woodersfbfc8a14aabb
diff --git a/letta/llm_api/anthropic.py b/letta/llm_api/anthropic.py
index b8151e7af..205f4cb74 100644
--- a/letta/llm_api/anthropic.py
+++ b/letta/llm_api/anthropic.py
@@ -47,14 +47,39 @@ BASE_URL = "https://api.anthropic.com/v1"
# https://docs.anthropic.com/claude/docs/models-overview
# Sadly hardcoded
MODEL_LIST = [
+ ## Opus
{
"name": "claude-3-opus-20240229",
"context_window": 200000,
},
+ ## Sonnet
+ # 3.0
+ {
+ "name": "claude-3-sonnet-20240229",
+ "context_window": 200000,
+ },
+ # 3.5
+ {
+ "name": "claude-3-5-sonnet-20240620",
+ "context_window": 200000,
+ },
+ # 3.5 new
{
"name": "claude-3-5-sonnet-20241022",
"context_window": 200000,
},
+ # 3.7
+ {
+ "name": "claude-3-7-sonnet-20250219",
+ "context_window": 200000,
+ },
+ ## Haiku
+ # 3.0
+ {
+ "name": "claude-3-haiku-20240307",
+ "context_window": 200000,
+ },
+ # 3.5
{
"name": "claude-3-5-haiku-20241022",
"context_window": 200000,
@@ -75,7 +100,18 @@ def anthropic_get_model_list(url: str, api_key: Union[str, None]) -> dict:
"""https://docs.anthropic.com/claude/docs/models-overview"""
# NOTE: currently there is no GET /models, so we need to hardcode
- return MODEL_LIST
+ # return MODEL_LIST
+
+ anthropic_override_key = ProviderManager().get_anthropic_override_key()
+ if anthropic_override_key:
+ anthropic_client = anthropic.Anthropic(api_key=anthropic_override_key)
+ elif model_settings.anthropic_api_key:
+ anthropic_client = anthropic.Anthropic()
+
+ models = anthropic_client.models.list()
+ models_json = models.model_dump()
+ assert "data" in models_json, f"Anthropic model query response missing 'data' field: {models_json}"
+ return models_json["data"]
def convert_tools_to_anthropic_format(tools: List[Tool]) -> List[dict]:
diff --git a/letta/schemas/providers.py b/letta/schemas/providers.py
index bc11909d8..1de05b0e0 100644
--- a/letta/schemas/providers.py
+++ b/letta/schemas/providers.py
@@ -410,28 +410,67 @@ class AnthropicProvider(Provider):
base_url: str = "https://api.anthropic.com/v1"
def list_llm_models(self) -> List[LLMConfig]:
- from letta.llm_api.anthropic import anthropic_get_model_list
+ from letta.llm_api.anthropic import MODEL_LIST, anthropic_get_model_list
models = anthropic_get_model_list(self.base_url, api_key=self.api_key)
+ """
+ Example response:
+ {
+ "data": [
+ {
+ "type": "model",
+ "id": "claude-3-5-sonnet-20241022",
+ "display_name": "Claude 3.5 Sonnet (New)",
+ "created_at": "2024-10-22T00:00:00Z"
+ }
+ ],
+ "has_more": true,
+ "first_id": "<string>",
+ "last_id": "<string>"
+ }
+ """
+
configs = []
for model in models:
+ if model["type"] != "model":
+ continue
+
+ if "id" not in model:
+ continue
+
+ # Don't support 2.0 and 2.1
+ if model["id"].startswith("claude-2"):
+ continue
+
+ # Anthropic doesn't return the context window in their API
+ if "context_window" not in model:
+ # Remap list to name: context_window
+ model_library = {m["name"]: m["context_window"] for m in MODEL_LIST}
+ # Attempt to look it up in a hardcoded list
+ if model["id"] in model_library:
+ model["context_window"] = model_library[model["id"]]
+ else:
+ # On fallback, we can set 200k (generally safe), but we should warn the user
+ warnings.warn(f"Couldn't find context window size for model {model['id']}, defaulting to 200,000")
+ model["context_window"] = 200000
+
# We set this to false by default, because Anthropic can
# natively support <thinking> tags inside of content fields
# However, putting COT inside of tool calls can make it more
# reliable for tool calling (no chance of a non-tool call step)
# Since tool_choice_type 'any' doesn't work with in-content COT
# NOTE For Haiku, it can be flaky if we don't enable this by default
- inner_thoughts_in_kwargs = True if "haiku" in model["name"] else False
+ inner_thoughts_in_kwargs = True if "haiku" in model["id"] else False
configs.append(
LLMConfig(
- model=model["name"],
+ model=model["id"],
model_endpoint_type="anthropic",
model_endpoint=self.base_url,
context_window=model["context_window"],
- handle=self.get_handle(model["name"]),
+ handle=self.get_handle(model["id"]),
put_inner_thoughts_in_kwargs=inner_thoughts_in_kwargs,
)
)