diff --git a/autogen/agentchat/conversable_agent.py b/autogen/agentchat/conversable_agent.py index eabe6d6d4606..e19cbd56de2b 100644 --- a/autogen/agentchat/conversable_agent.py +++ b/autogen/agentchat/conversable_agent.py @@ -1658,8 +1658,8 @@ async def a_generate_function_call_reply( if messages is None: messages = self._oai_messages[sender] message = messages[-1] - if "function_call" in message: - func_call = message["function_call"] + func_call = message.get("function_call") + if func_call: func_name = func_call.get("name", "") func = self._function_map.get(func_name, None) if func and inspect.iscoroutinefunction(func): diff --git a/test/agentchat/test_function_and_tool_calling.py b/test/agentchat/test_function_and_tool_calling.py index 4e0775d014c0..97727fe5c321 100644 --- a/test/agentchat/test_function_and_tool_calling.py +++ b/test/agentchat/test_function_and_tool_calling.py @@ -33,6 +33,7 @@ async def _a_tool_func_error(arg1: str, arg2: str) -> str: _tool_use_message_1 = { "role": "assistant", "content": None, + "function_call": None, "tool_calls": [ { "id": "1", @@ -56,6 +57,7 @@ async def _a_tool_func_error(arg1: str, arg2: str) -> str: _tool_use_message_1_bad_json = { "role": "assistant", "content": None, + "function_call": None, "tool_calls": [ { "id": "1",