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: special otid handling for approval request (#5726)

cthomas6b37ef2cb7b5
diff --git a/letta/interfaces/anthropic_parallel_tool_call_streaming_interface.py b/letta/interfaces/anthropic_parallel_tool_call_streaming_interface.py
index 08f83e52a..370f900fc 100644
--- a/letta/interfaces/anthropic_parallel_tool_call_streaming_interface.py
+++ b/letta/interfaces/anthropic_parallel_tool_call_streaming_interface.py
@@ -39,7 +39,7 @@ from letta.schemas.letta_stop_reason import LettaStopReason, StopReasonType
from letta.schemas.message import Message
from letta.schemas.openai.chat_completion_response import FunctionCall, ToolCall
from letta.server.rest_api.json_parser import JSONParser, PydanticJSONParser
-from letta.server.rest_api.utils import increment_message_uuid
+from letta.server.rest_api.utils import decrement_message_uuid
logger = get_logger(__name__)
@@ -284,11 +284,11 @@ class SimpleAnthropicStreamingInterface:
# Initialize arguments from the start event's input (often {}) to avoid undefined in UIs
if name in self.requires_approval_tools:
tool_call_msg = ApprovalRequestMessage(
- id=increment_message_uuid(self.letta_message_id),
+ id=decrement_message_uuid(self.letta_message_id),
# Do not emit placeholder arguments here to avoid UI duplicates
tool_call=ToolCallDelta(name=name, tool_call_id=call_id),
date=datetime.now(timezone.utc).isoformat(),
- otid=Message.generate_otid_from_id(increment_message_uuid(self.letta_message_id), message_index),
+ otid=Message.generate_otid_from_id(decrement_message_uuid(self.letta_message_id), -1),
run_id=self.run_id,
step_id=self.step_id,
)
@@ -381,10 +381,10 @@ class SimpleAnthropicStreamingInterface:
if name in self.requires_approval_tools:
tool_call_msg = ApprovalRequestMessage(
- id=increment_message_uuid(self.letta_message_id),
+ id=decrement_message_uuid(self.letta_message_id),
tool_call=ToolCallDelta(name=name, tool_call_id=call_id, arguments=delta.partial_json),
date=datetime.now(timezone.utc).isoformat(),
- otid=Message.generate_otid_from_id(increment_message_uuid(self.letta_message_id), message_index),
+ otid=Message.generate_otid_from_id(decrement_message_uuid(self.letta_message_id), -1),
run_id=self.run_id,
step_id=self.step_id,
)
diff --git a/letta/schemas/message.py b/letta/schemas/message.py
index 6d4954175..ceb5f43c7 100644
--- a/letta/schemas/message.py
+++ b/letta/schemas/message.py
@@ -1855,6 +1855,9 @@ class Message(BaseMessage):
"""
Convert message id to bits and change the list bit to the index
"""
+ if index == -1:
+ return message_id
+
if not 0 <= index < 128:
raise ValueError("Index must be between 0 and 127")
diff --git a/letta/server/rest_api/utils.py b/letta/server/rest_api/utils.py
index 972dd13cb..57feca10a 100644
--- a/letta/server/rest_api/utils.py
+++ b/letta/server/rest_api/utils.py
@@ -263,17 +263,17 @@ def create_approval_request_message_from_llm_response(
run_id=run_id,
)
if pre_computed_assistant_message_id:
- approval_message.id = increment_message_uuid(pre_computed_assistant_message_id)
+ approval_message.id = decrement_message_uuid(pre_computed_assistant_message_id)
messages.append(approval_message)
return messages
-def increment_message_uuid(message_id: str):
+def decrement_message_uuid(message_id: str):
message_uuid = uuid.UUID(message_id.split("-", maxsplit=1)[1])
uuid_as_int = message_uuid.int
- incremented_int = uuid_as_int + 1
- incremented_uuid = uuid.UUID(int=incremented_int)
- return "message-" + str(incremented_uuid)
+ decremented_int = uuid_as_int - 1
+ decremented_uuid = uuid.UUID(int=decremented_int)
+ return "message-" + str(decremented_uuid)
def create_letta_messages_from_llm_response(