@@ -868,7 +868,7 @@ def initiate_chat(
868
868
summary_method : Optional [Union [str , Callable ]] = DEFAULT_SUMMARY_METHOD ,
869
869
summary_args : Optional [dict ] = {},
870
870
message : Optional [Union [Dict , str , Callable ]] = None ,
871
- ** context ,
871
+ ** kwargs ,
872
872
) -> ChatResult :
873
873
"""Initiate a chat with the recipient agent.
874
874
@@ -944,19 +944,19 @@ def my_message(sender: ConversableAgent, recipient: ConversableAgent, context: d
944
944
final_msg["context"] = {"prefix": "Today I feel"}
945
945
return final_msg
946
946
```
947
- **context : any context information. It has the following reserved fields:
947
+ **kwargs : any additional information. It has the following reserved fields:
948
948
- "carryover": a string or a list of string to specify the carryover information to be passed to this chat.
949
949
If provided, we will combine this carryover (by attaching a "context: " string and the carryover content after the message content) with the "message" content when generating the initial chat
950
950
message in `generate_init_message`.
951
+ - "verbose": a boolean to specify whether to print the message and carryover in a chat. Default is False.
951
952
952
953
Raises:
953
954
RuntimeError: if any async reply functions are registered and not ignored in sync chat.
954
955
955
956
Returns:
956
957
ChatResult: an ChatResult object.
957
958
"""
958
- _chat_info = context .copy ()
959
- _chat_info ["recipient" ] = recipient
959
+ _chat_info = locals ().copy ()
960
960
_chat_info ["sender" ] = self
961
961
consolidate_chat_info (_chat_info , uniform_sender = self )
962
962
for agent in [self , recipient ]:
@@ -968,9 +968,9 @@ def my_message(sender: ConversableAgent, recipient: ConversableAgent, context: d
968
968
for _ in range (max_turns ):
969
969
if _ == 0 :
970
970
if isinstance (message , Callable ):
971
- msg2send = message (_chat_info ["sender" ], _chat_info ["recipient" ], context )
971
+ msg2send = message (_chat_info ["sender" ], _chat_info ["recipient" ], kwargs )
972
972
else :
973
- msg2send = self .generate_init_message (message , ** context )
973
+ msg2send = self .generate_init_message (message , ** kwargs )
974
974
else :
975
975
msg2send = self .generate_reply (messages = self .chat_messages [recipient ], sender = recipient )
976
976
if msg2send is None :
@@ -979,9 +979,9 @@ def my_message(sender: ConversableAgent, recipient: ConversableAgent, context: d
979
979
else :
980
980
self ._prepare_chat (recipient , clear_history )
981
981
if isinstance (message , Callable ):
982
- msg2send = message (_chat_info ["sender" ], _chat_info ["recipient" ], context )
982
+ msg2send = message (_chat_info ["sender" ], _chat_info ["recipient" ], kwargs )
983
983
else :
984
- msg2send = self .generate_init_message (message , ** context )
984
+ msg2send = self .generate_init_message (message , ** kwargs )
985
985
self .send (msg2send , recipient , silent = silent )
986
986
summary = self ._summarize_chat (
987
987
summary_method ,
@@ -1010,7 +1010,7 @@ async def a_initiate_chat(
1010
1010
summary_method : Optional [Union [str , Callable ]] = DEFAULT_SUMMARY_METHOD ,
1011
1011
summary_args : Optional [dict ] = {},
1012
1012
message : Optional [Union [str , Callable ]] = None ,
1013
- ** context ,
1013
+ ** kwargs ,
1014
1014
) -> ChatResult :
1015
1015
"""(async) Initiate a chat with the recipient agent.
1016
1016
@@ -1023,8 +1023,7 @@ async def a_initiate_chat(
1023
1023
Returns:
1024
1024
ChatResult: an ChatResult object.
1025
1025
"""
1026
- _chat_info = context .copy ()
1027
- _chat_info ["recipient" ] = recipient
1026
+ _chat_info = locals ().copy ()
1028
1027
_chat_info ["sender" ] = self
1029
1028
consolidate_chat_info (_chat_info , uniform_sender = self )
1030
1029
for agent in [self , recipient ]:
@@ -1035,9 +1034,9 @@ async def a_initiate_chat(
1035
1034
for _ in range (max_turns ):
1036
1035
if _ == 0 :
1037
1036
if isinstance (message , Callable ):
1038
- msg2send = message (_chat_info ["sender" ], _chat_info ["recipient" ], context )
1037
+ msg2send = message (_chat_info ["sender" ], _chat_info ["recipient" ], kwargs )
1039
1038
else :
1040
- msg2send = await self .a_generate_init_message (message , ** context )
1039
+ msg2send = await self .a_generate_init_message (message , ** kwargs )
1041
1040
else :
1042
1041
msg2send = await self .a_generate_reply (messages = self .chat_messages [recipient ], sender = recipient )
1043
1042
if msg2send is None :
@@ -1046,9 +1045,9 @@ async def a_initiate_chat(
1046
1045
else :
1047
1046
self ._prepare_chat (recipient , clear_history )
1048
1047
if isinstance (message , Callable ):
1049
- msg2send = message (_chat_info ["sender" ], _chat_info ["recipient" ], context )
1048
+ msg2send = message (_chat_info ["sender" ], _chat_info ["recipient" ], kwargs )
1050
1049
else :
1051
- msg2send = await self .a_generate_init_message (message , ** context )
1050
+ msg2send = await self .a_generate_init_message (message , ** kwargs )
1052
1051
await self .a_send (msg2send , recipient , silent = silent )
1053
1052
summary = self ._summarize_chat (
1054
1053
summary_method ,
@@ -2217,13 +2216,13 @@ async def a_execute_function(self, func_call):
2217
2216
"content" : str (content ),
2218
2217
}
2219
2218
2220
- def generate_init_message (self , message : Union [Dict , str , None ], ** context ) -> Union [str , Dict ]:
2219
+ def generate_init_message (self , message : Union [Dict , str , None ], ** kwargs ) -> Union [str , Dict ]:
2221
2220
"""Generate the initial message for the agent.
2222
2221
If message is None, input() will be called to get the initial message.
2223
2222
2224
2223
Args:
2225
2224
message (str or None): the message to be processed.
2226
- **context : any context information. It has the following reserved fields:
2225
+ **kwargs : any additional information. It has the following reserved fields:
2227
2226
"carryover": a string or a list of string to specify the carryover information to be passed to this chat. It can be a string or a list of string.
2228
2227
If provided, we will combine this carryover with the "message" content when generating the initial chat
2229
2228
message.
@@ -2233,17 +2232,17 @@ def generate_init_message(self, message: Union[Dict, str, None], **context) -> U
2233
2232
if message is None :
2234
2233
message = self .get_human_input (">" )
2235
2234
if isinstance (message , str ):
2236
- return self ._process_carryover (message , context )
2235
+ return self ._process_carryover (message , kwargs )
2237
2236
elif isinstance (message , dict ):
2238
2237
message = message .copy ()
2239
2238
# TODO: Do we need to do the following?
2240
2239
# if message.get("content") is None:
2241
2240
# message["content"] = self.get_human_input(">")
2242
- message ["content" ] = self ._process_carryover (message .get ("content" , "" ), context )
2241
+ message ["content" ] = self ._process_carryover (message .get ("content" , "" ), kwargs )
2243
2242
return message
2244
2243
2245
- def _process_carryover (self , message : str , context : dict ) -> str :
2246
- carryover = context .get ("carryover" )
2244
+ def _process_carryover (self , message : str , kwargs : dict ) -> str :
2245
+ carryover = kwargs .get ("carryover" )
2247
2246
if carryover :
2248
2247
# if carryover is string
2249
2248
if isinstance (carryover , str ):
@@ -2256,7 +2255,7 @@ def _process_carryover(self, message: str, context: dict) -> str:
2256
2255
)
2257
2256
return message
2258
2257
2259
- async def a_generate_init_message (self , message : Union [Dict , str , None ], ** context ) -> Union [str , Dict ]:
2258
+ async def a_generate_init_message (self , message : Union [Dict , str , None ], ** kwargs ) -> Union [str , Dict ]:
2260
2259
"""Generate the initial message for the agent.
2261
2260
If message is None, input() will be called to get the initial message.
2262
2261
@@ -2269,10 +2268,10 @@ async def a_generate_init_message(self, message: Union[Dict, str, None], **conte
2269
2268
if message is None :
2270
2269
message = await self .a_get_human_input (">" )
2271
2270
if isinstance (message , str ):
2272
- return self ._process_carryover (message , context )
2271
+ return self ._process_carryover (message , kwargs )
2273
2272
elif isinstance (message , dict ):
2274
2273
message = message .copy ()
2275
- message ["content" ] = self ._process_carryover (message ["content" ], context )
2274
+ message ["content" ] = self ._process_carryover (message ["content" ], kwargs )
2276
2275
return message
2277
2276
2278
2277
def register_function (self , function_map : Dict [str , Union [Callable , None ]]):
0 commit comments