From b2f04f8cebe7f4019d83092bfea98ab3bd8dbf3f Mon Sep 17 00:00:00 2001 From: Eduardo Salinas Date: Wed, 13 Mar 2024 16:22:45 -0400 Subject: [PATCH 1/2] 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'. --- autogen/agentchat/conversable_agent.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/autogen/agentchat/conversable_agent.py b/autogen/agentchat/conversable_agent.py index 609a72b4768..216c94c6df8 100644 --- a/autogen/agentchat/conversable_agent.py +++ b/autogen/agentchat/conversable_agent.py @@ -162,7 +162,6 @@ def __init__( ) self._default_auto_reply = default_auto_reply self._reply_func_list = [] - self._ignore_async_func_in_sync_chat_list = [] self._human_input = [] self.reply_at_receive = defaultdict(bool) self.register_reply([Agent, None], ConversableAgent.generate_oai_reply) @@ -339,10 +338,9 @@ def reply_func( "config": copy.copy(config), "init_config": config, "reset_config": reset_config, + "ignore_async_in_sync_chat": ignore_async_in_sync_chat and inspect.iscoroutinefunction(reply_func), }, ) - if ignore_async_in_sync_chat and inspect.iscoroutinefunction(reply_func): - self._ignore_async_func_in_sync_chat_list.append(reply_func) @staticmethod def _summary_from_nested_chats( @@ -838,9 +836,11 @@ def _raise_exception_on_async_reply_functions(self) -> None: Raises: RuntimeError: if any async reply functions are registered. """ - reply_functions = {f["reply_func"] for f in self._reply_func_list}.difference( - self._ignore_async_func_in_sync_chat_list - ) + reply_functions = { + f["reply_func"] + for f in self._reply_func_list + if not f.get("ignore_async_in_sync_chat", False) + } async_reply_functions = [f for f in reply_functions if inspect.iscoroutinefunction(f)] if async_reply_functions != []: From 303aab0c85070c20b054da2ef627949729c35ed6 Mon Sep 17 00:00:00 2001 From: Eduardo Salinas Date: Wed, 13 Mar 2024 16:26:14 -0400 Subject: [PATCH 2/2] Update conversable_agent.py --- autogen/agentchat/conversable_agent.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/autogen/agentchat/conversable_agent.py b/autogen/agentchat/conversable_agent.py index 216c94c6df8..95c178aa074 100644 --- a/autogen/agentchat/conversable_agent.py +++ b/autogen/agentchat/conversable_agent.py @@ -837,9 +837,7 @@ def _raise_exception_on_async_reply_functions(self) -> None: RuntimeError: if any async reply functions are registered. """ reply_functions = { - f["reply_func"] - for f in self._reply_func_list - if not f.get("ignore_async_in_sync_chat", False) + f["reply_func"] for f in self._reply_func_list if not f.get("ignore_async_in_sync_chat", False) } async_reply_functions = [f for f in reply_functions if inspect.iscoroutinefunction(f)]