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.

fix: disable reasoning toggle when agent type is letta agent v1 [PRO-1346] (#4946)

Charles Packer81bf13271288
diff --git a/letta/llm_api/anthropic_client.py b/letta/llm_api/anthropic_client.py
index d01d8da79..6e737aa7a 100644
--- a/letta/llm_api/anthropic_client.py
+++ b/letta/llm_api/anthropic_client.py
@@ -186,7 +186,7 @@ class AnthropicClient(LLMClientBase):
) -> dict:
# TODO: This needs to get cleaned up. The logic here is pretty confusing.
# TODO: I really want to get rid of prefixing, it's a recipe for disaster code maintenance wise
- prefix_fill = True
+ prefix_fill = True if agent_type != AgentType.letta_v1_agent else False
if not self.use_tool_naming:
raise NotImplementedError("Only tool calling supported on Anthropic API requests")
diff --git a/letta/schemas/llm_config.py b/letta/schemas/llm_config.py
index 65f7a462c..12269bd17 100644
--- a/letta/schemas/llm_config.py
+++ b/letta/schemas/llm_config.py
@@ -1,4 +1,4 @@
-from typing import Literal, Optional
+from typing import TYPE_CHECKING, Literal, Optional
from pydantic import BaseModel, ConfigDict, Field, model_validator
@@ -259,7 +259,62 @@ class LLMConfig(BaseModel):
return config.model_endpoint_type == "openai" and config.model.startswith("gpt-5")
@classmethod
- def apply_reasoning_setting_to_config(cls, config: "LLMConfig", reasoning: bool):
+ def apply_reasoning_setting_to_config(cls, config: "LLMConfig", reasoning: bool, agent_type: Optional["AgentType"] = None):
+ """
+ Normalize reasoning-related flags on the config based on the requested
+ "reasoning" setting, model capabilities, and optionally the agent type.
+
+ For AgentType.letta_v1_agent, we enforce stricter semantics:
+ - OpenAI native reasoning (o1/o3/o4/gpt-5): force enabled (non-togglable)
+ - Anthropic (claude 3.7 / 4): toggle honored (default on elsewhere)
+ - Google Gemini (2.5 family): force disabled until native reasoning supported
+ - All others: disabled (no simulated reasoning via kwargs)
+ """
+ # Late import to avoid circular import with Agent schema using LLMConfig
+ if TYPE_CHECKING:
+ from letta.schemas.enums import AgentType # pragma: no cover
+ else:
+ try:
+ from letta.schemas.enums import AgentType # type: ignore
+ except Exception:
+ AgentType = None # type: ignore
+
+ # V1 agent policy: do not allow simulated reasoning for non-native models
+ if agent_type is not None and AgentType is not None and agent_type == AgentType.letta_v1_agent: # type: ignore
+ # OpenAI native reasoning models: always on
+ if cls.is_openai_reasoning_model(config):
+ config.put_inner_thoughts_in_kwargs = False
+ config.enable_reasoner = True
+ if config.reasoning_effort is None:
+ if config.model.startswith("gpt-5"):
+ config.reasoning_effort = "minimal"
+ else:
+ config.reasoning_effort = "medium"
+ if config.model.startswith("gpt-5") and config.verbosity is None:
+ config.verbosity = "medium"
+ return config
+
+ # Anthropic 3.7/4: toggle honored
+ if cls.is_anthropic_reasoning_model(config):
+ config.enable_reasoner = bool(reasoning)
+ config.put_inner_thoughts_in_kwargs = False
+ if config.enable_reasoner and config.max_reasoning_tokens == 0:
+ config.max_reasoning_tokens = 1024
+ return config
+
+ # Gemini (Vertex or Google AI): force disabled for v1 until native support
+ if cls.is_google_vertex_reasoning_model(config) or cls.is_google_ai_reasoning_model(config):
+ config.put_inner_thoughts_in_kwargs = False
+ config.enable_reasoner = False
+ config.max_reasoning_tokens = 0
+ return config
+
+ # Everything else: disabled (no inner_thoughts-in-kwargs simulation)
+ config.put_inner_thoughts_in_kwargs = False
+ config.enable_reasoner = False
+ config.max_reasoning_tokens = 0
+ return config
+
if not reasoning:
if cls.is_openai_reasoning_model(config):
logger.warning("Reasoning cannot be disabled for OpenAI o1/o3/gpt-5 models")
diff --git a/letta/services/agent_manager.py b/letta/services/agent_manager.py
index ead5199e9..f852e5f6c 100644
--- a/letta/services/agent_manager.py
+++ b/letta/services/agent_manager.py
@@ -315,7 +315,20 @@ class AgentManager:
raise ValueError("llm_config and embedding_config are required")
if agent_create.reasoning is not None:
- agent_create.llm_config = LLMConfig.apply_reasoning_setting_to_config(agent_create.llm_config, agent_create.reasoning)
+ agent_create.llm_config = LLMConfig.apply_reasoning_setting_to_config(
+ agent_create.llm_config,
+ agent_create.reasoning,
+ agent_create.agent_type,
+ )
+ # For v1 agents, enforce sane defaults even when reasoning is omitted
+ elif agent_create.agent_type == AgentType.letta_v1_agent:
+ # Default togglable models (Anthropic 3.7/4) to enabled; others disabled
+ default_reasoning = LLMConfig.is_anthropic_reasoning_model(agent_create.llm_config)
+ agent_create.llm_config = LLMConfig.apply_reasoning_setting_to_config(
+ agent_create.llm_config,
+ default_reasoning,
+ agent_create.agent_type,
+ )
# blocks
block_ids = list(agent_create.block_ids or [])
@@ -642,7 +655,11 @@ class AgentManager:
if agent_update.reasoning is not None:
llm_config = agent_update.llm_config or agent.llm_config
- agent_update.llm_config = LLMConfig.apply_reasoning_setting_to_config(llm_config, agent_update.reasoning)
+ agent_update.llm_config = LLMConfig.apply_reasoning_setting_to_config(
+ llm_config,
+ agent_update.reasoning,
+ agent.agent_type,
+ )
scalar_updates = {
"name": agent_update.name,
diff --git a/tests/test_providers.py b/tests/test_providers.py
index b8ac3d015..a990ff6b9 100644
--- a/tests/test_providers.py
+++ b/tests/test_providers.py
@@ -2,6 +2,7 @@ from typing import Literal, Optional
import pytest
+from letta.schemas.enums import AgentType
from letta.schemas.llm_config import LLMConfig
from letta.schemas.providers import (
AnthropicProvider,
@@ -356,7 +357,7 @@ def test_reasoning_toggle_by_provider(
handle=handle,
context_window=1024,
)
- new_config = LLMConfig.apply_reasoning_setting_to_config(config, reasoning=reasoning)
+ new_config = LLMConfig.apply_reasoning_setting_to_config(config, reasoning=reasoning, agent_type=AgentType.memgpt_v2_agent)
assert new_config.enable_reasoner == expected_enable_reasoner
assert new_config.put_inner_thoughts_in_kwargs == expected_put_inner_thoughts_in_kwargs