Skip to content

Commit e23bdfb

Browse files
lalosonichi
andauthored
refactor: [conversable_agent] remove list of func pointers (#2005)
* refactor: [conversable_agent] remove list of func pointers Ideally register_reply creates less state in multiple places and avoid having two copies of the same 'func pointer'. * Update conversable_agent.py --------- Co-authored-by: Chi Wang <[email protected]>
1 parent e35db7e commit e23bdfb

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

autogen/agentchat/conversable_agent.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ def __init__(
161161
)
162162
self._default_auto_reply = default_auto_reply
163163
self._reply_func_list = []
164-
self._ignore_async_func_in_sync_chat_list = []
165164
self._human_input = []
166165
self.reply_at_receive = defaultdict(bool)
167166
self.register_reply([Agent, None], ConversableAgent.generate_oai_reply)
@@ -335,10 +334,9 @@ def reply_func(
335334
"config": copy.copy(config),
336335
"init_config": config,
337336
"reset_config": reset_config,
337+
"ignore_async_in_sync_chat": ignore_async_in_sync_chat and inspect.iscoroutinefunction(reply_func),
338338
},
339339
)
340-
if ignore_async_in_sync_chat and inspect.iscoroutinefunction(reply_func):
341-
self._ignore_async_func_in_sync_chat_list.append(reply_func)
342340

343341
@staticmethod
344342
def _summary_from_nested_chats(
@@ -836,9 +834,9 @@ def _raise_exception_on_async_reply_functions(self) -> None:
836834
Raises:
837835
RuntimeError: if any async reply functions are registered.
838836
"""
839-
reply_functions = {f["reply_func"] for f in self._reply_func_list}.difference(
840-
self._ignore_async_func_in_sync_chat_list
841-
)
837+
reply_functions = {
838+
f["reply_func"] for f in self._reply_func_list if not f.get("ignore_async_in_sync_chat", False)
839+
}
842840

843841
async_reply_functions = [f for f in reply_functions if inspect.iscoroutinefunction(f)]
844842
if async_reply_functions != []:

0 commit comments

Comments
 (0)