remove useless code in groupchat; simplify the handling of termination msg (#1532)

* remove useless code in groupchat

* include termination msg
This commit is contained in:
Chi Wang 2024-02-04 11:20:18 -08:00 committed by GitHub
parent 1abbcf3c44
commit c6c5fb0ffb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 20 deletions

View File

@ -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

View File

@ -1 +1 @@
__version__ = "0.2.10"
__version__ = "0.2.11"

View File

@ -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