Resuming a Group Chat
In GroupChat, we can resume a previous group chat by passing the messages from that conversation to the GroupChatManager’s resume
function (or a_resume
for asynchronous workflows). This prepares the GroupChat, GroupChatManager, and group chat’s agents for resuming. An agent’s initiate_chat
can then be called to resume the chat.
The resume
function returns the last agent in the messages as well as the last message itself. These can be used to run the initiate_chat
.
To resume, the agents, GroupChat, and GroupChatManager objects must exist and match the original group chat.
The messages passed into the resume
function can be passed in as a JSON string or a List[Dict]
of messages, typically from the ChatResult’s chat_history
of the previous conversation or the GroupChat’s messages
property. Use the GroupChatManager’s messages_to_string
function to retrieve a JSON string that can be used for resuming:
An example of the JSON string:
When preparing for resuming, the messages will be validated against the groupchat’s agents to make sure that the messages can be assigned to them. Messages will be allocated to the agents and then the last speaker and message will be returned for use in initiate_chat
.
Continuing a terminated conversation
If the previous group chat terminated and the resuming group chat has the same termination condition (such as if the message contains “TERMINATE”) then the conversation will terminate when resuming as the terminate check occurs with the message passed in to initiate_chat
.
If the termination condition is based on a string within the message, you can pass in that string in the remove_termination_string
parameter of the resume
function and it will be removed. If the termination condition is more complicated, you will need to adjust the messages accordingly before calling resume
.
The resume
function will then check if the last message provided still meets the termination condition and warns you, if so.
Example of resuming a GroupChat
Start with the LLM config. This can differ from the original group chat.
Create the group chat objects, they should have the same name
as the original group chat.
Load the previous messages (from a JSON string or messages List[Dict]
)
Resume the group chat using the last agent and last message.
Example of resuming a terminated GroupChat
This example shows how to resume a group chat that was terminated with a termination string.
The termination string is TERMINATE
Create the group chat objects, they should have the same name
as the original group chat.
Prepare the resumption of the group chat without removing the termination condition. A warning will show. Then attempting to resume the chat will terminate immediately.
The above will terminate immediately as the termination message will trigger the termination.
This time, we will remove the termination message, by using the remove_termination_string
parameter, and then resume.
In the above, you’ll see that the conversation continued, the Chief_Marketing_officer spoke and they will terminate the conversation.
Example of resuming a terminated GroupChat with a new message and agent
Rather than continuing a group chat by using the last message, we can resume a group chat using a new message.
IMPORTANT: To remain in a group chat, use the GroupChatManager to initiate the chat, otherwise you can continue with an agent-to-agent conversation by using another agent to initiate the chat.
We’ll continue with the previous example by using the messages from that conversation and resuming it with a new conversation in the agent ‘meeting’.
We start by preparing the group chat by using the messages from the previous chat.
Let’s continue the meeting with a new topic.