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

def _prepare_chat for groupchat manager to reset the groupchat #1254

Merged
merged 9 commits into from
Jan 18, 2024
8 changes: 4 additions & 4 deletions autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,13 +616,13 @@ async def a_receive(
if reply is not None:
await self.a_send(reply, sender, silent=silent)

def _prepare_chat(self, recipient, clear_history):
def _prepare_chat(self, recipient: "ConversableAgent", clear_history: bool, prepare_recipient: bool = True) -> None:
sonichi marked this conversation as resolved.
Show resolved Hide resolved
self.reset_consecutive_auto_reply_counter(recipient)
recipient.reset_consecutive_auto_reply_counter(self)
self.reply_at_receive[recipient] = recipient.reply_at_receive[self] = True
self.reply_at_receive[recipient] = True
if clear_history:
self.clear_history(recipient)
recipient.clear_history(self)
if prepare_recipient:
recipient._prepare_chat(self, clear_history, False)

def _raise_exception_on_async_reply_functions(self) -> None:
"""Raise an exception if any async reply functions are registered.
Expand Down
10 changes: 10 additions & 0 deletions autogen/agentchat/groupchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,16 @@ def __init__(
ignore_async_in_sync_chat=True,
)

def _prepare_chat(self, recipient: ConversableAgent, clear_history: bool, prepare_recipient: bool = True) -> None:
super()._prepare_chat(recipient, clear_history, prepare_recipient)

if clear_history:
self._groupchat.reset()

for agent in self._groupchat.agents:
if (recipient != agent or prepare_recipient) and isinstance(agent, ConversableAgent):
agent._prepare_chat(self, clear_history, False)

def run_chat(
self,
messages: Optional[List[Dict]] = None,
Expand Down
82 changes: 43 additions & 39 deletions notebook/agentchat_function_call_async.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 1,
"id": "dca301a4",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -119,7 +119,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 2,
"id": "9fb85afb",
"metadata": {},
"outputs": [
Expand All @@ -134,22 +134,14 @@
"--------------------------------------------------------------------------------\n",
"\u001b[33mchatbot\u001b[0m (to user_proxy):\n",
"\n",
"\u001b[32m***** Suggested tool Call (call_mZqUtVEf6hwarnCqdiKtVhAE): timer *****\u001b[0m\n",
"\u001b[32m***** Suggested tool Call (call_fGgH8U261nOnx3JGNJWslhh6): timer *****\u001b[0m\n",
"Arguments: \n",
"{\n",
" \"num_seconds\": \"5\"\n",
"}\n",
"{\"num_seconds\":\"5\"}\n",
"\u001b[32m**********************************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[35m\n",
">>>>>>>> EXECUTING ASYNC FUNCTION timer...\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
">>>>>>>> EXECUTING ASYNC FUNCTION timer...\u001b[0m\n",
"\u001b[33muser_proxy\u001b[0m (to chatbot):\n",
"\n",
"\u001b[33muser_proxy\u001b[0m (to chatbot):\n",
Expand All @@ -161,11 +153,9 @@
"--------------------------------------------------------------------------------\n",
"\u001b[33mchatbot\u001b[0m (to user_proxy):\n",
"\n",
"\u001b[32m***** Suggested tool Call (call_xHz73PpH4ipdv7kTxK2AiVCf): stopwatch *****\u001b[0m\n",
"\u001b[32m***** Suggested tool Call (call_BZs6ynF8gtcZKhONiIRZkECB): stopwatch *****\u001b[0m\n",
"Arguments: \n",
"{\n",
" \"num_seconds\": \"5\"\n",
"}\n",
"{\"num_seconds\":\"5\"}\n",
"\u001b[32m**************************************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
Expand Down Expand Up @@ -195,7 +185,7 @@
"\n",
"coder = autogen.AssistantAgent(\n",
" name=\"chatbot\",\n",
" system_message=\"For coding tasks, only use the functions you have been provided with. Reply TERMINATE when the task is done.\",\n",
" system_message=\"For coding tasks, only use the functions you have been provided with. You have a stopwatch and a timer, these tools can and should be used in parallel. Reply TERMINATE when the task is done.\",\n",
" llm_config=llm_config,\n",
")\n",
"\n",
Expand Down Expand Up @@ -253,7 +243,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 3,
"id": "2472f95c",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -288,7 +278,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 4,
"id": "e2c9267a",
"metadata": {},
"outputs": [
Expand All @@ -299,29 +289,27 @@
"\u001b[33muser_proxy\u001b[0m (to chat_manager):\n",
"\n",
"\n",
"1) Create a timer for 5 seconds.\n",
"2) a stopwatch for 5 seconds.\n",
"3) Pretty print the result as md.\n",
"4) when 1-3 are done, terminate the group chat\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33muser_proxy\u001b[0m (to chat_manager):\n",
"\n",
"\n",
"1) Create a timer and a stopwatch for 5 seconds each in parallel.\n",
"2) Pretty print the result as md.\n",
"3) when 1 and 2 are done, terminate the group chat\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mchatbot\u001b[0m (to chat_manager):\n",
"\n",
"\u001b[32m***** Suggested tool Call (call_rdYofiAgFpRfaZaCT4tzAhOb): timer *****\u001b[0m\n",
"\u001b[32m***** Suggested tool Call (call_zlHKR9LBzCqs1iLId5kvNvJ5): timer *****\u001b[0m\n",
"Arguments: \n",
"{\n",
" \"num_seconds\": \"5\"\n",
"}\n",
"{\"num_seconds\": \"5\"}\n",
"\u001b[32m**********************************************************************\u001b[0m\n",
"\u001b[32m***** Suggested tool Call (call_rH1dgbS9itiJO1Gwnxxhcm35): stopwatch *****\u001b[0m\n",
"Arguments: \n",
"{\"num_seconds\": \"5\"}\n",
"\u001b[32m**************************************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[35m\n",
">>>>>>>> EXECUTING ASYNC FUNCTION timer...\u001b[0m\n",
"\u001b[35m\n",
">>>>>>>> EXECUTING ASYNC FUNCTION stopwatch...\u001b[0m\n",
"\u001b[33muser_proxy\u001b[0m (to chat_manager):\n",
"\n",
"\u001b[33muser_proxy\u001b[0m (to chat_manager):\n",
Expand All @@ -333,17 +321,34 @@
"--------------------------------------------------------------------------------\n",
"\u001b[33muser_proxy\u001b[0m (to chat_manager):\n",
"\n",
"\n",
"\u001b[32m***** Response from calling tool \"stopwatch\" *****\u001b[0m\n",
"Stopwatch is done!\n",
"\u001b[32m**************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33muser_proxy\u001b[0m (to chat_manager):\n",
"\u001b[33mMarkdown_agent\u001b[0m (to chat_manager):\n",
"\n",
"The results of the timer and stopwatch are as follows:\n",
"\n",
"- Timer: Timer is done!\n",
"- Stopwatch: Stopwatch is done!\n",
"\n",
"Now, I will proceed to terminate the group chat.\n",
"\u001b[32m***** Suggested tool Call (call_3Js7oU80vPatnA8IiaKXB5Xu): terminate_group_chat *****\u001b[0m\n",
"Arguments: \n",
"{\"message\":\"The session has concluded, and the group chat will now be terminated.\"}\n",
"\u001b[32m*************************************************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[35m\n",
">>>>>>>> EXECUTING ASYNC FUNCTION terminate_group_chat...\u001b[0m\n",
"\u001b[33muser_proxy\u001b[0m (to chat_manager):\n",
"\n",
"\u001b[33muser_proxy\u001b[0m (to chat_manager):\n",
"\n",
"\u001b[32m***** Response from calling tool \"terminate_group_chat\" *****\u001b[0m\n",
"[GROUPCHAT_TERMINATE] The session has concluded, and the group chat will now be terminated.\n",
"\u001b[32m*************************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n"
]
Expand All @@ -354,10 +359,9 @@
"await user_proxy.a_initiate_chat( # noqa: F704\n",
" manager,\n",
" message=\"\"\"\n",
"1) Create a timer for 5 seconds.\n",
"2) a stopwatch for 5 seconds.\n",
"3) Pretty print the result as md.\n",
"4) when 1-3 are done, terminate the group chat\"\"\",\n",
"1) Create a timer and a stopwatch for 5 seconds each in parallel.\n",
"2) Pretty print the result as md.\n",
"3) when 1 and 2 are done, terminate the group chat\"\"\",\n",
")"
]
},
Expand Down
Loading