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: anthropic streaming (#1768)

cthomascd9496288289
diff --git a/letta/schemas/message.py b/letta/schemas/message.py
index 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 parts
elif 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].text
diff --git a/letta/server/rest_api/interface.py b/letta/server/rest_api/interface.py
index 7748b343d..c5508f61b 100644
--- a/letta/server/rest_api/interface.py
+++ b/letta/server/rest_api/interface.py
@@ -6,6 +6,8 @@ from collections import deque
from datetime import datetime
from typing import AsyncGenerator, Literal, Optional, Union
+import demjson3 as demjson
+
from letta.constants import DEFAULT_MESSAGE_TOOL, DEFAULT_MESSAGE_TOOL_KWARG
from letta.helpers.datetime_helpers import is_utc_datetime
from letta.interface import AgentInterface
@@ -530,7 +532,6 @@ class StreamingServerInterface(AgentChunkStreamingInterface):
try:
# NOTE: this is hardcoded for our DeepSeek API integration
json_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