diff --git a/autogen/agentchat/groupchat.py b/autogen/agentchat/groupchat.py index 611cd4795..5dc64e7f8 100644 --- a/autogen/agentchat/groupchat.py +++ b/autogen/agentchat/groupchat.py @@ -366,15 +366,12 @@ class GroupChatManager(ConversableAgent): a.client_cache = self.client_cache for i in range(groupchat.max_round): groupchat.append(message, speaker) - if self._is_termination_msg(message): - # The conversation is over - break # broadcast the message to all agents except the speaker for agent in groupchat.agents: if agent != speaker: self.send(message, agent, request_reply=False, silent=True) - if i == groupchat.max_round - 1: - # the last round + if self._is_termination_msg(message) or i == groupchat.max_round - 1: + # The conversation is over or it's the last round break try: # select the next speaker @@ -391,6 +388,7 @@ class GroupChatManager(ConversableAgent): # admin agent is not found in the participants raise if reply is None: + # no reply is generated, exit the chat break # check for "clear history" phrase in reply and activate clear history function if found @@ -403,8 +401,6 @@ class GroupChatManager(ConversableAgent): # The speaker sends the message without requesting a reply speaker.send(reply, self, request_reply=False) message = self.last_message(speaker) - if i == groupchat.max_round - 1: - groupchat.append(message, speaker) if self.client_cache is not None: for a in groupchat.agents: a.client_cache = a.previous_cache diff --git a/autogen/version.py b/autogen/version.py index 6232f7ab1..5635676f6 100644 --- a/autogen/version.py +++ b/autogen/version.py @@ -1 +1 @@ -__version__ = "0.2.10" +__version__ = "0.2.11" diff --git a/test/agentchat/contrib/test_society_of_mind_agent.py b/test/agentchat/contrib/test_society_of_mind_agent.py index 15b2dcdfb..acee39a16 100644 --- a/test/agentchat/contrib/test_society_of_mind_agent.py +++ b/test/agentchat/contrib/test_society_of_mind_agent.py @@ -63,12 +63,12 @@ def test_society_of_mind_agent(): assert groupchat.messages[3]["name"] == "sam" assert groupchat.messages[3]["content"] == "This is sam speaking. TERMINATE" - assert len(agent1.chat_messages[group_chat_manager]) == 3 # Everything but the termination message - assert len(agent2.chat_messages[group_chat_manager]) == 3 # Everything but the termination message + assert len(agent1.chat_messages[group_chat_manager]) == 4 # Everything *including* the termination message + assert len(agent2.chat_messages[group_chat_manager]) == 4 # Everything *including* the termination message assert len(agent3.chat_messages[group_chat_manager]) == 4 # Everything *including* the termination message - assert len(group_chat_manager.chat_messages[agent1]) == 3 # Everything but the termination message - assert len(group_chat_manager.chat_messages[agent2]) == 3 # Everything but the termination message + assert len(group_chat_manager.chat_messages[agent1]) == 4 # Everything *including* the termination message + assert len(group_chat_manager.chat_messages[agent2]) == 4 # Everything *including* the termination message assert len(group_chat_manager.chat_messages[agent3]) == 4 # Everything *including* the termination message # Let's go again. It should reset the inner monologue, but keep the external monologue @@ -89,21 +89,21 @@ def test_society_of_mind_agent(): assert groupchat.messages[3]["content"] == "This is sam speaking. TERMINATE" assert ( - len(agent1.chat_messages[group_chat_manager]) == 5 - ) # Prior external conversation + everything but the termination message + len(agent1.chat_messages[group_chat_manager]) == 6 + ) # Prior external conversation + everything including the termination message assert ( - len(agent2.chat_messages[group_chat_manager]) == 5 - ) # Prior external conversation + everything but the termination message + len(agent2.chat_messages[group_chat_manager]) == 6 + ) # Prior external conversation + everything including the termination message assert ( len(agent3.chat_messages[group_chat_manager]) == 6 ) # Prior external conversation + everything *including* the termination message assert ( - len(group_chat_manager.chat_messages[agent1]) == 5 - ) # Prior external conversation + everything but the termination message + len(group_chat_manager.chat_messages[agent1]) == 6 + ) # Prior external conversation + everything including the termination message assert ( - len(group_chat_manager.chat_messages[agent2]) == 5 - ) # Prior external conversation + everything but the termination message + len(group_chat_manager.chat_messages[agent2]) == 6 + ) # Prior external conversation + everything including the termination message assert ( len(group_chat_manager.chat_messages[agent3]) == 6 ) # Prior external conversation + everything *including* the termination message