Skip to content

Commit

Permalink
Minor fix groupchat (microsoft#904)
Browse files Browse the repository at this point in the history
* minor fix groupchat

* update

* update

---------

Co-authored-by: Davor Runje <davor@airt.ai>
  • Loading branch information
yiranwu0 and davorrunje authored Jan 3, 2024
1 parent e31a6fa commit a90cd30
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion autogen/agentchat/groupchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions test/agentchat/test_function_call_groupchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit a90cd30

Please sign in to comment.