From c072c4aee67208ce4b39b3f6ab30139302879dae Mon Sep 17 00:00:00 2001 From: Yiran Wu <32823396+kevin666aa@users.noreply.github.com> Date: Sat, 16 Nov 2024 17:01:31 -0500 Subject: [PATCH] update --- autogen/agentchat/conversable_agent.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/autogen/agentchat/conversable_agent.py b/autogen/agentchat/conversable_agent.py index d2f8763281..840da79204 100644 --- a/autogen/agentchat/conversable_agent.py +++ b/autogen/agentchat/conversable_agent.py @@ -659,6 +659,9 @@ def _append_oai_message(self, message: Union[Dict, str], role, conversation_id: if message.get("role") in ["function", "tool"]: oai_message["role"] = message.get("role") + if "tool_responses" in oai_message: + for tool_response in oai_message["tool_responses"]: + tool_response["content"] = str(tool_response["content"]) elif "override_role" in message: # If we have a direction to override the role then set the # role accordingly. Used to customise the role for the @@ -791,15 +794,16 @@ async def a_send( "Message can't be converted into a valid ChatCompletion message. Either content or function_call must be provided." ) - def _print_received_message(self, message: Union[Dict, str], sender: Agent): + def _print_received_message(self, message: Union[Dict, str], sender: Agent, skip_head: bool = False): iostream = IOStream.get_default() # print the message received - iostream.print(colored(sender.name, "yellow"), "(to", f"{self.name}):\n", flush=True) + if not skip_head: + iostream.print(colored(sender.name, "yellow"), "(to", f"{self.name}):\n", flush=True) message = self._message_to_dict(message) if message.get("tool_responses"): # Handle tool multi-call responses for tool_response in message["tool_responses"]: - self._print_received_message(tool_response, sender) + self._print_received_message(tool_response, sender, skip_head=True) if message.get("role") == "tool": return # If role is tool, then content is just a concatenation of all tool_responses @@ -2288,7 +2292,7 @@ def _format_json_str(jstr): result.append(char) return "".join(result) - def execute_function(self, func_call, verbose: bool = False) -> Tuple[bool, Dict[str, str]]: + def execute_function(self, func_call, verbose: bool = False) -> Tuple[bool, Dict[str, Any]]: """Execute a function call and return the result. Override this function to modify the way to execute function and tool calls. @@ -2342,7 +2346,7 @@ def execute_function(self, func_call, verbose: bool = False) -> Tuple[bool, Dict return is_exec_success, { "name": func_name, "role": "function", - "content": str(content), + "content": content, } async def a_execute_function(self, func_call): @@ -2397,7 +2401,7 @@ async def a_execute_function(self, func_call): return is_exec_success, { "name": func_name, "role": "function", - "content": str(content), + "content": content, } def generate_init_message(self, message: Union[Dict, str, None], **kwargs) -> Union[str, Dict]: