Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: anthropic streaming (#1768)
cthomasec623325da72
diff --git a/letta/schemas/message.py b/letta/schemas/message.pyindex 4eb45f892..bc5b6141a 100644--- a/letta/schemas/message.py+++ b/letta/schemas/message.py@@ -619,7 +619,7 @@ class Message(BaseMessage):text_content = self.content[0].text# Otherwise, check if we have TextContent and multiple other partselif self.content and len(self.content) > 1:- text = [content for content in self.content if isinstance(self.content[0], TextContent)]+ text = [content for content in self.content if isinstance(content, TextContent)]if len(text) > 1:assert len(text) == 1, f"multiple text content parts found in a single message: {self.content}"text_content = text[0].textdiff --git a/letta/server/rest_api/interface.py b/letta/server/rest_api/interface.pyindex 7748b343d..c5508f61b 100644--- a/letta/server/rest_api/interface.py+++ b/letta/server/rest_api/interface.py@@ -6,6 +6,8 @@ from collections import dequefrom datetime import datetimefrom typing import AsyncGenerator, Literal, Optional, Union+import demjson3 as demjson+from letta.constants import DEFAULT_MESSAGE_TOOL, DEFAULT_MESSAGE_TOOL_KWARGfrom letta.helpers.datetime_helpers import is_utc_datetimefrom letta.interface import AgentInterface@@ -530,7 +532,6 @@ class StreamingServerInterface(AgentChunkStreamingInterface):try:# NOTE: this is hardcoded for our DeepSeek API integrationjson_reasoning_content = parse_json(self.expect_reasoning_content_buffer)- print(f"json_reasoning_content: {json_reasoning_content}")processed_chunk = ToolCallMessage(id=message_id,@@ -547,6 +548,10 @@ class StreamingServerInterface(AgentChunkStreamingInterface):except json.JSONDecodeError as e:print(f"Failed to interpret reasoning content ({self.expect_reasoning_content_buffer}) as JSON: {e}")+ return None+ except demjson.JSONDecodeError as e:+ print(f"Failed to interpret reasoning content ({self.expect_reasoning_content_buffer}) as JSON: {e}")+return None# Else,# return None