(async) Initiate a list of chats.
PARAMETER | DESCRIPTION |
chat_queue | A list of dictionaries containing the information about the chats. TYPE: List[Dict] |
For | "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: example |
RETURNS | DESCRIPTION |
dict[int, ChatResult] | - (Dict): a dict of ChatId: ChatResult corresponding to the finished chats in the chat_queue.
|
Source code in autogen/agentchat/chat.py
| async def a_initiate_chats(chat_queue: list[dict[str, Any]]) -> dict[int, ChatResult]:
"""(async) 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:
- (Dict): a dict of ChatId: ChatResult corresponding to the finished chats in the chat_queue.
"""
consolidate_chat_info(chat_queue)
_validate_recipients(chat_queue)
chat_book = {chat_info["chat_id"]: chat_info for chat_info in chat_queue}
num_chats = chat_book.keys()
prerequisites = __create_async_prerequisites(chat_queue)
chat_order_by_id = __find_async_chat_order(num_chats, prerequisites)
finished_chat_futures = dict()
for chat_id in chat_order_by_id:
chat_info = chat_book[chat_id]
prerequisite_chat_ids = chat_info.get("prerequisites", [])
pre_chat_futures = dict()
for pre_chat_id in prerequisite_chat_ids:
pre_chat_future = finished_chat_futures[pre_chat_id]
pre_chat_futures[pre_chat_id] = pre_chat_future
current_chat_future = await _dependent_chat_future(chat_id, chat_info, pre_chat_futures)
finished_chat_futures[chat_id] = current_chat_future
await asyncio.gather(*list(finished_chat_futures.values()))
finished_chats = dict()
for chat in finished_chat_futures:
chat_result = finished_chat_futures[chat].result()
finished_chats[chat] = chat_result
return finished_chats
|