Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP! add a silent option to GroupChatManager to reduce noise on the command line #2212

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions autogen/agentchat/groupchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def custom_speaker_selection_func(
speaker_transitions_type: Literal["allowed", "disallowed", None] = None
enable_clear_history: Optional[bool] = False
send_introductions: bool = False
silent: bool = False
Copy link
Collaborator

@WaelKarkoub WaelKarkoub Apr 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argument is not used in this class


_VALID_SPEAKER_SELECTION_METHODS = ["auto", "manual", "random", "round_robin"]
_VALID_SPEAKER_TRANSITIONS_TYPE = ["allowed", "disallowed", None]
Expand Down Expand Up @@ -516,6 +517,7 @@ def __init__(
max_consecutive_auto_reply: Optional[int] = sys.maxsize,
human_input_mode: Optional[str] = "NEVER",
system_message: Optional[Union[str, List]] = "Group chat manager.",
silent: Optional[bool] = False,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to add an object variable self._silent = silent in the init for it to be useable in the rest of the class

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
silent: Optional[bool] = False,
silent: bool = False,

**kwargs,
):
if (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (
self._silent = silent
if (

Expand Down Expand Up @@ -596,7 +598,7 @@ def run_chat(
# Broadcast the intro
intro = groupchat.introductions_msg()
for agent in groupchat.agents:
self.send(intro, agent, request_reply=False, silent=True)
self.send(intro, agent, request_reply=False, silent=self.silent)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.send(intro, agent, request_reply=False, silent=self.silent)
self.send(intro, agent, request_reply=False, silent=self._silent)

# NOTE: We do not also append to groupchat.messages,
# since groupchat handles its own introductions

Expand All @@ -609,7 +611,7 @@ def run_chat(
# 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)
self.send(message, agent, request_reply=False)
if self._is_termination_msg(message) or i == groupchat.max_round - 1:
# The conversation is over or it's the last round
break
Expand Down Expand Up @@ -671,7 +673,7 @@ async def a_run_chat(
# Broadcast the intro
intro = groupchat.introductions_msg()
for agent in groupchat.agents:
await self.a_send(intro, agent, request_reply=False, silent=True)
await self.a_send(intro, agent, request_reply=False, silent=self.silent)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await self.a_send(intro, agent, request_reply=False, silent=self.silent)
await self.a_send(intro, agent, request_reply=False, silent=self._silent)

# NOTE: We do not also append to groupchat.messages,
# since groupchat handles its own introductions

Expand All @@ -689,7 +691,7 @@ async def a_run_chat(
# broadcast the message to all agents except the speaker
for agent in groupchat.agents:
if agent != speaker:
await self.a_send(message, agent, request_reply=False, silent=True)
await self.a_send(message, agent, request_reply=False, silent=self.silent)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await self.a_send(message, agent, request_reply=False, silent=self.silent)
await self.a_send(message, agent, request_reply=False, silent=self._silent)

if i == groupchat.max_round - 1:
# the last round
break
Expand All @@ -710,7 +712,7 @@ async def a_run_chat(
if reply is None:
break
# The speaker sends the message without requesting a reply
await speaker.a_send(reply, self, request_reply=False)
await speaker.a_send(reply, self, request_reply=False, silent=self.silent)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await speaker.a_send(reply, self, request_reply=False, silent=self.silent)
await speaker.a_send(reply, self, request_reply=False, silent=self._silent)

message = self.last_message(speaker)
if self.client_cache is not None:
for a in groupchat.agents:
Expand Down
44 changes: 44 additions & 0 deletions test/agentchat/test_chats.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,49 @@ def test_chat_messages_for_summary():
assert len(messages) == 2


def test_silent_manager():

financial_assistant = AssistantAgent(
name="Financial_assistant",
llm_config={"config_list": config_list},
)

writer = AssistantAgent(
name="Writer",
llm_config={"config_list": config_list},
system_message="""
You are a professional writer, known for
your insightful and engaging articles.
You transform complex concepts into compelling narratives.
Reply "TERMINATE" in the end when everything is done.
""",
)

critic = AssistantAgent(
name="Critic",
system_message="""Critic. Double check plan, claims, code from other agents and provide feedback. Check whether the plan includes adding verifiable info such as source URL.
Reply "TERMINATE" in the end when everything is done.
""",
llm_config={"config_list": config_list},
)

groupchat = GroupChat(agents=[financial_assistant, critic], messages=[], max_round=3)

manager = GroupChatManager(
groupchat=groupchat,
name="Research_manager",
llm_config={"config_list": config_list},
code_execution_config={
"last_n_messages": 1,
"work_dir": "groupchat",
"use_docker": False,
},
is_termination_msg=lambda x: x.get("content", "").find("TERMINATE") >= 0,
silent=False,
)
writer.initiate_chat(manager, message="What is the goal?")


@pytest.mark.skipif(skip_openai, reason="requested to skip openai tests")
def test_chats_group():
financial_tasks = [
Expand Down Expand Up @@ -616,3 +659,4 @@ def my_writing_task(sender, recipient, context):
# test_chats_w_func()
# test_chat_messages_for_summary()
# test_udf_message_in_chats()
test_silent_manager()
Loading