Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: add temp hack to gracefully handle parallel tool calling (#2654)
cthomasaa564fc84736
diff --git a/letta/agents/letta_agent.py b/letta/agents/letta_agent.pyindex 348ed6695..59acf6545 100644--- a/letta/agents/letta_agent.py+++ b/letta/agents/letta_agent.py@@ -821,6 +821,9 @@ class LettaAgent(BaseAgent):"""tool_call_name = tool_call.function.nametool_call_args_str = tool_call.function.arguments+ # Temp hack to gracefully handle parallel tool calling attempt, only take first one+ if "}{" in tool_call_args_str:+ tool_call_args_str = tool_call_args_str.split("}{", 1)[0] + "}"try:tool_args = json.loads(tool_call_args_str)diff --git a/letta/interfaces/anthropic_streaming_interface.py b/letta/interfaces/anthropic_streaming_interface.pyindex 4e643afb5..16622093a 100644--- a/letta/interfaces/anthropic_streaming_interface.py+++ b/letta/interfaces/anthropic_streaming_interface.py@@ -379,7 +379,7 @@ class AnthropicStreamingInterface:group: List[Union[ReasoningMessage, HiddenReasoningMessage]], group_type: str) -> Union[TextContent, ReasoningContent, RedactedReasoningContent]:if group_type == "reasoning":- reasoning_text = "".join(chunk.reasoning for chunk in group)+ reasoning_text = "".join(chunk.reasoning for chunk in group).strip()is_native = any(chunk.source == "reasoner_model" for chunk in group)signature = next((chunk.signature for chunk in group if chunk.signature is not None), None)if is_native:diff --git a/letta/interfaces/openai_streaming_interface.py b/letta/interfaces/openai_streaming_interface.pyindex b392a2941..33ac60514 100644--- a/letta/interfaces/openai_streaming_interface.py+++ b/letta/interfaces/openai_streaming_interface.py@@ -32,6 +32,7 @@ class OpenAIStreamingInterface:self.function_args_buffer = Noneself.function_id_buffer = Noneself.last_flushed_function_name = None+ self.last_flushed_function_id = None# Buffer to hold function arguments until inner thoughts are completeself.current_function_arguments = ""@@ -53,14 +54,14 @@ class OpenAIStreamingInterface:self.reasoning_messages = []def get_reasoning_content(self) -> List[TextContent]:- content = "".join(self.reasoning_messages)+ content = "".join(self.reasoning_messages).strip()return [TextContent(text=content)]def get_tool_call_object(self) -> ToolCall:"""Useful for agent loop"""function_name = self.last_flushed_function_name if self.last_flushed_function_name else self.function_name_bufferreturn ToolCall(- id=self.letta_message_id,+ id=self.last_flushed_function_id,function=FunctionCall(arguments=self.current_function_arguments, name=function_name),)@@ -184,6 +185,8 @@ class OpenAIStreamingInterface:# Record what the last function name we flushed wasself.last_flushed_function_name = self.function_name_buffer+ if self.last_flushed_function_id is None:+ self.last_flushed_function_id = self.function_id_buffer# Clear the bufferself.function_name_buffer = Noneself.function_id_buffer = None