@@ -1180,6 +1180,23 @@ def _reflection_with_llm(
1180
1180
response = self ._generate_oai_reply_from_client (llm_client = llm_client , messages = messages , cache = cache )
1181
1181
return response
1182
1182
1183
+ def _check_chat_queue_for_sender (self , chat_queue : List [Dict [str , Any ]]) -> List [Dict [str , Any ]]:
1184
+ """
1185
+ Check the chat queue and add the "sender" key if it's missing.
1186
+
1187
+ Args:
1188
+ chat_queue (List[Dict[str, Any]]): A list of dictionaries containing chat information.
1189
+
1190
+ Returns:
1191
+ List[Dict[str, Any]]: A new list of dictionaries with the "sender" key added if it was missing.
1192
+ """
1193
+ chat_queue_with_sender = []
1194
+ for chat_info in chat_queue :
1195
+ if chat_info .get ("sender" ) is None :
1196
+ chat_info ["sender" ] = self
1197
+ chat_queue_with_sender .append (chat_info )
1198
+ return chat_queue_with_sender
1199
+
1183
1200
def initiate_chats (self , chat_queue : List [Dict [str , Any ]]) -> List [ChatResult ]:
1184
1201
"""(Experimental) Initiate chats with multiple agents.
1185
1202
@@ -1189,16 +1206,13 @@ def initiate_chats(self, chat_queue: List[Dict[str, Any]]) -> List[ChatResult]:
1189
1206
1190
1207
Returns: a list of ChatResult objects corresponding to the finished chats in the chat_queue.
1191
1208
"""
1192
- _chat_queue = chat_queue .copy ()
1193
- for chat_info in _chat_queue :
1194
- chat_info ["sender" ] = self
1209
+ _chat_queue = self ._check_chat_queue_for_sender (chat_queue )
1195
1210
self ._finished_chats = initiate_chats (_chat_queue )
1196
1211
return self ._finished_chats
1197
1212
1198
1213
async def a_initiate_chats (self , chat_queue : List [Dict [str , Any ]]) -> Dict [int , ChatResult ]:
1199
- _chat_queue = chat_queue .copy ()
1200
- for chat_info in _chat_queue :
1201
- chat_info ["sender" ] = self
1214
+
1215
+ _chat_queue = self ._check_chat_queue_for_sender (chat_queue )
1202
1216
self ._finished_chats = await a_initiate_chats (_chat_queue )
1203
1217
return self ._finished_chats
1204
1218
0 commit comments