Skip to content

Commit 94974c0

Browse files
authored
remove useless code in groupchat; simplify the handling of termination msg (microsoft#1532)
* remove useless code in groupchat * include termination msg
1 parent 5d16dde commit 94974c0

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

autogen/agentchat/groupchat.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -366,15 +366,12 @@ def run_chat(
366366
a.client_cache = self.client_cache
367367
for i in range(groupchat.max_round):
368368
groupchat.append(message, speaker)
369-
if self._is_termination_msg(message):
370-
# The conversation is over
371-
break
372369
# broadcast the message to all agents except the speaker
373370
for agent in groupchat.agents:
374371
if agent != speaker:
375372
self.send(message, agent, request_reply=False, silent=True)
376-
if i == groupchat.max_round - 1:
377-
# the last round
373+
if self._is_termination_msg(message) or i == groupchat.max_round - 1:
374+
# The conversation is over or it's the last round
378375
break
379376
try:
380377
# select the next speaker
@@ -391,6 +388,7 @@ def run_chat(
391388
# admin agent is not found in the participants
392389
raise
393390
if reply is None:
391+
# no reply is generated, exit the chat
394392
break
395393

396394
# check for "clear history" phrase in reply and activate clear history function if found
@@ -403,8 +401,6 @@ def run_chat(
403401
# The speaker sends the message without requesting a reply
404402
speaker.send(reply, self, request_reply=False)
405403
message = self.last_message(speaker)
406-
if i == groupchat.max_round - 1:
407-
groupchat.append(message, speaker)
408404
if self.client_cache is not None:
409405
for a in groupchat.agents:
410406
a.client_cache = a.previous_cache

autogen/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.2.10"
1+
__version__ = "0.2.11"

test/agentchat/contrib/test_society_of_mind_agent.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ def test_society_of_mind_agent():
6363
assert groupchat.messages[3]["name"] == "sam"
6464
assert groupchat.messages[3]["content"] == "This is sam speaking. TERMINATE"
6565

66-
assert len(agent1.chat_messages[group_chat_manager]) == 3 # Everything but the termination message
67-
assert len(agent2.chat_messages[group_chat_manager]) == 3 # Everything but the termination message
66+
assert len(agent1.chat_messages[group_chat_manager]) == 4 # Everything *including* the termination message
67+
assert len(agent2.chat_messages[group_chat_manager]) == 4 # Everything *including* the termination message
6868
assert len(agent3.chat_messages[group_chat_manager]) == 4 # Everything *including* the termination message
6969

70-
assert len(group_chat_manager.chat_messages[agent1]) == 3 # Everything but the termination message
71-
assert len(group_chat_manager.chat_messages[agent2]) == 3 # Everything but the termination message
70+
assert len(group_chat_manager.chat_messages[agent1]) == 4 # Everything *including* the termination message
71+
assert len(group_chat_manager.chat_messages[agent2]) == 4 # Everything *including* the termination message
7272
assert len(group_chat_manager.chat_messages[agent3]) == 4 # Everything *including* the termination message
7373

7474
# 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():
8989
assert groupchat.messages[3]["content"] == "This is sam speaking. TERMINATE"
9090

9191
assert (
92-
len(agent1.chat_messages[group_chat_manager]) == 5
93-
) # Prior external conversation + everything but the termination message
92+
len(agent1.chat_messages[group_chat_manager]) == 6
93+
) # Prior external conversation + everything including the termination message
9494
assert (
95-
len(agent2.chat_messages[group_chat_manager]) == 5
96-
) # Prior external conversation + everything but the termination message
95+
len(agent2.chat_messages[group_chat_manager]) == 6
96+
) # Prior external conversation + everything including the termination message
9797
assert (
9898
len(agent3.chat_messages[group_chat_manager]) == 6
9999
) # Prior external conversation + everything *including* the termination message
100100

101101
assert (
102-
len(group_chat_manager.chat_messages[agent1]) == 5
103-
) # Prior external conversation + everything but the termination message
102+
len(group_chat_manager.chat_messages[agent1]) == 6
103+
) # Prior external conversation + everything including the termination message
104104
assert (
105-
len(group_chat_manager.chat_messages[agent2]) == 5
106-
) # Prior external conversation + everything but the termination message
105+
len(group_chat_manager.chat_messages[agent2]) == 6
106+
) # Prior external conversation + everything including the termination message
107107
assert (
108108
len(group_chat_manager.chat_messages[agent3]) == 6
109109
) # Prior external conversation + everything *including* the termination message

0 commit comments

Comments
 (0)