From 8be47ab2ff773d19da6d7906480d2b684c6f895d Mon Sep 17 00:00:00 2001 From: Matt Zhou Date: Tue, 1 Oct 2024 14:57:03 -0700 Subject: [PATCH 1/2] Fix bug --- letta/agent.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/letta/agent.py b/letta/agent.py index 3217a52d0d..6ca4e9fbc0 100644 --- a/letta/agent.py +++ b/letta/agent.py @@ -551,18 +551,15 @@ def _handle_ai_response( ) # extend conversation with assistant's reply printd(f"Function call message: {messages[-1]}") - # The content if then internal monologue, not chat - self.interface.internal_monologue(response_message.content, msg_obj=messages[-1]) - # Step 3: call the function # Note: the JSON response may not always be valid; be sure to handle errors - - # Failure case 1: function name is wrong function_call = ( response_message.function_call if response_message.function_call is not None else response_message.tool_calls[0].function ) function_name = function_call.name printd(f"Request to call function {function_name} with tool_call_id: {tool_call_id}") + + # Failure case 1: function name is wrong try: function_to_call = self.functions_python[function_name] except KeyError: @@ -607,6 +604,13 @@ def _handle_ai_response( self.interface.function_message(f"Error: {error_msg}", msg_obj=messages[-1]) return messages, False, True # force a heartbeat to allow agent to handle error + # Community noted that inner thoughts can sometimes appear in the function args + if "inner_thoughts" in function_args: + response_message.content = function_args.pop("inner_thoughts") + if response_message.content: + # The content if then internal monologue, not chat + self.interface.internal_monologue(response_message.content, msg_obj=messages[-1]) + # (Still parsing function args) # Handle requests for immediate heartbeat heartbeat_request = function_args.pop("request_heartbeat", None) From b1edbb3b1ddce09088376e715d711d5ab0134386 Mon Sep 17 00:00:00 2001 From: Matt Zhou Date: Tue, 1 Oct 2024 15:51:08 -0700 Subject: [PATCH 2/2] Fix critiques --- letta/agent.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/letta/agent.py b/letta/agent.py index 6ca4e9fbc0..831e0f4a71 100644 --- a/letta/agent.py +++ b/letta/agent.py @@ -551,6 +551,10 @@ def _handle_ai_response( ) # extend conversation with assistant's reply printd(f"Function call message: {messages[-1]}") + if response_message.content: + # The content if then internal monologue, not chat + self.interface.internal_monologue(response_message.content, msg_obj=messages[-1]) + # Step 3: call the function # Note: the JSON response may not always be valid; be sure to handle errors function_call = ( @@ -604,13 +608,6 @@ def _handle_ai_response( self.interface.function_message(f"Error: {error_msg}", msg_obj=messages[-1]) return messages, False, True # force a heartbeat to allow agent to handle error - # Community noted that inner thoughts can sometimes appear in the function args - if "inner_thoughts" in function_args: - response_message.content = function_args.pop("inner_thoughts") - if response_message.content: - # The content if then internal monologue, not chat - self.interface.internal_monologue(response_message.content, msg_obj=messages[-1]) - # (Still parsing function args) # Handle requests for immediate heartbeat heartbeat_request = function_args.pop("request_heartbeat", None)