mirror of
https://github.com/microsoft/autogen.git
synced 2025-11-12 08:04:11 +00:00
def _prepare_chat for groupchat manager to reset the groupchat (#1254)
* def _prepare_chat for groupchat manager to reset the groupchat * typo Co-authored-by: Chi Wang <wang.chi@microsoft.com> * typehint and simplify --------- Co-authored-by: Chi Wang <wang.chi@microsoft.com>
This commit is contained in:
parent
260e0cfa53
commit
73c75226b6
@ -616,13 +616,13 @@ class ConversableAgent(Agent):
|
|||||||
if reply is not None:
|
if reply is not None:
|
||||||
await self.a_send(reply, sender, silent=silent)
|
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:
|
||||||
self.reset_consecutive_auto_reply_counter(recipient)
|
self.reset_consecutive_auto_reply_counter(recipient)
|
||||||
recipient.reset_consecutive_auto_reply_counter(self)
|
self.reply_at_receive[recipient] = True
|
||||||
self.reply_at_receive[recipient] = recipient.reply_at_receive[self] = True
|
|
||||||
if clear_history:
|
if clear_history:
|
||||||
self.clear_history(recipient)
|
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:
|
def _raise_exception_on_async_reply_functions(self) -> None:
|
||||||
"""Raise an exception if any async reply functions are registered.
|
"""Raise an exception if any async reply functions are registered.
|
||||||
|
|||||||
@ -334,6 +334,16 @@ class GroupChatManager(ConversableAgent):
|
|||||||
ignore_async_in_sync_chat=True,
|
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(
|
def run_chat(
|
||||||
self,
|
self,
|
||||||
messages: Optional[List[Dict]] = None,
|
messages: Optional[List[Dict]] = None,
|
||||||
|
|||||||
@ -61,7 +61,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 5,
|
"execution_count": 1,
|
||||||
"id": "dca301a4",
|
"id": "dca301a4",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@ -119,7 +119,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 6,
|
"execution_count": 2,
|
||||||
"id": "9fb85afb",
|
"id": "9fb85afb",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@ -134,22 +134,14 @@
|
|||||||
"--------------------------------------------------------------------------------\n",
|
"--------------------------------------------------------------------------------\n",
|
||||||
"\u001b[33mchatbot\u001b[0m (to user_proxy):\n",
|
"\u001b[33mchatbot\u001b[0m (to user_proxy):\n",
|
||||||
"\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",
|
"Arguments: \n",
|
||||||
"{\n",
|
"{\"num_seconds\":\"5\"}\n",
|
||||||
" \"num_seconds\": \"5\"\n",
|
|
||||||
"}\n",
|
|
||||||
"\u001b[32m**********************************************************************\u001b[0m\n",
|
"\u001b[32m**********************************************************************\u001b[0m\n",
|
||||||
"\n",
|
"\n",
|
||||||
"--------------------------------------------------------------------------------\n",
|
"--------------------------------------------------------------------------------\n",
|
||||||
"\u001b[35m\n",
|
"\u001b[35m\n",
|
||||||
">>>>>>>> EXECUTING ASYNC FUNCTION timer...\u001b[0m\n"
|
">>>>>>>> EXECUTING ASYNC FUNCTION timer...\u001b[0m\n",
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"\u001b[33muser_proxy\u001b[0m (to chatbot):\n",
|
"\u001b[33muser_proxy\u001b[0m (to chatbot):\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\u001b[33muser_proxy\u001b[0m (to chatbot):\n",
|
"\u001b[33muser_proxy\u001b[0m (to chatbot):\n",
|
||||||
@ -161,11 +153,9 @@
|
|||||||
"--------------------------------------------------------------------------------\n",
|
"--------------------------------------------------------------------------------\n",
|
||||||
"\u001b[33mchatbot\u001b[0m (to user_proxy):\n",
|
"\u001b[33mchatbot\u001b[0m (to user_proxy):\n",
|
||||||
"\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",
|
"Arguments: \n",
|
||||||
"{\n",
|
"{\"num_seconds\":\"5\"}\n",
|
||||||
" \"num_seconds\": \"5\"\n",
|
|
||||||
"}\n",
|
|
||||||
"\u001b[32m**************************************************************************\u001b[0m\n",
|
"\u001b[32m**************************************************************************\u001b[0m\n",
|
||||||
"\n",
|
"\n",
|
||||||
"--------------------------------------------------------------------------------\n",
|
"--------------------------------------------------------------------------------\n",
|
||||||
@ -195,7 +185,7 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"coder = autogen.AssistantAgent(\n",
|
"coder = autogen.AssistantAgent(\n",
|
||||||
" name=\"chatbot\",\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",
|
" llm_config=llm_config,\n",
|
||||||
")\n",
|
")\n",
|
||||||
"\n",
|
"\n",
|
||||||
@ -253,7 +243,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 7,
|
"execution_count": 3,
|
||||||
"id": "2472f95c",
|
"id": "2472f95c",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@ -288,7 +278,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 8,
|
"execution_count": 4,
|
||||||
"id": "e2c9267a",
|
"id": "e2c9267a",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@ -299,29 +289,27 @@
|
|||||||
"\u001b[33muser_proxy\u001b[0m (to chat_manager):\n",
|
"\u001b[33muser_proxy\u001b[0m (to chat_manager):\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"1) Create a timer for 5 seconds.\n",
|
"1) Create a timer and a stopwatch for 5 seconds each in parallel.\n",
|
||||||
"2) a stopwatch for 5 seconds.\n",
|
"2) Pretty print the result as md.\n",
|
||||||
"3) Pretty print the result as md.\n",
|
"3) when 1 and 2 are done, terminate the group chat\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",
|
|
||||||
"\n",
|
"\n",
|
||||||
"--------------------------------------------------------------------------------\n",
|
"--------------------------------------------------------------------------------\n",
|
||||||
"\u001b[33mchatbot\u001b[0m (to chat_manager):\n",
|
"\u001b[33mchatbot\u001b[0m (to chat_manager):\n",
|
||||||
"\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",
|
"Arguments: \n",
|
||||||
"{\n",
|
"{\"num_seconds\": \"5\"}\n",
|
||||||
" \"num_seconds\": \"5\"\n",
|
|
||||||
"}\n",
|
|
||||||
"\u001b[32m**********************************************************************\u001b[0m\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",
|
||||||
"--------------------------------------------------------------------------------\n",
|
"--------------------------------------------------------------------------------\n",
|
||||||
"\u001b[35m\n",
|
"\u001b[35m\n",
|
||||||
">>>>>>>> EXECUTING ASYNC FUNCTION timer...\u001b[0m\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",
|
"\u001b[33muser_proxy\u001b[0m (to chat_manager):\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\u001b[33muser_proxy\u001b[0m (to chat_manager):\n",
|
"\u001b[33muser_proxy\u001b[0m (to chat_manager):\n",
|
||||||
@ -333,17 +321,34 @@
|
|||||||
"--------------------------------------------------------------------------------\n",
|
"--------------------------------------------------------------------------------\n",
|
||||||
"\u001b[33muser_proxy\u001b[0m (to chat_manager):\n",
|
"\u001b[33muser_proxy\u001b[0m (to chat_manager):\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\u001b[32m***** Response from calling tool \"stopwatch\" *****\u001b[0m\n",
|
||||||
|
"Stopwatch is done!\n",
|
||||||
|
"\u001b[32m**************************************************\u001b[0m\n",
|
||||||
"\n",
|
"\n",
|
||||||
"--------------------------------------------------------------------------------\n",
|
"--------------------------------------------------------------------------------\n",
|
||||||
"\u001b[33muser_proxy\u001b[0m (to chat_manager):\n",
|
"\u001b[33mMarkdown_agent\u001b[0m (to chat_manager):\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"The results of the timer and stopwatch are as follows:\n",
|
||||||
"\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",
|
||||||
"--------------------------------------------------------------------------------\n",
|
"--------------------------------------------------------------------------------\n",
|
||||||
|
"\u001b[35m\n",
|
||||||
|
">>>>>>>> EXECUTING ASYNC FUNCTION terminate_group_chat...\u001b[0m\n",
|
||||||
"\u001b[33muser_proxy\u001b[0m (to chat_manager):\n",
|
"\u001b[33muser_proxy\u001b[0m (to chat_manager):\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"\u001b[33muser_proxy\u001b[0m (to chat_manager):\n",
|
||||||
"\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",
|
||||||
"--------------------------------------------------------------------------------\n"
|
"--------------------------------------------------------------------------------\n"
|
||||||
]
|
]
|
||||||
@ -354,10 +359,9 @@
|
|||||||
"await user_proxy.a_initiate_chat( # noqa: F704\n",
|
"await user_proxy.a_initiate_chat( # noqa: F704\n",
|
||||||
" manager,\n",
|
" manager,\n",
|
||||||
" message=\"\"\"\n",
|
" message=\"\"\"\n",
|
||||||
"1) Create a timer for 5 seconds.\n",
|
"1) Create a timer and a stopwatch for 5 seconds each in parallel.\n",
|
||||||
"2) a stopwatch for 5 seconds.\n",
|
"2) Pretty print the result as md.\n",
|
||||||
"3) Pretty print the result as md.\n",
|
"3) when 1 and 2 are done, terminate the group chat\"\"\",\n",
|
||||||
"4) when 1-3 are done, terminate the group chat\"\"\",\n",
|
|
||||||
")"
|
")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user