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.

chore: Add Opus 4.6 with 1M context window [OPUS-46] (#9301)

Devansh Jain644f7b9d5d79
diff --git a/letta/llm_api/anthropic_client.py b/letta/llm_api/anthropic_client.py
index 54a743ea0..13851639d 100644
--- a/letta/llm_api/anthropic_client.py
+++ b/letta/llm_api/anthropic_client.py
@@ -71,7 +71,7 @@ class AnthropicClient(LLMClientBase):
else:
betas.append("interleaved-thinking-2025-05-14")
- # 1M context beta for Sonnet 4/4.5 when enabled
+ # 1M context beta for Sonnet 4/4.5 or Opus 4.6 when enabled
try:
from letta.settings import model_settings
@@ -79,6 +79,8 @@ class AnthropicClient(LLMClientBase):
llm_config.model.startswith("claude-sonnet-4") or llm_config.model.startswith("claude-sonnet-4-5")
):
betas.append("context-1m-2025-08-07")
+ elif model_settings.anthropic_opus_1m and llm_config.model.startswith("claude-opus-4-6"):
+ betas.append("context-1m-2025-08-07")
except Exception:
pass
@@ -118,7 +120,7 @@ class AnthropicClient(LLMClientBase):
else:
betas.append("interleaved-thinking-2025-05-14")
- # 1M context beta for Sonnet 4/4.5 when enabled
+ # 1M context beta for Sonnet 4/4.5 or Opus 4.6 when enabled
try:
from letta.settings import model_settings
@@ -126,6 +128,8 @@ class AnthropicClient(LLMClientBase):
llm_config.model.startswith("claude-sonnet-4") or llm_config.model.startswith("claude-sonnet-4-5")
):
betas.append("context-1m-2025-08-07")
+ elif model_settings.anthropic_opus_1m and llm_config.model.startswith("claude-opus-4-6"):
+ betas.append("context-1m-2025-08-07")
except Exception:
pass
@@ -291,7 +295,7 @@ class AnthropicClient(LLMClientBase):
else:
betas.append("interleaved-thinking-2025-05-14")
- # 1M context beta for Sonnet 4/4.5 when enabled
+ # 1M context beta for Sonnet 4/4.5 or Opus 4.6 when enabled
try:
from letta.settings import model_settings
@@ -299,6 +303,8 @@ class AnthropicClient(LLMClientBase):
llm_config.model.startswith("claude-sonnet-4") or llm_config.model.startswith("claude-sonnet-4-5")
):
betas.append("context-1m-2025-08-07")
+ elif model_settings.anthropic_opus_1m and llm_config.model.startswith("claude-opus-4-6"):
+ betas.append("context-1m-2025-08-07")
except Exception:
pass
@@ -849,6 +855,8 @@ class AnthropicClient(LLMClientBase):
and (model.startswith("claude-sonnet-4") or model.startswith("claude-sonnet-4-5"))
):
betas.append("context-1m-2025-08-07")
+ elif model and model_settings.anthropic_opus_1m and model.startswith("claude-opus-4-6"):
+ betas.append("context-1m-2025-08-07")
except Exception:
pass
diff --git a/letta/schemas/providers/anthropic.py b/letta/schemas/providers/anthropic.py
index fbb7a2c3e..9c18feb82 100644
--- a/letta/schemas/providers/anthropic.py
+++ b/letta/schemas/providers/anthropic.py
@@ -201,7 +201,7 @@ class AnthropicProvider(Provider):
logger.warning(f"Couldn't find context window size for model {model['id']}, defaulting to 200,000")
model["context_window"] = 200000
- # Optional override: enable 1M context for Sonnet 4/4.5 when flag is set
+ # Optional override: enable 1M context for Sonnet 4/4.5 or Opus 4.6 when flag is set
try:
from letta.settings import model_settings
@@ -209,6 +209,8 @@ class AnthropicProvider(Provider):
model["id"].startswith("claude-sonnet-4") or model["id"].startswith("claude-sonnet-4-5")
):
model["context_window"] = 1_000_000
+ elif model_settings.anthropic_opus_1m and model["id"].startswith("claude-opus-4-6"):
+ model["context_window"] = 1_000_000
except Exception:
pass
diff --git a/letta/settings.py b/letta/settings.py
index 486330978..05b87bce6 100644
--- a/letta/settings.py
+++ b/letta/settings.py
@@ -177,6 +177,16 @@ class ModelSettings(BaseSettings):
),
alias="ANTHROPIC_SONNET_1M",
)
+ anthropic_opus_1m: bool = Field(
+ default=False,
+ description=(
+ "Enable 1M-token context window for Claude Opus 4.6. When true, adds the"
+ " 'context-1m-2025-08-07' beta to Anthropic requests and sets model context_window"
+ " to 1,000,000 instead of 200,000. Note: This feature is in beta and not available"
+ " to all orgs; once GA, this flag can be removed and behavior can default to on."
+ ),
+ alias="ANTHROPIC_OPUS_1M",
+ )
# ollama
ollama_base_url: Optional[str] = None