feat: latest hitl + parallel tool call changes (#5565)

This commit is contained in:
cthomas
2025-10-18 22:27:51 -07:00
committed by Caren Thomas
parent de0896c547
commit 73dcc0d4b7
12 changed files with 215 additions and 142 deletions

View File

@@ -39,6 +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
logger = get_logger(__name__)
@@ -282,14 +283,12 @@ class SimpleAnthropicStreamingInterface:
call_id = content.id
# Initialize arguments from the start event's input (often {}) to avoid undefined in UIs
if name in self.requires_approval_tools:
if prev_message_type and prev_message_type != "approval_request_message":
message_index += 1
tool_call_msg = ApprovalRequestMessage(
id=self.letta_message_id,
id=increment_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(self.letta_message_id, message_index),
otid=Message.generate_otid_from_id(increment_message_uuid(self.letta_message_id), message_index),
run_id=self.run_id,
step_id=self.step_id,
)
@@ -306,7 +305,7 @@ class SimpleAnthropicStreamingInterface:
run_id=self.run_id,
step_id=self.step_id,
)
prev_message_type = tool_call_msg.message_type
prev_message_type = tool_call_msg.message_type
yield tool_call_msg
elif isinstance(content, BetaThinkingBlock):
@@ -382,13 +381,11 @@ class SimpleAnthropicStreamingInterface:
call_id = ctx.get("id")
if name in self.requires_approval_tools:
if prev_message_type and prev_message_type != "approval_request_message":
message_index += 1
tool_call_msg = ApprovalRequestMessage(
id=self.letta_message_id,
id=increment_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(self.letta_message_id, message_index),
otid=Message.generate_otid_from_id(increment_message_uuid(self.letta_message_id), message_index),
run_id=self.run_id,
step_id=self.step_id,
)
@@ -404,7 +401,7 @@ class SimpleAnthropicStreamingInterface:
run_id=self.run_id,
step_id=self.step_id,
)
prev_message_type = tool_call_msg.message_type
yield tool_call_msg
elif isinstance(delta, BetaThinkingDelta):