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(core): ensure buffered Anthropic tool chunks always include otid (#9516)

jnjpnga59f24ac8766
diff --git a/letta/interfaces/anthropic_streaming_interface.py b/letta/interfaces/anthropic_streaming_interface.py
index 8dfd872f0..dcb8d4e70 100644
--- a/letta/interfaces/anthropic_streaming_interface.py
+++ b/letta/interfaces/anthropic_streaming_interface.py
@@ -593,9 +593,15 @@ class AnthropicStreamingInterface:
pass
elif isinstance(event, BetaRawContentBlockStopEvent):
# If we're exiting a tool use block and there are still buffered messages,
- # we should flush them now
+ # we should flush them now.
+ # Ensure each flushed chunk has an otid before yielding.
if self.anthropic_mode == EventMode.TOOL_USE and self.tool_call_buffer:
for buffered_msg in self.tool_call_buffer:
+ if not buffered_msg.otid:
+ if prev_message_type and prev_message_type != buffered_msg.message_type:
+ message_index += 1
+ buffered_msg.otid = Message.generate_otid_from_id(buffered_msg.id, message_index)
+ prev_message_type = buffered_msg.message_type
yield buffered_msg
self.tool_call_buffer = []