diff --git a/autogen/agentchat/groupchat.py b/autogen/agentchat/groupchat.py index 03251eccfb7..1e6a636c8ec 100644 --- a/autogen/agentchat/groupchat.py +++ b/autogen/agentchat/groupchat.py @@ -170,7 +170,7 @@ def _prepare_and_select_agents(self, last_speaker: Agent) -> Tuple[Optional[Agen return agents[0], agents elif not agents: raise ValueError( - f"No agent can execute the function {self.messages[-1]['name']}. " + f"No agent can execute the function {self.messages[-1]['function_call']['name']}. " "Please check the function_map of the agents." ) # remove the last speaker from the list to avoid selecting the same speaker if allow_repeat_speaker is False diff --git a/test/agentchat/test_function_call_groupchat.py b/test/agentchat/test_function_call_groupchat.py index 02fe14a3eee..7b5266195f7 100644 --- a/test/agentchat/test_function_call_groupchat.py +++ b/test/agentchat/test_function_call_groupchat.py @@ -71,5 +71,33 @@ def get_random_number(): user_proxy.initiate_chat(manager, message="Let's start the game!") +def test_no_function_map(): + dummy1 = autogen.UserProxyAgent( + name="User_proxy", + system_message="A human admin that will execute function_calls.", + human_input_mode="NEVER", + ) + + dummy2 = autogen.UserProxyAgent( + name="User_proxy", + system_message="A human admin that will execute function_calls.", + human_input_mode="NEVER", + ) + groupchat = autogen.GroupChat(agents=[dummy1, dummy2], messages=[], max_round=7) + groupchat.messages = [ + { + "role": "assistant", + "content": None, + "function_call": {"name": "get_random_number", "arguments": "{}"}, + } + ] + with pytest.raises( + ValueError, + match="No agent can execute the function get_random_number. Please check the function_map of the agents.", + ): + groupchat._prepare_and_select_agents(dummy2) + + if __name__ == "__main__": test_function_call_groupchat() + test_no_function_map()