Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: pass thinking to anthropic client (#4150)
Kevin Lin80ea4a0608fd
diff --git a/letta/llm_api/anthropic_client.py b/letta/llm_api/anthropic_client.pyindex b2e90889f..ef54ff62a 100644--- a/letta/llm_api/anthropic_client.py+++ b/letta/llm_api/anthropic_client.py@@ -287,12 +287,26 @@ class AnthropicClient(LLMClientBase):else:anthropic_tools = None+ thinking_enabled = False+ if messages:+ for message in messages:+ if isinstance(message.get("content"), list):+ for content_block in message["content"]:+ if content_block.get("type") == "thinking":+ thinking_enabled = True+ break+try:- result = await client.beta.messages.count_tokens(- model=model or "claude-3-7-sonnet-20250219",- messages=messages or [{"role": "user", "content": "hi"}],- tools=anthropic_tools or [],- )+ count_params = {+ "model": model or "claude-3-7-sonnet-20250219",+ "messages": messages or [{"role": "user", "content": "hi"}],+ "tools": anthropic_tools or [],+ }++ if thinking_enabled:+ count_params["thinking"] = {"type": "enabled", "budget_tokens": 16000}++ result = await client.beta.messages.count_tokens(**count_params)except:raisediff --git a/letta/schemas/message.py b/letta/schemas/message.pyindex 4fd0a8eaa..5376cd5f7 100644--- a/letta/schemas/message.py+++ b/letta/schemas/message.py@@ -846,7 +846,7 @@ class Message(BaseMessage):}content = []# COT / reasoning / thinking- if self.content is not None and len(self.content) > 1:+ if self.content is not None and len(self.content) >= 1:for content_part in self.content:if isinstance(content_part, ReasoningContent):content.append(