Initiate a list of chats.
PARAMETER | DESCRIPTION |
chat_queue | A list of dictionaries containing the information about the chats. Each dictionary should contain the input arguments for ConversableAgent.initiate_chat . For example: - "sender" - the sender agent. - "recipient" - the recipient agent. - "clear_history" (bool) - whether to clear the chat history with the agent. Default is True. - "silent" (bool or None) - (Experimental) whether to print the messages in this conversation. Default is False. - "cache" (Cache or None) - the cache client to use for this conversation. Default is None. - "max_turns" (int or None) - maximum number of turns for the chat. If None, the chat will continue until a termination condition is met. Default is None. - "summary_method" (str or callable) - a string or callable specifying the method to get a summary from the chat. Default is DEFAULT_summary_method, i.e., "last_msg". - "summary_args" (dict) - a dictionary of arguments to be passed to the summary_method. Default is {}. - "message" (str, callable or None) - if None, input() will be called to get the initial message. - **context - additional context information to be passed to the chat. - "carryover" - It can be used to specify the carryover information to be passed to this chat. If provided, we will combine this carryover with the "message" content when generating the initial chat message in generate_init_message . - "finished_chat_indexes_to_exclude_from_carryover" - It can be used by specifying a list of indexes of the finished_chats list, from which to exclude the summaries for carryover. If 'finished_chat_indexes_to_exclude_from_carryover' is not provided or an empty list, then summary from all the finished chats will be taken. TYPE: List[Dict] |
RETURNS | DESCRIPTION |
list | a list of ChatResult objects corresponding to the finished chats in the chat_queue. |
Source code in autogen/agentchat/chat.py
| @export_module("autogen")
def initiate_chats(chat_queue: list[dict[str, Any]]) -> list[ChatResult]:
"""Initiate a list of chats.
Args:
chat_queue (List[Dict]): A list of dictionaries containing the information about the chats.
Each dictionary should contain the input arguments for
[`ConversableAgent.initiate_chat`](/docs/api-reference/autogen/ConversableAgent#initiate-chat).
For example:
- `"sender"` - the sender agent.
- `"recipient"` - the recipient agent.
- `"clear_history"` (bool) - whether to clear the chat history with the agent.
Default is True.
- `"silent"` (bool or None) - (Experimental) whether to print the messages in this
conversation. Default is False.
- `"cache"` (Cache or None) - the cache client to use for this conversation.
Default is None.
- `"max_turns"` (int or None) - maximum number of turns for the chat. If None, the chat
will continue until a termination condition is met. Default is None.
- `"summary_method"` (str or callable) - a string or callable specifying the method to get
a summary from the chat. Default is DEFAULT_summary_method, i.e., "last_msg".
- `"summary_args"` (dict) - a dictionary of arguments to be passed to the summary_method.
Default is {}.
- `"message"` (str, callable or None) - if None, input() will be called to get the
initial message.
- `**context` - additional context information to be passed to the chat.
- `"carryover"` - It can be used to specify the carryover information to be passed
to this chat. If provided, we will combine this carryover with the "message" content when
generating the initial chat message in `generate_init_message`.
- `"finished_chat_indexes_to_exclude_from_carryover"` - It can be used by specifying a list of indexes of the finished_chats list,
from which to exclude the summaries for carryover. If 'finished_chat_indexes_to_exclude_from_carryover' is not provided or an empty list,
then summary from all the finished chats will be taken.
Returns:
(list): a list of ChatResult objects corresponding to the finished chats in the chat_queue.
"""
consolidate_chat_info(chat_queue)
_validate_recipients(chat_queue)
current_chat_queue = chat_queue.copy()
finished_chats = []
while current_chat_queue:
chat_info = current_chat_queue.pop(0)
_chat_carryover = chat_info.get("carryover", [])
finished_chat_indexes_to_exclude_from_carryover = chat_info.get(
"finished_chat_indexes_to_exclude_from_carryover", []
)
if isinstance(_chat_carryover, str):
_chat_carryover = [_chat_carryover]
chat_info["carryover"] = _chat_carryover + [
r.summary for i, r in enumerate(finished_chats) if i not in finished_chat_indexes_to_exclude_from_carryover
]
if not chat_info.get("silent", False):
__post_carryover_processing(chat_info)
sender = chat_info["sender"]
chat_res = sender.initiate_chat(**chat_info)
finished_chats.append(chat_res)
return finished_chats
|