From 8f8a0bdc1a66bb4595f0d571427f57e53bd53ac0 Mon Sep 17 00:00:00 2001 From: Rajan Date: Thu, 25 Jul 2024 12:07:56 -0400 Subject: [PATCH 01/29] Added Runtime Factory to support multiple implementations --- .../cap/py/autogencap/ComponentEnsemble.py | 4 +- .../apps/cap/py/autogencap/actor_runtime.py | 35 +++++++++++++++ .../apps/cap/py/autogencap/runtime_factory.py | 43 +++++++++++++++++++ samples/apps/cap/py/demo/SimpleActorDemo.py | 12 +++--- 4 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 samples/apps/cap/py/autogencap/actor_runtime.py create mode 100644 samples/apps/cap/py/autogencap/runtime_factory.py diff --git a/samples/apps/cap/py/autogencap/ComponentEnsemble.py b/samples/apps/cap/py/autogencap/ComponentEnsemble.py index ebb31fb9aa7c..9805b1fe3196 100644 --- a/samples/apps/cap/py/autogencap/ComponentEnsemble.py +++ b/samples/apps/cap/py/autogencap/ComponentEnsemble.py @@ -10,9 +10,9 @@ from .DebugLog import Debug, Warn from .DirectorySvc import DirectorySvc from .proto.CAP_pb2 import ActorInfo, ActorInfoCollection +from .actor_runtime import IRuntime - -class ComponentEnsemble: +class ComponentEnsemble(IRuntime): def __init__(self, name: str = "Local Actor Network", start_broker: bool = True): self.local_actors = {} self.name: str = name diff --git a/samples/apps/cap/py/autogencap/actor_runtime.py b/samples/apps/cap/py/autogencap/actor_runtime.py new file mode 100644 index 000000000000..fa3451b49134 --- /dev/null +++ b/samples/apps/cap/py/autogencap/actor_runtime.py @@ -0,0 +1,35 @@ +from abc import ABC, abstractmethod +from .Actor import Actor +from .ActorConnector import ActorConnector +from typing import List +from .proto.CAP_pb2 import ActorInfo + + +class IRuntime(ABC): + @abstractmethod + def register(self, actor: Actor): + pass + + @abstractmethod + def connect(self): + pass + + @abstractmethod + def disconnect(self): + pass + + @abstractmethod + def find_by_topic(self, topic: str) -> ActorConnector: + pass + + @abstractmethod + def find_by_name(self, name: str) -> ActorConnector: + pass + + @abstractmethod + def find_termination(self) -> ActorConnector: + pass + + @abstractmethod + def find_by_name_regex(self, name_regex) -> List[ActorInfo]: + pass diff --git a/samples/apps/cap/py/autogencap/runtime_factory.py b/samples/apps/cap/py/autogencap/runtime_factory.py new file mode 100644 index 000000000000..62553761c0be --- /dev/null +++ b/samples/apps/cap/py/autogencap/runtime_factory.py @@ -0,0 +1,43 @@ +from autogencap.ComponentEnsemble import ComponentEnsemble +from autogencap.DebugLog import Error +from autogencap.actor_runtime import IRuntime + +class RuntimeFactory: + _supported_runtimes = {} + + """ + Factory class for creating a runtime instance. + """ + @staticmethod + def get_runtime(runtime_type) -> IRuntime: + """ + Creates a runtime instance based on the runtime type. + + :param runtime_type: The type of runtime to create. + :return: The runtime instance. + """ + if runtime_type in RuntimeFactory._supported_runtimes: + return RuntimeFactory._supported_runtimes[runtime_type] + else: + not_found = f"Runtime type not found: {runtime_type}" + Error("RuntimeFactory", not_found) + raise ValueError(not_found) + + @staticmethod + def register_runtime(runtime_type: str, runtime: IRuntime): + """ + Registers a runtime instance. + + :param runtime: The runtime instance. + """ + RuntimeFactory._supported_runtimes[runtime_type] = runtime + + @classmethod + def _initialize(cls): + """ + Static initialization method. + """ + cls.register_runtime("ZMQ",ComponentEnsemble()) + +# Static initialization +RuntimeFactory._initialize() \ No newline at end of file diff --git a/samples/apps/cap/py/demo/SimpleActorDemo.py b/samples/apps/cap/py/demo/SimpleActorDemo.py index f0f081a5d630..e63df28ef02c 100644 --- a/samples/apps/cap/py/demo/SimpleActorDemo.py +++ b/samples/apps/cap/py/demo/SimpleActorDemo.py @@ -1,6 +1,6 @@ from AppAgents import GreeterAgent from autogencap.ComponentEnsemble import ComponentEnsemble - +from autogencap.runtime_factory import RuntimeFactory def simple_actor_demo(): """ @@ -8,10 +8,10 @@ def simple_actor_demo(): sending a message, and performing cleanup operations. """ # CAP Platform - ensemble = ComponentEnsemble() + runtime = RuntimeFactory.get_runtime("ZMQ") agent = GreeterAgent() - ensemble.register(agent) - ensemble.connect() - greeter_link = ensemble.find_by_name("Greeter") + runtime.register(agent) + runtime.connect() + greeter_link = runtime.find_by_name("Greeter") greeter_link.send_txt_msg("Hello World!") - ensemble.disconnect() + runtime.disconnect() From a241bdcd46532c9cf25081205926517692b97d18 Mon Sep 17 00:00:00 2001 From: Rajan Date: Thu, 25 Jul 2024 12:40:45 -0400 Subject: [PATCH 02/29] Rename to ComponentEnsemble to ZMQRuntime --- .../py/autogencap/{ComponentEnsemble.py => ZMQRuntime.py} | 2 +- samples/apps/cap/py/autogencap/ag_adapter/AG2CAP.py | 6 +++--- samples/apps/cap/py/autogencap/ag_adapter/CAP2AG.py | 8 ++++---- samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChat.py | 6 +++--- .../cap/py/autogencap/ag_adapter/CAPGroupChatManager.py | 6 +++--- samples/apps/cap/py/autogencap/runtime_factory.py | 4 ++-- samples/apps/cap/py/demo/AppAgents.py | 7 ++++--- samples/apps/cap/py/demo/CAPAutGenGroupDemo.py | 4 ++-- samples/apps/cap/py/demo/CAPAutoGenPairDemo.py | 4 ++-- samples/apps/cap/py/demo/ComplexActorDemo.py | 4 ++-- samples/apps/cap/py/demo/SimpleActorDemo.py | 1 - samples/apps/cap/py/demo/list_agents.py | 4 ++-- samples/apps/cap/py/demo/single_threaded.py | 4 ++-- samples/apps/cap/py/demo/standalone/UserProxy.py | 4 ++-- samples/apps/cap/py/demo/standalone/assistant.py | 4 ++-- samples/apps/cap/py/demo/standalone/user_proxy.py | 4 ++-- 16 files changed, 36 insertions(+), 36 deletions(-) rename samples/apps/cap/py/autogencap/{ComponentEnsemble.py => ZMQRuntime.py} (98%) diff --git a/samples/apps/cap/py/autogencap/ComponentEnsemble.py b/samples/apps/cap/py/autogencap/ZMQRuntime.py similarity index 98% rename from samples/apps/cap/py/autogencap/ComponentEnsemble.py rename to samples/apps/cap/py/autogencap/ZMQRuntime.py index 9805b1fe3196..a64b8fabe352 100644 --- a/samples/apps/cap/py/autogencap/ComponentEnsemble.py +++ b/samples/apps/cap/py/autogencap/ZMQRuntime.py @@ -12,7 +12,7 @@ from .proto.CAP_pb2 import ActorInfo, ActorInfoCollection from .actor_runtime import IRuntime -class ComponentEnsemble(IRuntime): +class ZMQRuntime(IRuntime): def __init__(self, name: str = "Local Actor Network", start_broker: bool = True): self.local_actors = {} self.name: str = name diff --git a/samples/apps/cap/py/autogencap/ag_adapter/AG2CAP.py b/samples/apps/cap/py/autogencap/ag_adapter/AG2CAP.py index 1854d219e7d1..4b5f79aefd85 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/AG2CAP.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/AG2CAP.py @@ -3,7 +3,7 @@ from autogen import Agent, ConversableAgent -from ..ComponentEnsemble import ComponentEnsemble +from ..actor_runtime import IRuntime from .AutoGenConnector import AutoGenConnector @@ -14,13 +14,13 @@ class AG2CAP(ConversableAgent): def __init__( self, - ensemble: ComponentEnsemble, + ensemble: IRuntime, agent_name: str, agent_description: Optional[str] = None, ): super().__init__(name=agent_name, description=agent_description, llm_config=False) self._agent_connector: AutoGenConnector = None - self._ensemble: ComponentEnsemble = ensemble + self._ensemble: IRuntime = ensemble self._recv_called = False def reset_receive_called(self): diff --git a/samples/apps/cap/py/autogencap/ag_adapter/CAP2AG.py b/samples/apps/cap/py/autogencap/ag_adapter/CAP2AG.py index 789ebd9bf4b8..0dd3b7be5ced 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/CAP2AG.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/CAP2AG.py @@ -4,7 +4,7 @@ from autogen import ConversableAgent -from ..ComponentEnsemble import ComponentEnsemble +from ..actor_runtime import IRuntime from ..DebugLog import Debug, Error, Info, Warn, shorten from ..proto.Autogen_pb2 import GenReplyReq, GenReplyResp, PrepChat, ReceiveReq, Terminate from .AG2CAP import AG2CAP @@ -27,10 +27,10 @@ def __init__(self, ag_agent: ConversableAgent, the_other_name: str, init_chat: b self.STATE = self.States.INIT self._can2ag_name: str = self.actor_name + ".can2ag" self._self_recursive: bool = self_recursive - self._ensemble: ComponentEnsemble = None + self._ensemble: IRuntime = None self._connectors = {} - def on_connect(self, ensemble: ComponentEnsemble): + def on_connect(self, ensemble: IRuntime): """ Connect to the AutoGen system. """ @@ -38,7 +38,7 @@ def on_connect(self, ensemble: ComponentEnsemble): self._ag2can_other_agent = AG2CAP(self._ensemble, self._other_agent_name) Debug(self._can2ag_name, "connected to {ensemble}") - def disconnect_network(self, ensemble: ComponentEnsemble): + def disconnect_network(self, ensemble: IRuntime): """ Disconnect from the AutoGen system. """ diff --git a/samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChat.py b/samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChat.py index 5fad7b359e16..bbd4ec32b9d2 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChat.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChat.py @@ -3,7 +3,7 @@ from autogen import Agent, AssistantAgent, GroupChat from autogencap.ag_adapter.AG2CAP import AG2CAP from autogencap.ag_adapter.CAP2AG import CAP2AG -from autogencap.ComponentEnsemble import ComponentEnsemble +from ..actor_runtime import IRuntime class CAPGroupChat(GroupChat): @@ -13,10 +13,10 @@ def __init__( messages: List[str], max_round: int, chat_initiator: str, - ensemble: ComponentEnsemble, + ensemble: IRuntime, ): self.chat_initiator: str = chat_initiator - self._cap_network: ComponentEnsemble = ensemble + self._cap_network: IRuntime = ensemble self._cap_proxies: List[CAP2AG] = [] self._ag_proxies: List[AG2CAP] = [] self._ag_agents: List[Agent] = agents diff --git a/samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChatManager.py b/samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChatManager.py index 85a746d7c661..0f4beaacfa0f 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChatManager.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChatManager.py @@ -4,12 +4,12 @@ from autogencap.ActorConnector import ActorConnector from autogencap.ag_adapter.CAP2AG import CAP2AG from autogencap.ag_adapter.CAPGroupChat import CAPGroupChat -from autogencap.ComponentEnsemble import ComponentEnsemble +from ..actor_runtime import IRuntime class CAPGroupChatManager: - def __init__(self, groupchat: CAPGroupChat, llm_config: dict, network: ComponentEnsemble): - self._ensemble: ComponentEnsemble = network + def __init__(self, groupchat: CAPGroupChat, llm_config: dict, network: IRuntime): + self._ensemble: IRuntime = network self._cap_group_chat: CAPGroupChat = groupchat self._ag_group_chat_manager: GroupChatManager = GroupChatManager( groupchat=self._cap_group_chat, llm_config=llm_config diff --git a/samples/apps/cap/py/autogencap/runtime_factory.py b/samples/apps/cap/py/autogencap/runtime_factory.py index 62553761c0be..2887ba827bc8 100644 --- a/samples/apps/cap/py/autogencap/runtime_factory.py +++ b/samples/apps/cap/py/autogencap/runtime_factory.py @@ -1,4 +1,4 @@ -from autogencap.ComponentEnsemble import ComponentEnsemble +from autogencap.ZMQRuntime import ZMQRuntime from autogencap.DebugLog import Error from autogencap.actor_runtime import IRuntime @@ -37,7 +37,7 @@ def _initialize(cls): """ Static initialization method. """ - cls.register_runtime("ZMQ",ComponentEnsemble()) + cls.register_runtime("ZMQ",ZMQRuntime()) # Static initialization RuntimeFactory._initialize() \ No newline at end of file diff --git a/samples/apps/cap/py/demo/AppAgents.py b/samples/apps/cap/py/demo/AppAgents.py index bed163a293ee..3e50ce699f22 100644 --- a/samples/apps/cap/py/demo/AppAgents.py +++ b/samples/apps/cap/py/demo/AppAgents.py @@ -6,7 +6,8 @@ from autogencap.Actor import Actor from autogencap.ActorConnector import ActorConnector -from autogencap.ComponentEnsemble import ComponentEnsemble +from autogencap.runtime_factory import RuntimeFactory +from autogencap.actor_runtime import IRuntime from autogencap.DebugLog import Debug, Info, shorten @@ -136,7 +137,7 @@ def __init__( self.quant: ActorConnector = None self.risk_manager: ActorConnector = None - def on_connect(self, network: ComponentEnsemble): + def on_connect(self, network: IRuntime): """ Connects the personal assistant to the specified local actor network. @@ -150,7 +151,7 @@ def on_connect(self, network: ComponentEnsemble): self.risk_manager = network.find_by_name("Risk Manager") Debug(self.actor_name, "connected") - def disconnect_network(self, network: ComponentEnsemble): + def disconnect_network(self, network: IRuntime): """ Disconnects the personal assistant from the specified local actor network. diff --git a/samples/apps/cap/py/demo/CAPAutGenGroupDemo.py b/samples/apps/cap/py/demo/CAPAutGenGroupDemo.py index 4c3aa1b80305..8d5b164eb571 100644 --- a/samples/apps/cap/py/demo/CAPAutGenGroupDemo.py +++ b/samples/apps/cap/py/demo/CAPAutGenGroupDemo.py @@ -1,6 +1,6 @@ from autogencap.ag_adapter.CAPGroupChat import CAPGroupChat from autogencap.ag_adapter.CAPGroupChatManager import CAPGroupChatManager -from autogencap.ComponentEnsemble import ComponentEnsemble +from autogencap.runtime_factory import RuntimeFactory from autogencap.DebugLog import Info from autogen import AssistantAgent, UserProxyAgent, config_list_from_json @@ -31,7 +31,7 @@ def cap_ag_group_demo(): system_message="Creative in software product ideas.", llm_config=gpt4_config, ) - ensemble = ComponentEnsemble() + ensemble = RuntimeFactory.get_runtime("ZMQ") cap_groupchat = CAPGroupChat( agents=[user_proxy, coder, pm], messages=[], max_round=12, ensemble=ensemble, chat_initiator=user_proxy.name ) diff --git a/samples/apps/cap/py/demo/CAPAutoGenPairDemo.py b/samples/apps/cap/py/demo/CAPAutoGenPairDemo.py index 00ff7a892878..358741951e3f 100644 --- a/samples/apps/cap/py/demo/CAPAutoGenPairDemo.py +++ b/samples/apps/cap/py/demo/CAPAutoGenPairDemo.py @@ -2,7 +2,7 @@ import autogencap.DebugLog as DebugLog from autogencap.ag_adapter.CAPPair import CAPPair -from autogencap.ComponentEnsemble import ComponentEnsemble +from autogencap.runtime_factory import RuntimeFactory from autogencap.DebugLog import ConsoleLogger, Info from autogen import AssistantAgent, UserProxyAgent, config_list_from_json @@ -20,7 +20,7 @@ def cap_ag_pair_demo(): ) # Composable Agent Platform AutoGen Pair adapter - ensemble = ComponentEnsemble() + ensemble = RuntimeFactory.get_runtime("ZMQ") pair = CAPPair(ensemble, user_proxy, assistant) user_cmd = "Plot a chart of MSFT daily closing prices for last 1 Month" diff --git a/samples/apps/cap/py/demo/ComplexActorDemo.py b/samples/apps/cap/py/demo/ComplexActorDemo.py index 6f6215daece8..b82d457cc67b 100644 --- a/samples/apps/cap/py/demo/ComplexActorDemo.py +++ b/samples/apps/cap/py/demo/ComplexActorDemo.py @@ -1,7 +1,7 @@ import time from AppAgents import FidelityAgent, FinancialPlannerAgent, PersonalAssistant, QuantAgent, RiskManager -from autogencap.ComponentEnsemble import ComponentEnsemble +from autogencap.runtime_factory import RuntimeFactory from termcolor import colored @@ -14,7 +14,7 @@ def complex_actor_demo(): sends them to the personal assistant agent, and terminates when the user enters "quit". """ - ensemble = ComponentEnsemble() + ensemble = RuntimeFactory.get_runtime("ZMQ") # Register agents ensemble.register(PersonalAssistant()) ensemble.register(FidelityAgent()) diff --git a/samples/apps/cap/py/demo/SimpleActorDemo.py b/samples/apps/cap/py/demo/SimpleActorDemo.py index e63df28ef02c..26123a4eb356 100644 --- a/samples/apps/cap/py/demo/SimpleActorDemo.py +++ b/samples/apps/cap/py/demo/SimpleActorDemo.py @@ -1,5 +1,4 @@ from AppAgents import GreeterAgent -from autogencap.ComponentEnsemble import ComponentEnsemble from autogencap.runtime_factory import RuntimeFactory def simple_actor_demo(): diff --git a/samples/apps/cap/py/demo/list_agents.py b/samples/apps/cap/py/demo/list_agents.py index 3a93dda29422..533290ad4c37 100644 --- a/samples/apps/cap/py/demo/list_agents.py +++ b/samples/apps/cap/py/demo/list_agents.py @@ -2,7 +2,7 @@ from typing import List from AppAgents import FidelityAgent, GreeterAgent -from autogencap.ComponentEnsemble import ComponentEnsemble +from autogencap.runtime_factory import RuntimeFactory from autogencap.DebugLog import Info from autogencap.proto.CAP_pb2 import ActorInfo @@ -14,7 +14,7 @@ def list_agents(): """ # CAP Platform - ensemble = ComponentEnsemble() + ensemble = RuntimeFactory.get_runtime("ZMQ") # Register an actor ensemble.register(GreeterAgent()) # Register an actor diff --git a/samples/apps/cap/py/demo/single_threaded.py b/samples/apps/cap/py/demo/single_threaded.py index d95f67128e64..3fa8015dbc48 100644 --- a/samples/apps/cap/py/demo/single_threaded.py +++ b/samples/apps/cap/py/demo/single_threaded.py @@ -1,6 +1,6 @@ import _paths from AppAgents import GreeterAgent -from autogencap.ComponentEnsemble import ComponentEnsemble +from autogencap.runtime_factory import RuntimeFactory from autogencap.DebugLog import Error from autogencap.proto.CAP_pb2 import Ping @@ -11,7 +11,7 @@ def single_threaded_demo(): sending a message, and performing cleanup operations. """ # CAP Platform - ensemble = ComponentEnsemble() + ensemble = RuntimeFactory.get_runtime("ZMQ") agent = GreeterAgent(start_thread=False) ensemble.register(agent) ensemble.connect() diff --git a/samples/apps/cap/py/demo/standalone/UserProxy.py b/samples/apps/cap/py/demo/standalone/UserProxy.py index 981198072e6f..2deb48723f2c 100644 --- a/samples/apps/cap/py/demo/standalone/UserProxy.py +++ b/samples/apps/cap/py/demo/standalone/UserProxy.py @@ -2,7 +2,7 @@ import _paths from autogencap.ag_adapter.CAP2AG import CAP2AG -from autogencap.ComponentEnsemble import ComponentEnsemble +from autogencap.runtime_factory import RuntimeFactory from autogencap.Config import IGNORED_LOG_CONTEXTS from autogencap.DebugLog import Info @@ -23,7 +23,7 @@ def run(self): is_termination_msg=lambda x: "TERMINATE" in x.get("content"), ) # Composable Agent Network adapter - ensemble = ComponentEnsemble() + ensemble = RuntimeFactory.get_runtime("ZMQ") user_proxy_adptr = CAP2AG(ag_agent=user_proxy, the_other_name="assistant", init_chat=True, self_recursive=True) ensemble.register(user_proxy_adptr) ensemble.connect() diff --git a/samples/apps/cap/py/demo/standalone/assistant.py b/samples/apps/cap/py/demo/standalone/assistant.py index 789482e48881..d454da07a36b 100644 --- a/samples/apps/cap/py/demo/standalone/assistant.py +++ b/samples/apps/cap/py/demo/standalone/assistant.py @@ -2,7 +2,7 @@ import _paths from autogencap.ag_adapter.CAP2AG import CAP2AG -from autogencap.ComponentEnsemble import ComponentEnsemble +from autogencap.runtime_factory import RuntimeFactory from autogencap.DebugLog import Info from autogen import AssistantAgent, config_list_from_json @@ -18,7 +18,7 @@ def run(self): config_list = config_list_from_json(env_or_file="OAI_CONFIG_LIST") assistant = AssistantAgent("assistant", llm_config={"config_list": config_list}) # Composable Agent Network adapter - ensemble = ComponentEnsemble() + ensemble = RuntimeFactory.get_runtime("ZMQ") assistant_adptr = CAP2AG(ag_agent=assistant, the_other_name="user_proxy", init_chat=False, self_recursive=True) ensemble.register(assistant_adptr) ensemble.connect() diff --git a/samples/apps/cap/py/demo/standalone/user_proxy.py b/samples/apps/cap/py/demo/standalone/user_proxy.py index 4859361bb41b..18aeb733769f 100644 --- a/samples/apps/cap/py/demo/standalone/user_proxy.py +++ b/samples/apps/cap/py/demo/standalone/user_proxy.py @@ -2,7 +2,7 @@ import _paths from autogencap.ag_adapter.agent import Agent -from autogencap.ComponentEnsemble import ComponentEnsemble +from autogencap.runtime_factory import RuntimeFactory from autogencap.Config import IGNORED_LOG_CONTEXTS from autogen import UserProxyAgent @@ -22,7 +22,7 @@ def main(): # Wrap AutoGen Agent in CAP cap_user_proxy = Agent(user_proxy, counter_party_name="assistant", init_chat=True) # Create the message bus - ensemble = ComponentEnsemble() + ensemble = RuntimeFactory.get_runtime("ZMQ") # Add the user_proxy to the message bus cap_user_proxy.register(ensemble) # Start message processing From b372e774903b1d1f33f51e0d6749c7479c9bcfea Mon Sep 17 00:00:00 2001 From: Rajan Date: Thu, 25 Jul 2024 12:42:45 -0400 Subject: [PATCH 03/29] rename zmq_runtime --- samples/apps/cap/py/autogencap/{ZMQRuntime.py => zmq_runtime.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename samples/apps/cap/py/autogencap/{ZMQRuntime.py => zmq_runtime.py} (100%) diff --git a/samples/apps/cap/py/autogencap/ZMQRuntime.py b/samples/apps/cap/py/autogencap/zmq_runtime.py similarity index 100% rename from samples/apps/cap/py/autogencap/ZMQRuntime.py rename to samples/apps/cap/py/autogencap/zmq_runtime.py From 15b715eac653e70f700ce072b151aeb9fb06c84f Mon Sep 17 00:00:00 2001 From: Rajan Date: Thu, 25 Jul 2024 12:44:35 -0400 Subject: [PATCH 04/29] rename zmq_runtime --- samples/apps/cap/py/autogencap/runtime_factory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/apps/cap/py/autogencap/runtime_factory.py b/samples/apps/cap/py/autogencap/runtime_factory.py index 2887ba827bc8..ba163230ae63 100644 --- a/samples/apps/cap/py/autogencap/runtime_factory.py +++ b/samples/apps/cap/py/autogencap/runtime_factory.py @@ -1,4 +1,4 @@ -from autogencap.ZMQRuntime import ZMQRuntime +from autogencap.zmq_runtime import ZMQRuntime from autogencap.DebugLog import Error from autogencap.actor_runtime import IRuntime From d91d478d121f50b1a0eaa5925bf9c782d7e208ad Mon Sep 17 00:00:00 2001 From: Rajan Date: Thu, 25 Jul 2024 20:49:37 -0400 Subject: [PATCH 05/29] pre-commit fixes --- samples/apps/cap/py/autogencap/actor_runtime.py | 7 ++++--- .../apps/cap/py/autogencap/ag_adapter/CAPGroupChat.py | 1 + .../cap/py/autogencap/ag_adapter/CAPGroupChatManager.py | 1 + samples/apps/cap/py/autogencap/runtime_factory.py | 9 +++++---- samples/apps/cap/py/autogencap/zmq_runtime.py | 3 ++- samples/apps/cap/py/demo/AppAgents.py | 4 ++-- samples/apps/cap/py/demo/CAPAutGenGroupDemo.py | 2 +- samples/apps/cap/py/demo/CAPAutoGenPairDemo.py | 2 +- samples/apps/cap/py/demo/SimpleActorDemo.py | 1 + samples/apps/cap/py/demo/list_agents.py | 2 +- samples/apps/cap/py/demo/single_threaded.py | 2 +- samples/apps/cap/py/demo/standalone/UserProxy.py | 2 +- samples/apps/cap/py/demo/standalone/assistant.py | 2 +- samples/apps/cap/py/demo/standalone/user_proxy.py | 2 +- 14 files changed, 23 insertions(+), 17 deletions(-) diff --git a/samples/apps/cap/py/autogencap/actor_runtime.py b/samples/apps/cap/py/autogencap/actor_runtime.py index fa3451b49134..027b20905877 100644 --- a/samples/apps/cap/py/autogencap/actor_runtime.py +++ b/samples/apps/cap/py/autogencap/actor_runtime.py @@ -1,7 +1,8 @@ from abc import ABC, abstractmethod +from typing import List + from .Actor import Actor from .ActorConnector import ActorConnector -from typing import List from .proto.CAP_pb2 import ActorInfo @@ -9,7 +10,7 @@ class IRuntime(ABC): @abstractmethod def register(self, actor: Actor): pass - + @abstractmethod def connect(self): pass @@ -17,7 +18,7 @@ def connect(self): @abstractmethod def disconnect(self): pass - + @abstractmethod def find_by_topic(self, topic: str) -> ActorConnector: pass diff --git a/samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChat.py b/samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChat.py index bbd4ec32b9d2..caf2a11a66f1 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChat.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChat.py @@ -3,6 +3,7 @@ from autogen import Agent, AssistantAgent, GroupChat from autogencap.ag_adapter.AG2CAP import AG2CAP from autogencap.ag_adapter.CAP2AG import CAP2AG + from ..actor_runtime import IRuntime diff --git a/samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChatManager.py b/samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChatManager.py index 0f4beaacfa0f..e71e6aecddf8 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChatManager.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChatManager.py @@ -4,6 +4,7 @@ from autogencap.ActorConnector import ActorConnector from autogencap.ag_adapter.CAP2AG import CAP2AG from autogencap.ag_adapter.CAPGroupChat import CAPGroupChat + from ..actor_runtime import IRuntime diff --git a/samples/apps/cap/py/autogencap/runtime_factory.py b/samples/apps/cap/py/autogencap/runtime_factory.py index ba163230ae63..0f10cbae8339 100644 --- a/samples/apps/cap/py/autogencap/runtime_factory.py +++ b/samples/apps/cap/py/autogencap/runtime_factory.py @@ -1,6 +1,7 @@ -from autogencap.zmq_runtime import ZMQRuntime -from autogencap.DebugLog import Error from autogencap.actor_runtime import IRuntime +from autogencap.DebugLog import Error +from autogencap.zmq_runtime import ZMQRuntime + class RuntimeFactory: _supported_runtimes = {} @@ -22,7 +23,7 @@ def get_runtime(runtime_type) -> IRuntime: not_found = f"Runtime type not found: {runtime_type}" Error("RuntimeFactory", not_found) raise ValueError(not_found) - + @staticmethod def register_runtime(runtime_type: str, runtime: IRuntime): """ @@ -40,4 +41,4 @@ def _initialize(cls): cls.register_runtime("ZMQ",ZMQRuntime()) # Static initialization -RuntimeFactory._initialize() \ No newline at end of file +RuntimeFactory._initialize() diff --git a/samples/apps/cap/py/autogencap/zmq_runtime.py b/samples/apps/cap/py/autogencap/zmq_runtime.py index a64b8fabe352..5735145c59e5 100644 --- a/samples/apps/cap/py/autogencap/zmq_runtime.py +++ b/samples/apps/cap/py/autogencap/zmq_runtime.py @@ -4,13 +4,14 @@ import zmq from .Actor import Actor +from .actor_runtime import IRuntime from .ActorConnector import ActorConnector from .Broker import Broker from .Constants import Termination_Topic from .DebugLog import Debug, Warn from .DirectorySvc import DirectorySvc from .proto.CAP_pb2 import ActorInfo, ActorInfoCollection -from .actor_runtime import IRuntime + class ZMQRuntime(IRuntime): def __init__(self, name: str = "Local Actor Network", start_broker: bool = True): diff --git a/samples/apps/cap/py/demo/AppAgents.py b/samples/apps/cap/py/demo/AppAgents.py index 3e50ce699f22..f13e4b471fd6 100644 --- a/samples/apps/cap/py/demo/AppAgents.py +++ b/samples/apps/cap/py/demo/AppAgents.py @@ -5,10 +5,10 @@ """ from autogencap.Actor import Actor -from autogencap.ActorConnector import ActorConnector -from autogencap.runtime_factory import RuntimeFactory from autogencap.actor_runtime import IRuntime +from autogencap.ActorConnector import ActorConnector from autogencap.DebugLog import Debug, Info, shorten +from autogencap.runtime_factory import RuntimeFactory class GreeterAgent(Actor): diff --git a/samples/apps/cap/py/demo/CAPAutGenGroupDemo.py b/samples/apps/cap/py/demo/CAPAutGenGroupDemo.py index 8d5b164eb571..93a28c753ca5 100644 --- a/samples/apps/cap/py/demo/CAPAutGenGroupDemo.py +++ b/samples/apps/cap/py/demo/CAPAutGenGroupDemo.py @@ -1,7 +1,7 @@ from autogencap.ag_adapter.CAPGroupChat import CAPGroupChat from autogencap.ag_adapter.CAPGroupChatManager import CAPGroupChatManager -from autogencap.runtime_factory import RuntimeFactory from autogencap.DebugLog import Info +from autogencap.runtime_factory import RuntimeFactory from autogen import AssistantAgent, UserProxyAgent, config_list_from_json diff --git a/samples/apps/cap/py/demo/CAPAutoGenPairDemo.py b/samples/apps/cap/py/demo/CAPAutoGenPairDemo.py index 358741951e3f..77323ddf8707 100644 --- a/samples/apps/cap/py/demo/CAPAutoGenPairDemo.py +++ b/samples/apps/cap/py/demo/CAPAutoGenPairDemo.py @@ -2,8 +2,8 @@ import autogencap.DebugLog as DebugLog from autogencap.ag_adapter.CAPPair import CAPPair -from autogencap.runtime_factory import RuntimeFactory from autogencap.DebugLog import ConsoleLogger, Info +from autogencap.runtime_factory import RuntimeFactory from autogen import AssistantAgent, UserProxyAgent, config_list_from_json diff --git a/samples/apps/cap/py/demo/SimpleActorDemo.py b/samples/apps/cap/py/demo/SimpleActorDemo.py index 26123a4eb356..afc398297268 100644 --- a/samples/apps/cap/py/demo/SimpleActorDemo.py +++ b/samples/apps/cap/py/demo/SimpleActorDemo.py @@ -1,6 +1,7 @@ from AppAgents import GreeterAgent from autogencap.runtime_factory import RuntimeFactory + def simple_actor_demo(): """ Demonstrates the usage of the CAP platform by registering an actor, connecting to the actor, diff --git a/samples/apps/cap/py/demo/list_agents.py b/samples/apps/cap/py/demo/list_agents.py index 533290ad4c37..ca02006df2b7 100644 --- a/samples/apps/cap/py/demo/list_agents.py +++ b/samples/apps/cap/py/demo/list_agents.py @@ -2,9 +2,9 @@ from typing import List from AppAgents import FidelityAgent, GreeterAgent -from autogencap.runtime_factory import RuntimeFactory from autogencap.DebugLog import Info from autogencap.proto.CAP_pb2 import ActorInfo +from autogencap.runtime_factory import RuntimeFactory def list_agents(): diff --git a/samples/apps/cap/py/demo/single_threaded.py b/samples/apps/cap/py/demo/single_threaded.py index 3fa8015dbc48..f4c1fdfb633f 100644 --- a/samples/apps/cap/py/demo/single_threaded.py +++ b/samples/apps/cap/py/demo/single_threaded.py @@ -1,8 +1,8 @@ import _paths from AppAgents import GreeterAgent -from autogencap.runtime_factory import RuntimeFactory from autogencap.DebugLog import Error from autogencap.proto.CAP_pb2 import Ping +from autogencap.runtime_factory import RuntimeFactory def single_threaded_demo(): diff --git a/samples/apps/cap/py/demo/standalone/UserProxy.py b/samples/apps/cap/py/demo/standalone/UserProxy.py index 2deb48723f2c..c2eb4bf42385 100644 --- a/samples/apps/cap/py/demo/standalone/UserProxy.py +++ b/samples/apps/cap/py/demo/standalone/UserProxy.py @@ -2,9 +2,9 @@ import _paths from autogencap.ag_adapter.CAP2AG import CAP2AG -from autogencap.runtime_factory import RuntimeFactory from autogencap.Config import IGNORED_LOG_CONTEXTS from autogencap.DebugLog import Info +from autogencap.runtime_factory import RuntimeFactory from autogen import UserProxyAgent, config_list_from_json diff --git a/samples/apps/cap/py/demo/standalone/assistant.py b/samples/apps/cap/py/demo/standalone/assistant.py index d454da07a36b..162071e60898 100644 --- a/samples/apps/cap/py/demo/standalone/assistant.py +++ b/samples/apps/cap/py/demo/standalone/assistant.py @@ -2,8 +2,8 @@ import _paths from autogencap.ag_adapter.CAP2AG import CAP2AG -from autogencap.runtime_factory import RuntimeFactory from autogencap.DebugLog import Info +from autogencap.runtime_factory import RuntimeFactory from autogen import AssistantAgent, config_list_from_json diff --git a/samples/apps/cap/py/demo/standalone/user_proxy.py b/samples/apps/cap/py/demo/standalone/user_proxy.py index 18aeb733769f..d1183a7b7a6e 100644 --- a/samples/apps/cap/py/demo/standalone/user_proxy.py +++ b/samples/apps/cap/py/demo/standalone/user_proxy.py @@ -2,8 +2,8 @@ import _paths from autogencap.ag_adapter.agent import Agent -from autogencap.runtime_factory import RuntimeFactory from autogencap.Config import IGNORED_LOG_CONTEXTS +from autogencap.runtime_factory import RuntimeFactory from autogen import UserProxyAgent From 9f27b797bcf030ac8bd6491aa1471d179ba9acfb Mon Sep 17 00:00:00 2001 From: Rajan Date: Thu, 25 Jul 2024 20:55:02 -0400 Subject: [PATCH 06/29] pre-commit fix --- samples/apps/cap/py/autogencap/runtime_factory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/apps/cap/py/autogencap/runtime_factory.py b/samples/apps/cap/py/autogencap/runtime_factory.py index 0f10cbae8339..64d8d74643a5 100644 --- a/samples/apps/cap/py/autogencap/runtime_factory.py +++ b/samples/apps/cap/py/autogencap/runtime_factory.py @@ -38,7 +38,7 @@ def _initialize(cls): """ Static initialization method. """ - cls.register_runtime("ZMQ",ZMQRuntime()) + cls.register_runtime("ZMQ", ZMQRuntime()) # Static initialization RuntimeFactory._initialize() From 83d9ae0235cb0a79bb230bf8bc4a48d2b33bd113 Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 29 Jul 2024 11:28:35 -0400 Subject: [PATCH 07/29] pre-commit fixes and default runtime --- samples/apps/cap/py/autogencap/Constants.py | 1 + samples/apps/cap/py/autogencap/runtime_factory.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/samples/apps/cap/py/autogencap/Constants.py b/samples/apps/cap/py/autogencap/Constants.py index 8326d6753d35..2825af73def3 100644 --- a/samples/apps/cap/py/autogencap/Constants.py +++ b/samples/apps/cap/py/autogencap/Constants.py @@ -1,2 +1,3 @@ Termination_Topic: str = "Termination" Directory_Svc_Topic: str = "Directory_Svc" +ZMQ_Runtime: str = "ZMQ" \ No newline at end of file diff --git a/samples/apps/cap/py/autogencap/runtime_factory.py b/samples/apps/cap/py/autogencap/runtime_factory.py index 64d8d74643a5..c731691a1054 100644 --- a/samples/apps/cap/py/autogencap/runtime_factory.py +++ b/samples/apps/cap/py/autogencap/runtime_factory.py @@ -1,6 +1,7 @@ from autogencap.actor_runtime import IRuntime from autogencap.DebugLog import Error from autogencap.zmq_runtime import ZMQRuntime +from autogencap.Constants import ZMQ_Runtime class RuntimeFactory: @@ -9,8 +10,9 @@ class RuntimeFactory: """ Factory class for creating a runtime instance. """ + @staticmethod - def get_runtime(runtime_type) -> IRuntime: + def get_runtime(runtime_type: str = ZMQ_Runtime) -> IRuntime: """ Creates a runtime instance based on the runtime type. @@ -38,7 +40,8 @@ def _initialize(cls): """ Static initialization method. """ - cls.register_runtime("ZMQ", ZMQRuntime()) + cls.register_runtime(ZMQ_Runtime, ZMQRuntime()) + # Static initialization RuntimeFactory._initialize() From 0e5cb67521e97cdd46dad13bfb3254d00538392b Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 29 Jul 2024 12:27:24 -0400 Subject: [PATCH 08/29] pre-commit fixes --- samples/apps/cap/py/autogencap/Constants.py | 2 +- samples/apps/cap/py/autogencap/runtime_factory.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/apps/cap/py/autogencap/Constants.py b/samples/apps/cap/py/autogencap/Constants.py index 2825af73def3..217fcf45e619 100644 --- a/samples/apps/cap/py/autogencap/Constants.py +++ b/samples/apps/cap/py/autogencap/Constants.py @@ -1,3 +1,3 @@ Termination_Topic: str = "Termination" Directory_Svc_Topic: str = "Directory_Svc" -ZMQ_Runtime: str = "ZMQ" \ No newline at end of file +ZMQ_Runtime: str = "ZMQ" diff --git a/samples/apps/cap/py/autogencap/runtime_factory.py b/samples/apps/cap/py/autogencap/runtime_factory.py index c731691a1054..8e8a11ba26ea 100644 --- a/samples/apps/cap/py/autogencap/runtime_factory.py +++ b/samples/apps/cap/py/autogencap/runtime_factory.py @@ -1,7 +1,7 @@ from autogencap.actor_runtime import IRuntime +from autogencap.Constants import ZMQ_Runtime from autogencap.DebugLog import Error from autogencap.zmq_runtime import ZMQRuntime -from autogencap.Constants import ZMQ_Runtime class RuntimeFactory: From 7a593f96d37c05943edf744be8daefb604fb121f Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 29 Jul 2024 12:30:48 -0400 Subject: [PATCH 09/29] Rename constants --- samples/apps/cap/py/autogencap/{Constants.py => Constants_.py} | 0 samples/apps/cap/py/autogencap/DirectorySvc.py | 2 +- samples/apps/cap/py/autogencap/ag_adapter/AGActor.py | 2 +- samples/apps/cap/py/autogencap/runtime_factory.py | 2 +- samples/apps/cap/py/autogencap/zmq_runtime.py | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) rename samples/apps/cap/py/autogencap/{Constants.py => Constants_.py} (100%) diff --git a/samples/apps/cap/py/autogencap/Constants.py b/samples/apps/cap/py/autogencap/Constants_.py similarity index 100% rename from samples/apps/cap/py/autogencap/Constants.py rename to samples/apps/cap/py/autogencap/Constants_.py diff --git a/samples/apps/cap/py/autogencap/DirectorySvc.py b/samples/apps/cap/py/autogencap/DirectorySvc.py index acb3b6223df5..e280609ebbe5 100644 --- a/samples/apps/cap/py/autogencap/DirectorySvc.py +++ b/samples/apps/cap/py/autogencap/DirectorySvc.py @@ -8,7 +8,7 @@ from autogencap.ActorConnector import ActorConnector, ActorSender from autogencap.Broker import Broker from autogencap.Config import router_url, xpub_url, xsub_url -from autogencap.Constants import Directory_Svc_Topic +from autogencap.Constants_ import Directory_Svc_Topic from autogencap.DebugLog import Debug, Error, Info from autogencap.proto.CAP_pb2 import ( ActorInfo, diff --git a/samples/apps/cap/py/autogencap/ag_adapter/AGActor.py b/samples/apps/cap/py/autogencap/ag_adapter/AGActor.py index cc301f38e7e7..5e43750f671d 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/AGActor.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/AGActor.py @@ -1,7 +1,7 @@ import zmq from autogencap.Actor import Actor -from autogencap.Constants import Termination_Topic +from autogencap.Constants_ import Termination_Topic from autogencap.DebugLog import Debug diff --git a/samples/apps/cap/py/autogencap/runtime_factory.py b/samples/apps/cap/py/autogencap/runtime_factory.py index 8e8a11ba26ea..4fe4df7e0190 100644 --- a/samples/apps/cap/py/autogencap/runtime_factory.py +++ b/samples/apps/cap/py/autogencap/runtime_factory.py @@ -1,5 +1,5 @@ from autogencap.actor_runtime import IRuntime -from autogencap.Constants import ZMQ_Runtime +from autogencap.Constants_ import ZMQ_Runtime from autogencap.DebugLog import Error from autogencap.zmq_runtime import ZMQRuntime diff --git a/samples/apps/cap/py/autogencap/zmq_runtime.py b/samples/apps/cap/py/autogencap/zmq_runtime.py index 5735145c59e5..0ef8a9648418 100644 --- a/samples/apps/cap/py/autogencap/zmq_runtime.py +++ b/samples/apps/cap/py/autogencap/zmq_runtime.py @@ -7,7 +7,7 @@ from .actor_runtime import IRuntime from .ActorConnector import ActorConnector from .Broker import Broker -from .Constants import Termination_Topic +from .Constants_ import Termination_Topic from .DebugLog import Debug, Warn from .DirectorySvc import DirectorySvc from .proto.CAP_pb2 import ActorInfo, ActorInfoCollection From 7aef12630c378f433df36be764a79d65076c83a4 Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 29 Jul 2024 12:31:35 -0400 Subject: [PATCH 10/29] Rename Constants --- samples/apps/cap/py/autogencap/DirectorySvc.py | 2 +- samples/apps/cap/py/autogencap/ag_adapter/AGActor.py | 2 +- samples/apps/cap/py/autogencap/{Constants_.py => constants.py} | 0 samples/apps/cap/py/autogencap/runtime_factory.py | 2 +- samples/apps/cap/py/autogencap/zmq_runtime.py | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) rename samples/apps/cap/py/autogencap/{Constants_.py => constants.py} (100%) diff --git a/samples/apps/cap/py/autogencap/DirectorySvc.py b/samples/apps/cap/py/autogencap/DirectorySvc.py index e280609ebbe5..6057558c0b24 100644 --- a/samples/apps/cap/py/autogencap/DirectorySvc.py +++ b/samples/apps/cap/py/autogencap/DirectorySvc.py @@ -8,7 +8,7 @@ from autogencap.ActorConnector import ActorConnector, ActorSender from autogencap.Broker import Broker from autogencap.Config import router_url, xpub_url, xsub_url -from autogencap.Constants_ import Directory_Svc_Topic +from autogencap.constants import Directory_Svc_Topic from autogencap.DebugLog import Debug, Error, Info from autogencap.proto.CAP_pb2 import ( ActorInfo, diff --git a/samples/apps/cap/py/autogencap/ag_adapter/AGActor.py b/samples/apps/cap/py/autogencap/ag_adapter/AGActor.py index 5e43750f671d..6bd804e33e9e 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/AGActor.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/AGActor.py @@ -1,7 +1,7 @@ import zmq from autogencap.Actor import Actor -from autogencap.Constants_ import Termination_Topic +from autogencap.constants import Termination_Topic from autogencap.DebugLog import Debug diff --git a/samples/apps/cap/py/autogencap/Constants_.py b/samples/apps/cap/py/autogencap/constants.py similarity index 100% rename from samples/apps/cap/py/autogencap/Constants_.py rename to samples/apps/cap/py/autogencap/constants.py diff --git a/samples/apps/cap/py/autogencap/runtime_factory.py b/samples/apps/cap/py/autogencap/runtime_factory.py index 4fe4df7e0190..77fb091a248d 100644 --- a/samples/apps/cap/py/autogencap/runtime_factory.py +++ b/samples/apps/cap/py/autogencap/runtime_factory.py @@ -1,5 +1,5 @@ from autogencap.actor_runtime import IRuntime -from autogencap.Constants_ import ZMQ_Runtime +from autogencap.constants import ZMQ_Runtime from autogencap.DebugLog import Error from autogencap.zmq_runtime import ZMQRuntime diff --git a/samples/apps/cap/py/autogencap/zmq_runtime.py b/samples/apps/cap/py/autogencap/zmq_runtime.py index 0ef8a9648418..a8074fb48d3b 100644 --- a/samples/apps/cap/py/autogencap/zmq_runtime.py +++ b/samples/apps/cap/py/autogencap/zmq_runtime.py @@ -7,7 +7,7 @@ from .actor_runtime import IRuntime from .ActorConnector import ActorConnector from .Broker import Broker -from .Constants_ import Termination_Topic +from .constants import Termination_Topic from .DebugLog import Debug, Warn from .DirectorySvc import DirectorySvc from .proto.CAP_pb2 import ActorInfo, ActorInfoCollection From 81b1d92c7371321af0aa276282baa3f378f563bc Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 5 Aug 2024 18:41:05 -0400 Subject: [PATCH 11/29] Create interfaces for connectors --- .../apps/cap/py/autogencap/ActorConnector.py | 162 ----------------- .../apps/cap/py/autogencap/actor_connector.py | 45 +++++ .../apps/cap/py/autogencap/actor_runtime.py | 8 +- .../cap/py/autogencap/ag_adapter/AG2CAP.py | 2 +- ...toGenConnector.py => autogen_connector.py} | 6 +- ...atManager.py => cap_group_chat_manager.py} | 4 +- .../{DirectorySvc.py => zmq_directory_svc.py} | 23 +-- samples/apps/cap/py/autogencap/zmq_runtime.py | 172 +++++++++++++++++- .../py/demo/{AppAgents.py => app_agents.py} | 12 +- ...GroupDemo.py => cap_autogen_group_demo.py} | 2 +- .../cap/py/demo/standalone/directory_svc.py | 2 +- 11 files changed, 237 insertions(+), 201 deletions(-) delete mode 100644 samples/apps/cap/py/autogencap/ActorConnector.py create mode 100644 samples/apps/cap/py/autogencap/actor_connector.py rename samples/apps/cap/py/autogencap/ag_adapter/{AutoGenConnector.py => autogen_connector.py} (94%) rename samples/apps/cap/py/autogencap/ag_adapter/{CAPGroupChatManager.py => cap_group_chat_manager.py} (89%) rename samples/apps/cap/py/autogencap/{DirectorySvc.py => zmq_directory_svc.py} (91%) rename samples/apps/cap/py/demo/{AppAgents.py => app_agents.py} (95%) rename samples/apps/cap/py/demo/{CAPAutGenGroupDemo.py => cap_autogen_group_demo.py} (95%) diff --git a/samples/apps/cap/py/autogencap/ActorConnector.py b/samples/apps/cap/py/autogencap/ActorConnector.py deleted file mode 100644 index 1595f641fc83..000000000000 --- a/samples/apps/cap/py/autogencap/ActorConnector.py +++ /dev/null @@ -1,162 +0,0 @@ -# Agent_Sender takes a zmq context, Topic and creates a -# socket that can publish to that topic. It exposes this functionality -# using send_msg method -import time -import uuid -from typing import Any, Dict - -import zmq -from zmq.utils.monitor import recv_monitor_message - -from .Config import router_url, xpub_url, xsub_url -from .DebugLog import Debug, Error, Info - - -class ActorSender: - def __init__(self, context, topic): - self._context = context - self._topic = topic - self._connect_pub_socket() - - def _connect_pub_socket(self): - Debug("ActorSender", f"Connecting pub socket {self._topic}") - self._pub_socket = self._context.socket(zmq.PUB) - monitor = self._pub_socket.get_monitor_socket() - self._pub_socket.setsockopt(zmq.LINGER, 0) - self._pub_socket.connect(xsub_url) - # Monitor handshake on the pub socket - while monitor.poll(): - evt: Dict[str, Any] = {} - mon_evt = recv_monitor_message(monitor) - evt.update(mon_evt) - if evt["event"] == zmq.EVENT_HANDSHAKE_SUCCEEDED: - Debug("ActorSender", "Handshake received") - break - elif evt["event"] == zmq.EVENT_MONITOR_STOPPED: - Debug("ActorSender", "Monitor stopped") - break - self._pub_socket.disable_monitor() - monitor.close() - self._send_recv_router_msg() - - def _send_recv_router_msg(self): - # Send a request to the router and wait for a response - req_socket = self._context.socket(zmq.REQ) - req_socket.connect(router_url) - try: - Debug("ActorSender", "Broker Check Request Sent") - req_socket.send_string("Request") - _ = req_socket.recv_string() - Debug("ActorSender", "Broker Check Response Received") - finally: - req_socket.close() - - def send_txt_msg(self, msg): - Debug("ActorSender", f"[{self._topic}] send_txt_msg: {msg}") - self._pub_socket.send_multipart( - [self._topic.encode("utf8"), "text".encode("utf8"), "no_resp".encode("utf8"), msg.encode("utf8")] - ) - - def send_bin_msg(self, msg_type: str, msg): - Debug("ActorSender", f"[{self._topic}] send_bin_msg: {msg_type}") - self._pub_socket.send_multipart( - [self._topic.encode("utf8"), msg_type.encode("utf8"), "no_resp".encode("utf8"), msg] - ) - - def send_bin_request_msg(self, msg_type: str, msg, resp_topic: str): - Debug("ActorSender", f"[{self._topic}] send_bin_request_msg: {msg_type}") - self._pub_socket.send_multipart( - [self._topic.encode("utf8"), msg_type.encode("utf8"), resp_topic.encode("utf8"), msg] - ) - - def close(self): - self._pub_socket.close() - - -class ActorConnector: - def __init__(self, context, topic): - self._context = context - self._topic = topic - self._connect_sub_socket() - self._sender = ActorSender(context, topic) - time.sleep(0.1) # Wait for the socket to connect - - def _connect_sub_socket(self): - self._resp_socket = self._context.socket(zmq.SUB) - monitor = self._resp_socket.get_monitor_socket() - self._resp_socket.setsockopt(zmq.LINGER, 0) - self._resp_socket.setsockopt(zmq.RCVTIMEO, 250) - self._resp_socket.connect(xpub_url) - self._resp_topic = str(uuid.uuid4()) - Debug("ActorConnector", f"subscribe to: {self._resp_topic}") - self._resp_socket.setsockopt_string(zmq.SUBSCRIBE, f"{self._resp_topic}") - while monitor.poll(): - evt: Dict[str, Any] = {} - mon_evt = recv_monitor_message(monitor) - evt.update(mon_evt) - Debug("ActorConnector", evt) - if evt["event"] == zmq.EVENT_MONITOR_STOPPED or evt["event"] == zmq.EVENT_HANDSHAKE_SUCCEEDED: - Debug("ActorConnector", "Handshake received (Or Monitor stopped)") - break - self._resp_socket.disable_monitor() - monitor.close() - self._send_recv_router_msg() - - def _send_recv_router_msg(self): - # Send a request to the router and wait for a response - req_socket = self._context.socket(zmq.REQ) - req_socket.connect(router_url) - try: - Debug("ActorConnector", "Broker Check Request Sent") - req_socket.send_string("Request") - _ = req_socket.recv_string() - Debug("ActorConnector", "Broker Check Response Received") - finally: - req_socket.close() - - def send_txt_msg(self, msg): - self._sender.send_txt_msg(msg) - - def send_bin_msg(self, msg_type: str, msg): - self._sender.send_bin_msg(msg_type, msg) - - def send_proto_msg(self, msg): - bin_msg = msg.SerializeToString() - class_type = type(msg) - self._sender.send_bin_msg(class_type.__name__, bin_msg) - - def send_recv_proto_msg(self, msg, num_attempts=5): - bin_msg = msg.SerializeToString() - class_type = type(msg) - return self.send_recv_msg(class_type.__name, bin_msg, num_attempts) - - def send_recv_msg(self, msg_type: str, msg, num_attempts=5): - original_timeout: int = 0 - if num_attempts == -1: - original_timeout = self._resp_socket.getsockopt(zmq.RCVTIMEO) - self._resp_socket.setsockopt(zmq.RCVTIMEO, 1000) - - try: - self._sender.send_bin_request_msg(msg_type, msg, self._resp_topic) - while num_attempts == -1 or num_attempts > 0: - try: - topic, resp_msg_type, _, resp = self._resp_socket.recv_multipart() - return topic, resp_msg_type, resp - except zmq.Again: - Debug( - "ActorConnector", - f"{self._topic}: No response received. retry_count={num_attempts}, max_retry={num_attempts}", - ) - time.sleep(0.01) - if num_attempts != -1: - num_attempts -= 1 - finally: - if num_attempts == -1: - self._resp_socket.setsockopt(zmq.RCVTIMEO, original_timeout) - - Error("ActorConnector", f"{self._topic}: No response received. Giving up.") - return None, None, None - - def close(self): - self._sender.close() - self._resp_socket.close() diff --git a/samples/apps/cap/py/autogencap/actor_connector.py b/samples/apps/cap/py/autogencap/actor_connector.py new file mode 100644 index 000000000000..15dcf1319a90 --- /dev/null +++ b/samples/apps/cap/py/autogencap/actor_connector.py @@ -0,0 +1,45 @@ +# Agent_Sender takes a zmq context, Topic and creates a +# socket that can publish to that topic. It exposes this functionality +# using send_msg method +from abc import ABC, abstractmethod + + +from .DebugLog import Info + +class IActorSender(ABC): + @abstractmethod + def send_txt_msg(self, msg): + pass + + @abstractmethod + def send_bin_msg(self, msg_type: str, msg): + pass + + @abstractmethod + def send_recv_msg(self, msg_type: str, msg, resp_topic: str): + pass + + @abstractmethod + def close(self): + pass + +class IActorConnector(ABC): + @abstractmethod + def send_txt_msg(self, msg): + pass + + def send_bin_msg(self, msg_type: str, msg): + pass + + def send_proto_msg(self, msg): + pass + + def send_recv_proto_msg(self, msg, num_attempts=5): + pass + + def send_recv_msg(self, msg_type: str, msg, num_attempts=5): + pass + + def close(self): + pass + diff --git a/samples/apps/cap/py/autogencap/actor_runtime.py b/samples/apps/cap/py/autogencap/actor_runtime.py index 027b20905877..ad6423553a99 100644 --- a/samples/apps/cap/py/autogencap/actor_runtime.py +++ b/samples/apps/cap/py/autogencap/actor_runtime.py @@ -2,7 +2,7 @@ from typing import List from .Actor import Actor -from .ActorConnector import ActorConnector +from .actor_connector import IActorConnector from .proto.CAP_pb2 import ActorInfo @@ -20,15 +20,15 @@ def disconnect(self): pass @abstractmethod - def find_by_topic(self, topic: str) -> ActorConnector: + def find_by_topic(self, topic: str) -> IActorConnector: pass @abstractmethod - def find_by_name(self, name: str) -> ActorConnector: + def find_by_name(self, name: str) -> IActorConnector: pass @abstractmethod - def find_termination(self) -> ActorConnector: + def find_termination(self) -> IActorConnector: pass @abstractmethod diff --git a/samples/apps/cap/py/autogencap/ag_adapter/AG2CAP.py b/samples/apps/cap/py/autogencap/ag_adapter/AG2CAP.py index 4b5f79aefd85..38abf0a8a098 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/AG2CAP.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/AG2CAP.py @@ -4,7 +4,7 @@ from autogen import Agent, ConversableAgent from ..actor_runtime import IRuntime -from .AutoGenConnector import AutoGenConnector +from .autogen_connector import AutoGenConnector class AG2CAP(ConversableAgent): diff --git a/samples/apps/cap/py/autogencap/ag_adapter/AutoGenConnector.py b/samples/apps/cap/py/autogencap/ag_adapter/autogen_connector.py similarity index 94% rename from samples/apps/cap/py/autogencap/ag_adapter/AutoGenConnector.py rename to samples/apps/cap/py/autogencap/ag_adapter/autogen_connector.py index 47b70ea7a130..97efd18b2e57 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/AutoGenConnector.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/autogen_connector.py @@ -3,7 +3,7 @@ from autogen import Agent -from ..ActorConnector import ActorConnector +from ..actor_runtime import IActorConnector from ..proto.Autogen_pb2 import GenReplyReq, GenReplyResp, PrepChat, ReceiveReq, Terminate @@ -13,8 +13,8 @@ class AutoGenConnector: to/from the CAP system. """ - def __init__(self, cap_sender: ActorConnector): - self._can_channel: ActorConnector = cap_sender + def __init__(self, cap_sender: IActorConnector): + self._can_channel: IActorConnector = cap_sender def close(self): """ diff --git a/samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChatManager.py b/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat_manager.py similarity index 89% rename from samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChatManager.py rename to samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat_manager.py index e71e6aecddf8..fca2094da9c7 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChatManager.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat_manager.py @@ -1,7 +1,7 @@ import time from autogen import GroupChatManager -from autogencap.ActorConnector import ActorConnector +from autogencap.actor_runtime import IActorConnector from autogencap.ag_adapter.CAP2AG import CAP2AG from autogencap.ag_adapter.CAPGroupChat import CAPGroupChat @@ -25,7 +25,7 @@ def __init__(self, groupchat: CAPGroupChat, llm_config: dict, network: IRuntime) def initiate_chat(self, txt_msg: str) -> None: self._ensemble.connect() - user_proxy_conn: ActorConnector = self._ensemble.find_by_name(self._cap_group_chat.chat_initiator) + user_proxy_conn: IActorConnector = self._ensemble.find_by_name(self._cap_group_chat.chat_initiator) user_proxy_conn.send_txt_msg(txt_msg) self._wait_for_user_exit() diff --git a/samples/apps/cap/py/autogencap/DirectorySvc.py b/samples/apps/cap/py/autogencap/zmq_directory_svc.py similarity index 91% rename from samples/apps/cap/py/autogencap/DirectorySvc.py rename to samples/apps/cap/py/autogencap/zmq_directory_svc.py index 6057558c0b24..9ccb6551778c 100644 --- a/samples/apps/cap/py/autogencap/DirectorySvc.py +++ b/samples/apps/cap/py/autogencap/zmq_directory_svc.py @@ -2,10 +2,11 @@ import threading import time +from autogencap.zmq_runtime import ZMQActorConnector import zmq from autogencap.Actor import Actor -from autogencap.ActorConnector import ActorConnector, ActorSender +from autogencap.zmq_runtime import ZMQActorSender from autogencap.Broker import Broker from autogencap.Config import router_url, xpub_url, xsub_url from autogencap.constants import Directory_Svc_Topic @@ -29,7 +30,7 @@ # service more generic and powerful -class DirectoryActor(Actor): +class ZMQDirectoryActor(Actor): def __init__(self, topic: str, name: str): super().__init__(topic, name) self._registered_actors = {} @@ -50,7 +51,7 @@ def _on_ping_msg(self, topic: str, msg_type: str, msg: bytes, sender_topic: str) Info("DirectorySvc", f"Ping received: {sender_topic}") pong = Pong() serialized_msg = pong.SerializeToString() - sender_connection = ActorSender(self._context, sender_topic) + sender_connection = ZMQActorSender(self._context, sender_topic) sender_connection.send_bin_msg(Pong.__name__, serialized_msg) def _on_actor_registration_msg(self, topic: str, msg_type: str, msg: bytes, sender_topic: str): @@ -67,7 +68,7 @@ def _on_actor_registration_msg(self, topic: str, msg_type: str, msg: bytes, send else: self._registered_actors[name] = actor_reg.actor_info - sender_connection = ActorSender(self._context, sender_topic) + sender_connection = ZMQActorSender(self._context, sender_topic) serialized_msg = err.SerializeToString() sender_connection.send_bin_msg(ErrorMsg.__name__, serialized_msg) @@ -96,16 +97,16 @@ def _on_actor_lookup_msg(self, topic: str, msg_type: str, msg: bytes, sender_top else: Error("DirectorySvc", f"Actor not found: {actor_lookup.actor_info.name}") - sender_connection = ActorSender(self._context, sender_topic) + sender_connection = ZMQActorSender(self._context, sender_topic) serialized_msg = actor_lookup_resp.SerializeToString() sender_connection.send_bin_msg(ActorLookupResponse.__name__, serialized_msg) -class DirectorySvc: +class ZMQDirectorySvc: def __init__(self, context: zmq.Context = zmq.Context()): self._context: zmq.Context = context - self._directory_connector: ActorConnector = None - self._directory_actor: DirectoryActor = None + self._directory_connector: ZMQActorConnector = None + self._directory_actor: ZMQDirectoryActor = None def _no_other_directory(self) -> bool: Debug("DirectorySvc", "Pinging existing DirectorySvc") @@ -118,9 +119,9 @@ def _no_other_directory(self) -> bool: def start(self): Debug("DirectorySvc", "Starting.") - self._directory_connector = ActorConnector(self._context, Directory_Svc_Topic) + self._directory_connector = ZMQActorConnector(self._context, Directory_Svc_Topic) if self._no_other_directory(): - self._directory_actor = DirectoryActor(Directory_Svc_Topic, "Directory Service") + self._directory_actor = ZMQDirectoryActor(Directory_Svc_Topic, "Directory Service") self._directory_actor.on_start(self._context) Info("DirectorySvc", "Directory service started.") else: @@ -176,7 +177,7 @@ def main(): proxy: Broker = Broker(context) proxy.start() # Start the directory service - directory_svc = DirectorySvc(context) + directory_svc = ZMQDirectorySvc(context) directory_svc.start() # # How do you register an actor? # directory_svc.register_actor_by_name("my_actor") diff --git a/samples/apps/cap/py/autogencap/zmq_runtime.py b/samples/apps/cap/py/autogencap/zmq_runtime.py index a8074fb48d3b..3ff6586f17ee 100644 --- a/samples/apps/cap/py/autogencap/zmq_runtime.py +++ b/samples/apps/cap/py/autogencap/zmq_runtime.py @@ -1,18 +1,172 @@ import time -from typing import List +from typing import Any, Dict, List +from autogencap.Config import router_url, xpub_url, xsub_url +from autogencap.DebugLog import Debug, Error +from autogencap.actor_connector import IActorSender import zmq +from zmq.utils.monitor import recv_monitor_message from .Actor import Actor from .actor_runtime import IRuntime -from .ActorConnector import ActorConnector +from .actor_connector import IActorConnector from .Broker import Broker from .constants import Termination_Topic from .DebugLog import Debug, Warn -from .DirectorySvc import DirectorySvc +from .zmq_directory_svc import ZMQDirectorySvc from .proto.CAP_pb2 import ActorInfo, ActorInfoCollection +class ZMQActorSender(IActorSender): + def __init__(self, context, topic): + self._context = context + self._topic = topic + self._connect_pub_socket() + + def _connect_pub_socket(self): + Debug("ActorSender", f"Connecting pub socket {self._topic}") + self._pub_socket = self._context.socket(zmq.PUB) + monitor = self._pub_socket.get_monitor_socket() + self._pub_socket.setsockopt(zmq.LINGER, 0) + self._pub_socket.connect(xsub_url) + # Monitor handshake on the pub socket + while monitor.poll(): + evt: Dict[str, Any] = {} + mon_evt = recv_monitor_message(monitor) + evt.update(mon_evt) + if evt["event"] == zmq.EVENT_HANDSHAKE_SUCCEEDED: + Debug("ActorSender", "Handshake received") + break + elif evt["event"] == zmq.EVENT_MONITOR_STOPPED: + Debug("ActorSender", "Monitor stopped") + break + self._pub_socket.disable_monitor() + monitor.close() + self._send_recv_router_msg() + + def _send_recv_router_msg(self): + # Send a request to the router and wait for a response + req_socket = self._context.socket(zmq.REQ) + req_socket.connect(router_url) + try: + Debug("ActorSender", "Broker Check Request Sent") + req_socket.send_string("Request") + _ = req_socket.recv_string() + Debug("ActorSender", "Broker Check Response Received") + finally: + req_socket.close() + + def send_txt_msg(self, msg): + Debug("ActorSender", f"[{self._topic}] send_txt_msg: {msg}") + self._pub_socket.send_multipart( + [self._topic.encode("utf8"), "text".encode("utf8"), "no_resp".encode("utf8"), msg.encode("utf8")] + ) + + def send_bin_msg(self, msg_type: str, msg): + Debug("ActorSender", f"[{self._topic}] send_bin_msg: {msg_type}") + self._pub_socket.send_multipart( + [self._topic.encode("utf8"), msg_type.encode("utf8"), "no_resp".encode("utf8"), msg] + ) + + def send_recv_msg(self, msg_type: str, msg, resp_topic: str): + Debug("ActorSender", f"[{self._topic}] send_bin_request_msg: {msg_type}") + self._pub_socket.send_multipart( + [self._topic.encode("utf8"), msg_type.encode("utf8"), resp_topic.encode("utf8"), msg] + ) + + def close(self): + self._pub_socket.close() + + +class ZMQActorConnector(IActorConnector): + def __init__(self, context, topic): + self._context = context + self._topic = topic + self._connect_sub_socket() + self._sender = ZMQActorSender(context, topic) + time.sleep(0.1) # Wait for the socket to connect + + def _connect_sub_socket(self): + self._resp_socket = self._context.socket(zmq.SUB) + monitor = self._resp_socket.get_monitor_socket() + self._resp_socket.setsockopt(zmq.LINGER, 0) + self._resp_socket.setsockopt(zmq.RCVTIMEO, 250) + self._resp_socket.connect(xpub_url) + self._resp_topic = str(uuid.uuid4()) + Debug("ActorConnector", f"subscribe to: {self._resp_topic}") + self._resp_socket.setsockopt_string(zmq.SUBSCRIBE, f"{self._resp_topic}") + while monitor.poll(): + evt: Dict[str, Any] = {} + mon_evt = recv_monitor_message(monitor) + evt.update(mon_evt) + Debug("ActorConnector", evt) + if evt["event"] == zmq.EVENT_MONITOR_STOPPED or evt["event"] == zmq.EVENT_HANDSHAKE_SUCCEEDED: + Debug("ActorConnector", "Handshake received (Or Monitor stopped)") + break + self._resp_socket.disable_monitor() + monitor.close() + self._send_recv_router_msg() + + def _send_recv_router_msg(self): + # Send a request to the router and wait for a response + req_socket = self._context.socket(zmq.REQ) + req_socket.connect(router_url) + try: + Debug("ActorConnector", "Broker Check Request Sent") + req_socket.send_string("Request") + _ = req_socket.recv_string() + Debug("ActorConnector", "Broker Check Response Received") + finally: + req_socket.close() + + def send_txt_msg(self, msg): + self._sender.send_txt_msg(msg) + + def send_bin_msg(self, msg_type: str, msg): + self._sender.send_bin_msg(msg_type, msg) + + def send_proto_msg(self, msg): + bin_msg = msg.SerializeToString() + class_type = type(msg) + self._sender.send_bin_msg(class_type.__name__, bin_msg) + + def send_recv_proto_msg(self, msg, num_attempts=5): + bin_msg = msg.SerializeToString() + class_type = type(msg) + return self.send_recv_msg(class_type.__name, bin_msg, num_attempts) + + def send_recv_msg(self, msg_type: str, msg, num_attempts=5): + original_timeout: int = 0 + if num_attempts == -1: + original_timeout = self._resp_socket.getsockopt(zmq.RCVTIMEO) + self._resp_socket.setsockopt(zmq.RCVTIMEO, 1000) + + try: + self._sender.send_recv_msg(msg_type, msg, self._resp_topic) + while num_attempts == -1 or num_attempts > 0: + try: + topic, resp_msg_type, _, resp = self._resp_socket.recv_multipart() + return topic, resp_msg_type, resp + except zmq.Again: + Debug( + "ActorConnector", + f"{self._topic}: No response received. retry_count={num_attempts}, max_retry={num_attempts}", + ) + time.sleep(0.01) + if num_attempts != -1: + num_attempts -= 1 + finally: + if num_attempts == -1: + self._resp_socket.setsockopt(zmq.RCVTIMEO, original_timeout) + + Error("ActorConnector", f"{self._topic}: No response received. Giving up.") + return None, None, None + + def close(self): + self._sender.close() + self._resp_socket.close() + + class ZMQRuntime(IRuntime): def __init__(self, name: str = "Local Actor Network", start_broker: bool = True): self.local_actors = {} @@ -20,7 +174,7 @@ def __init__(self, name: str = "Local Actor Network", start_broker: bool = True) self._context: zmq.Context = zmq.Context() self._start_broker: bool = start_broker self._broker: Broker = None - self._directory_svc: DirectorySvc = None + self._directory_svc: ZMQDirectorySvc = None def __str__(self): return f"{self.name}" @@ -32,7 +186,7 @@ def _init_runtime(self): self._start_broker = False # Don't try to start the broker again self._broker = None if self._directory_svc is None: - self._directory_svc = DirectorySvc(self._context) + self._directory_svc = ZMQDirectorySvc(self._context) self._directory_svc.start() time.sleep(0.25) # Process queued thread events in Broker and Directory @@ -58,10 +212,10 @@ def disconnect(self): if self._broker: self._broker.stop() - def find_by_topic(self, topic: str) -> ActorConnector: - return ActorConnector(self._context, topic) + def find_by_topic(self, topic: str) -> IActorConnector: + return ZMQActorConnector(self._context, topic) - def find_by_name(self, name: str) -> ActorConnector: + def find_by_name(self, name: str) -> IActorConnector: actor_info: ActorInfo = self._directory_svc.lookup_actor_by_name(name) if actor_info is None: Warn("Local_Actor_Network", f"{name}, not found in the network.") @@ -69,7 +223,7 @@ def find_by_name(self, name: str) -> ActorConnector: Debug("Local_Actor_Network", f"[{name}] found in the network.") return self.find_by_topic(name) - def find_termination(self) -> ActorConnector: + def find_termination(self) -> IActorConnector: termination_topic: str = Termination_Topic return self.find_by_topic(termination_topic) diff --git a/samples/apps/cap/py/demo/AppAgents.py b/samples/apps/cap/py/demo/app_agents.py similarity index 95% rename from samples/apps/cap/py/demo/AppAgents.py rename to samples/apps/cap/py/demo/app_agents.py index f13e4b471fd6..1e69c81572d7 100644 --- a/samples/apps/cap/py/demo/AppAgents.py +++ b/samples/apps/cap/py/demo/app_agents.py @@ -6,10 +6,8 @@ from autogencap.Actor import Actor from autogencap.actor_runtime import IRuntime -from autogencap.ActorConnector import ActorConnector +from autogencap.actor_connector import IActorConnector from autogencap.DebugLog import Debug, Info, shorten -from autogencap.runtime_factory import RuntimeFactory - class GreeterAgent(Actor): """ @@ -132,10 +130,10 @@ def __init__( description="This is the personal assistant, who knows how to connect to the other agents and get information from them.", ): super().__init__(agent_name, description) - self.fidelity: ActorConnector = None - self.financial_planner: ActorConnector = None - self.quant: ActorConnector = None - self.risk_manager: ActorConnector = None + self.fidelity: IActorConnector = None + self.financial_planner: IActorConnector = None + self.quant: IActorConnector = None + self.risk_manager: IActorConnector = None def on_connect(self, network: IRuntime): """ diff --git a/samples/apps/cap/py/demo/CAPAutGenGroupDemo.py b/samples/apps/cap/py/demo/cap_autogen_group_demo.py similarity index 95% rename from samples/apps/cap/py/demo/CAPAutGenGroupDemo.py rename to samples/apps/cap/py/demo/cap_autogen_group_demo.py index 93a28c753ca5..16740f1cb5df 100644 --- a/samples/apps/cap/py/demo/CAPAutGenGroupDemo.py +++ b/samples/apps/cap/py/demo/cap_autogen_group_demo.py @@ -1,5 +1,5 @@ from autogencap.ag_adapter.CAPGroupChat import CAPGroupChat -from autogencap.ag_adapter.CAPGroupChatManager import CAPGroupChatManager +from autogencap.ag_adapter.cap_group_chat_manager import CAPGroupChatManager from autogencap.DebugLog import Info from autogencap.runtime_factory import RuntimeFactory diff --git a/samples/apps/cap/py/demo/standalone/directory_svc.py b/samples/apps/cap/py/demo/standalone/directory_svc.py index 3320b96e573e..974c697de995 100644 --- a/samples/apps/cap/py/demo/standalone/directory_svc.py +++ b/samples/apps/cap/py/demo/standalone/directory_svc.py @@ -1,5 +1,5 @@ import _paths -from autogencap.DirectorySvc import main +from autogencap.zmq_directory_svc import main if __name__ == "__main__": main() From 1dd77b81b13012dbef547fbdd23c70bc29ef0adc Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 5 Aug 2024 18:53:21 -0400 Subject: [PATCH 12/29] pre-commit fixes --- samples/apps/cap/py/autogencap/actor_connector.py | 11 +++++------ .../ag_adapter/{CAPGroupChat.py => cap_group_chat.py} | 0 .../autogencap/ag_adapter/cap_group_chat_manager.py | 2 +- samples/apps/cap/py/autogencap/zmq_directory_svc.py | 3 +-- samples/apps/cap/py/autogencap/zmq_runtime.py | 11 ++++++----- samples/apps/cap/py/demo/app_agents.py | 3 ++- samples/apps/cap/py/demo/cap_autogen_group_demo.py | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) rename samples/apps/cap/py/autogencap/ag_adapter/{CAPGroupChat.py => cap_group_chat.py} (100%) diff --git a/samples/apps/cap/py/autogencap/actor_connector.py b/samples/apps/cap/py/autogencap/actor_connector.py index 15dcf1319a90..a3813d63b0aa 100644 --- a/samples/apps/cap/py/autogencap/actor_connector.py +++ b/samples/apps/cap/py/autogencap/actor_connector.py @@ -4,7 +4,6 @@ from abc import ABC, abstractmethod -from .DebugLog import Info class IActorSender(ABC): @abstractmethod @@ -23,23 +22,23 @@ def send_recv_msg(self, msg_type: str, msg, resp_topic: str): def close(self): pass + class IActorConnector(ABC): @abstractmethod def send_txt_msg(self, msg): pass - + def send_bin_msg(self, msg_type: str, msg): pass - + def send_proto_msg(self, msg): pass - + def send_recv_proto_msg(self, msg, num_attempts=5): pass - + def send_recv_msg(self, msg_type: str, msg, num_attempts=5): pass def close(self): pass - diff --git a/samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChat.py b/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat.py similarity index 100% rename from samples/apps/cap/py/autogencap/ag_adapter/CAPGroupChat.py rename to samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat.py diff --git a/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat_manager.py b/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat_manager.py index fca2094da9c7..d1523f065ed9 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat_manager.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat_manager.py @@ -3,7 +3,7 @@ from autogen import GroupChatManager from autogencap.actor_runtime import IActorConnector from autogencap.ag_adapter.CAP2AG import CAP2AG -from autogencap.ag_adapter.CAPGroupChat import CAPGroupChat +from autogencap.ag_adapter.cap_group_chat import CAPGroupChat from ..actor_runtime import IRuntime diff --git a/samples/apps/cap/py/autogencap/zmq_directory_svc.py b/samples/apps/cap/py/autogencap/zmq_directory_svc.py index 9ccb6551778c..ef1a845562c0 100644 --- a/samples/apps/cap/py/autogencap/zmq_directory_svc.py +++ b/samples/apps/cap/py/autogencap/zmq_directory_svc.py @@ -2,11 +2,9 @@ import threading import time -from autogencap.zmq_runtime import ZMQActorConnector import zmq from autogencap.Actor import Actor -from autogencap.zmq_runtime import ZMQActorSender from autogencap.Broker import Broker from autogencap.Config import router_url, xpub_url, xsub_url from autogencap.constants import Directory_Svc_Topic @@ -25,6 +23,7 @@ Error as ErrorMsg, ) from autogencap.utility import report_error_msg +from autogencap.zmq_runtime import ZMQActorConnector, ZMQActorSender # TODO (Future DirectorySv PR) use actor description, network_id, other properties to make directory # service more generic and powerful diff --git a/samples/apps/cap/py/autogencap/zmq_runtime.py b/samples/apps/cap/py/autogencap/zmq_runtime.py index 3ff6586f17ee..d59a1428b5ad 100644 --- a/samples/apps/cap/py/autogencap/zmq_runtime.py +++ b/samples/apps/cap/py/autogencap/zmq_runtime.py @@ -1,20 +1,21 @@ import time from typing import Any, Dict, List -from autogencap.Config import router_url, xpub_url, xsub_url -from autogencap.DebugLog import Debug, Error -from autogencap.actor_connector import IActorSender import zmq from zmq.utils.monitor import recv_monitor_message +from autogencap.actor_connector import IActorSender +from autogencap.Config import router_url, xpub_url, xsub_url +from autogencap.DebugLog import Debug, Error + from .Actor import Actor -from .actor_runtime import IRuntime from .actor_connector import IActorConnector +from .actor_runtime import IRuntime from .Broker import Broker from .constants import Termination_Topic from .DebugLog import Debug, Warn -from .zmq_directory_svc import ZMQDirectorySvc from .proto.CAP_pb2 import ActorInfo, ActorInfoCollection +from .zmq_directory_svc import ZMQDirectorySvc class ZMQActorSender(IActorSender): diff --git a/samples/apps/cap/py/demo/app_agents.py b/samples/apps/cap/py/demo/app_agents.py index 1e69c81572d7..8f91de551141 100644 --- a/samples/apps/cap/py/demo/app_agents.py +++ b/samples/apps/cap/py/demo/app_agents.py @@ -5,10 +5,11 @@ """ from autogencap.Actor import Actor -from autogencap.actor_runtime import IRuntime from autogencap.actor_connector import IActorConnector +from autogencap.actor_runtime import IRuntime from autogencap.DebugLog import Debug, Info, shorten + class GreeterAgent(Actor): """ Prints message to screen diff --git a/samples/apps/cap/py/demo/cap_autogen_group_demo.py b/samples/apps/cap/py/demo/cap_autogen_group_demo.py index 16740f1cb5df..0942a78e0624 100644 --- a/samples/apps/cap/py/demo/cap_autogen_group_demo.py +++ b/samples/apps/cap/py/demo/cap_autogen_group_demo.py @@ -1,5 +1,5 @@ -from autogencap.ag_adapter.CAPGroupChat import CAPGroupChat from autogencap.ag_adapter.cap_group_chat_manager import CAPGroupChatManager +from autogencap.ag_adapter.cap_group_chat import CAPGroupChat from autogencap.DebugLog import Info from autogencap.runtime_factory import RuntimeFactory From 5e3ffadc9b063d6f8efdf84bd8bcb1f43a201ca1 Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 5 Aug 2024 19:02:13 -0400 Subject: [PATCH 13/29] pre-commit fixes --- samples/apps/cap/py/autogencap/actor_connector.py | 1 - samples/apps/cap/py/autogencap/zmq_runtime.py | 3 +-- samples/apps/cap/py/demo/cap_autogen_group_demo.py | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/samples/apps/cap/py/autogencap/actor_connector.py b/samples/apps/cap/py/autogencap/actor_connector.py index a3813d63b0aa..240c9625cae2 100644 --- a/samples/apps/cap/py/autogencap/actor_connector.py +++ b/samples/apps/cap/py/autogencap/actor_connector.py @@ -4,7 +4,6 @@ from abc import ABC, abstractmethod - class IActorSender(ABC): @abstractmethod def send_txt_msg(self, msg): diff --git a/samples/apps/cap/py/autogencap/zmq_runtime.py b/samples/apps/cap/py/autogencap/zmq_runtime.py index d59a1428b5ad..ec5dcfa531ee 100644 --- a/samples/apps/cap/py/autogencap/zmq_runtime.py +++ b/samples/apps/cap/py/autogencap/zmq_runtime.py @@ -1,6 +1,6 @@ import time from typing import Any, Dict, List - +import uuid import zmq from zmq.utils.monitor import recv_monitor_message @@ -13,7 +13,6 @@ from .actor_runtime import IRuntime from .Broker import Broker from .constants import Termination_Topic -from .DebugLog import Debug, Warn from .proto.CAP_pb2 import ActorInfo, ActorInfoCollection from .zmq_directory_svc import ZMQDirectorySvc diff --git a/samples/apps/cap/py/demo/cap_autogen_group_demo.py b/samples/apps/cap/py/demo/cap_autogen_group_demo.py index 0942a78e0624..aab35d7bb859 100644 --- a/samples/apps/cap/py/demo/cap_autogen_group_demo.py +++ b/samples/apps/cap/py/demo/cap_autogen_group_demo.py @@ -1,5 +1,5 @@ -from autogencap.ag_adapter.cap_group_chat_manager import CAPGroupChatManager from autogencap.ag_adapter.cap_group_chat import CAPGroupChat +from autogencap.ag_adapter.cap_group_chat_manager import CAPGroupChatManager from autogencap.DebugLog import Info from autogencap.runtime_factory import RuntimeFactory From 5480efb3ac6ea02564c2f6610b087b17dde73e41 Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 5 Aug 2024 19:05:28 -0400 Subject: [PATCH 14/29] pre-commit fixes --- samples/apps/cap/py/autogencap/zmq_runtime.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/samples/apps/cap/py/autogencap/zmq_runtime.py b/samples/apps/cap/py/autogencap/zmq_runtime.py index ec5dcfa531ee..c10bff3c1baf 100644 --- a/samples/apps/cap/py/autogencap/zmq_runtime.py +++ b/samples/apps/cap/py/autogencap/zmq_runtime.py @@ -1,12 +1,13 @@ import time -from typing import Any, Dict, List import uuid +from typing import Any, Dict, List + import zmq from zmq.utils.monitor import recv_monitor_message from autogencap.actor_connector import IActorSender from autogencap.Config import router_url, xpub_url, xsub_url -from autogencap.DebugLog import Debug, Error +from autogencap.DebugLog import Debug, Error, Warn from .Actor import Actor from .actor_connector import IActorConnector From a89675ee4cb029ae2d7b3cd7746f3f06008abf4e Mon Sep 17 00:00:00 2001 From: Rajan Date: Wed, 7 Aug 2024 17:58:36 -0400 Subject: [PATCH 15/29] lower case file names --- samples/apps/cap/py/autogencap/Actor.py | 4 ++-- samples/apps/cap/py/autogencap/Broker.py | 4 ++-- .../apps/cap/py/autogencap/actor_runtime.py | 2 +- .../ag_adapter/{AGActor.py => ag_actor.py} | 4 ++-- .../ag_adapter/{AG2CAP.py => ag_to_cap.py} | 0 .../cap/py/autogencap/ag_adapter/agent.py | 4 ++-- .../autogencap/ag_adapter/cap_group_chat.py | 4 ++-- .../ag_adapter/cap_group_chat_manager.py | 2 +- .../ag_adapter/{CAPPair.py => cap_pair.py} | 2 +- .../ag_adapter/{CAP2AG.py => cap_to_ag.py} | 6 +++--- .../autogencap/{DebugLog.py => debug_log.py} | 6 +++--- .../apps/cap/py/autogencap/runtime_factory.py | 2 +- samples/apps/cap/py/autogencap/utility.py | 2 +- .../cap/py/autogencap/zmq_directory_svc.py | 8 +++---- samples/apps/cap/py/autogencap/zmq_runtime.py | 8 +++---- samples/apps/cap/py/demo/App.py | 21 +++++++++---------- .../cap/py/demo/{AGDemo.py => ag_demo.py} | 0 ...GroupChatDemo.py => ag_group_chat_demo.py} | 0 samples/apps/cap/py/demo/app_agents.py | 4 ++-- .../cap/py/demo/cap_autogen_group_demo.py | 2 +- ...enPairDemo.py => cap_autogen_pair_demo.py} | 8 +++---- ...plexActorDemo.py => complex_actor_demo.py} | 0 samples/apps/cap/py/demo/list_agents.py | 2 +- ...RemoteAGDemo.py => remote_autogen_demo.py} | 0 ...impleActorDemo.py => simple_actor_demo.py} | 0 samples/apps/cap/py/demo/single_threaded.py | 2 +- samples/apps/cap/py/demo/standalone/Broker.py | 2 +- .../apps/cap/py/demo/standalone/UserProxy.py | 6 +++--- .../apps/cap/py/demo/standalone/assistant.py | 4 ++-- .../apps/cap/py/demo/standalone/user_proxy.py | 2 +- samples/apps/cap/py/demo/zmq_tests.py | 2 +- 31 files changed, 56 insertions(+), 57 deletions(-) rename samples/apps/cap/py/autogencap/ag_adapter/{AGActor.py => ag_actor.py} (81%) rename samples/apps/cap/py/autogencap/ag_adapter/{AG2CAP.py => ag_to_cap.py} (100%) rename samples/apps/cap/py/autogencap/ag_adapter/{CAPPair.py => cap_pair.py} (95%) rename samples/apps/cap/py/autogencap/ag_adapter/{CAP2AG.py => cap_to_ag.py} (98%) rename samples/apps/cap/py/autogencap/{DebugLog.py => debug_log.py} (94%) rename samples/apps/cap/py/demo/{AGDemo.py => ag_demo.py} (100%) rename samples/apps/cap/py/demo/{AGGroupChatDemo.py => ag_group_chat_demo.py} (100%) rename samples/apps/cap/py/demo/{CAPAutoGenPairDemo.py => cap_autogen_pair_demo.py} (85%) rename samples/apps/cap/py/demo/{ComplexActorDemo.py => complex_actor_demo.py} (100%) rename samples/apps/cap/py/demo/{RemoteAGDemo.py => remote_autogen_demo.py} (100%) rename samples/apps/cap/py/demo/{SimpleActorDemo.py => simple_actor_demo.py} (100%) diff --git a/samples/apps/cap/py/autogencap/Actor.py b/samples/apps/cap/py/autogencap/Actor.py index 778fd7634c21..4f1cfab89b23 100644 --- a/samples/apps/cap/py/autogencap/Actor.py +++ b/samples/apps/cap/py/autogencap/Actor.py @@ -3,8 +3,8 @@ import zmq -from .Config import xpub_url -from .DebugLog import Debug, Error, Info +from .config import xpub_url +from .debug_log import Debug, Error, Info class Actor: diff --git a/samples/apps/cap/py/autogencap/Broker.py b/samples/apps/cap/py/autogencap/Broker.py index 2fd430d1bc70..39da094203cb 100644 --- a/samples/apps/cap/py/autogencap/Broker.py +++ b/samples/apps/cap/py/autogencap/Broker.py @@ -3,8 +3,8 @@ import zmq -from autogencap.Config import router_url, xpub_url, xsub_url -from autogencap.DebugLog import Debug, Info, Warn +from autogencap.config import router_url, xpub_url, xsub_url +from autogencap.debug_log import Debug, Info, Warn class Broker: diff --git a/samples/apps/cap/py/autogencap/actor_runtime.py b/samples/apps/cap/py/autogencap/actor_runtime.py index ad6423553a99..ad3b25566030 100644 --- a/samples/apps/cap/py/autogencap/actor_runtime.py +++ b/samples/apps/cap/py/autogencap/actor_runtime.py @@ -1,7 +1,7 @@ from abc import ABC, abstractmethod from typing import List -from .Actor import Actor +from .actor import Actor from .actor_connector import IActorConnector from .proto.CAP_pb2 import ActorInfo diff --git a/samples/apps/cap/py/autogencap/ag_adapter/AGActor.py b/samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py similarity index 81% rename from samples/apps/cap/py/autogencap/ag_adapter/AGActor.py rename to samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py index 6bd804e33e9e..accb6acf6df4 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/AGActor.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py @@ -1,8 +1,8 @@ import zmq -from autogencap.Actor import Actor +from autogencap.actor import Actor from autogencap.constants import Termination_Topic -from autogencap.DebugLog import Debug +from autogencap.debug_log import Debug class AGActor(Actor): diff --git a/samples/apps/cap/py/autogencap/ag_adapter/AG2CAP.py b/samples/apps/cap/py/autogencap/ag_adapter/ag_to_cap.py similarity index 100% rename from samples/apps/cap/py/autogencap/ag_adapter/AG2CAP.py rename to samples/apps/cap/py/autogencap/ag_adapter/ag_to_cap.py diff --git a/samples/apps/cap/py/autogencap/ag_adapter/agent.py b/samples/apps/cap/py/autogencap/ag_adapter/agent.py index 219bb7297c18..aa47554bd0cc 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/agent.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/agent.py @@ -2,8 +2,8 @@ from autogen import ConversableAgent -from ..DebugLog import Info, Warn -from .CAP2AG import CAP2AG +from ..debug_log import Info, Warn +from .cap_to_ag import CAP2AG class Agent: diff --git a/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat.py b/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat.py index caf2a11a66f1..889f90f8fffb 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat.py @@ -1,8 +1,8 @@ from typing import List from autogen import Agent, AssistantAgent, GroupChat -from autogencap.ag_adapter.AG2CAP import AG2CAP -from autogencap.ag_adapter.CAP2AG import CAP2AG +from autogencap.ag_adapter.ag_to_cap import AG2CAP +from autogencap.ag_adapter.cap_to_ag import CAP2AG from ..actor_runtime import IRuntime diff --git a/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat_manager.py b/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat_manager.py index d1523f065ed9..7031c5a98cee 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat_manager.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat_manager.py @@ -2,7 +2,7 @@ from autogen import GroupChatManager from autogencap.actor_runtime import IActorConnector -from autogencap.ag_adapter.CAP2AG import CAP2AG +from autogencap.ag_adapter.cap_to_ag import CAP2AG from autogencap.ag_adapter.cap_group_chat import CAPGroupChat from ..actor_runtime import IRuntime diff --git a/samples/apps/cap/py/autogencap/ag_adapter/CAPPair.py b/samples/apps/cap/py/autogencap/ag_adapter/cap_pair.py similarity index 95% rename from samples/apps/cap/py/autogencap/ag_adapter/CAPPair.py rename to samples/apps/cap/py/autogencap/ag_adapter/cap_pair.py index 4a87a742b5dd..85dda2bca830 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/CAPPair.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/cap_pair.py @@ -1,4 +1,4 @@ -from autogencap.ag_adapter.CAP2AG import CAP2AG +from autogencap.ag_adapter.cap_to_ag import CAP2AG class CAPPair: diff --git a/samples/apps/cap/py/autogencap/ag_adapter/CAP2AG.py b/samples/apps/cap/py/autogencap/ag_adapter/cap_to_ag.py similarity index 98% rename from samples/apps/cap/py/autogencap/ag_adapter/CAP2AG.py rename to samples/apps/cap/py/autogencap/ag_adapter/cap_to_ag.py index 0dd3b7be5ced..4f94936b37e3 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/CAP2AG.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/cap_to_ag.py @@ -5,10 +5,10 @@ from autogen import ConversableAgent from ..actor_runtime import IRuntime -from ..DebugLog import Debug, Error, Info, Warn, shorten +from ..debug_log import Debug, Error, Info, Warn, shorten from ..proto.Autogen_pb2 import GenReplyReq, GenReplyResp, PrepChat, ReceiveReq, Terminate -from .AG2CAP import AG2CAP -from .AGActor import AGActor +from .ag_to_cap import AG2CAP +from .ag_actor import AGActor class CAP2AG(AGActor): diff --git a/samples/apps/cap/py/autogencap/DebugLog.py b/samples/apps/cap/py/autogencap/debug_log.py similarity index 94% rename from samples/apps/cap/py/autogencap/DebugLog.py rename to samples/apps/cap/py/autogencap/debug_log.py index f8a3f209ee3a..000457b6a013 100644 --- a/samples/apps/cap/py/autogencap/DebugLog.py +++ b/samples/apps/cap/py/autogencap/debug_log.py @@ -3,7 +3,7 @@ from termcolor import colored -import autogencap.Config as Config +import autogencap.config as config # Define log levels as constants DEBUG = 0 @@ -22,9 +22,9 @@ def __init__(self): def Log(self, level, context, msg): # Check if the current level meets the threshold - if level >= Config.LOG_LEVEL: # Use the LOG_LEVEL from the Config module + if level >= config.LOG_LEVEL: # Use the LOG_LEVEL from the Config module # Check if the context is in the list of ignored contexts - if context in Config.IGNORED_LOG_CONTEXTS: + if context in config.IGNORED_LOG_CONTEXTS: return with self._lock: self.WriteLog(level, context, msg) diff --git a/samples/apps/cap/py/autogencap/runtime_factory.py b/samples/apps/cap/py/autogencap/runtime_factory.py index 77fb091a248d..c585653e1324 100644 --- a/samples/apps/cap/py/autogencap/runtime_factory.py +++ b/samples/apps/cap/py/autogencap/runtime_factory.py @@ -1,6 +1,6 @@ from autogencap.actor_runtime import IRuntime from autogencap.constants import ZMQ_Runtime -from autogencap.DebugLog import Error +from autogencap.debug_log import Error from autogencap.zmq_runtime import ZMQRuntime diff --git a/samples/apps/cap/py/autogencap/utility.py b/samples/apps/cap/py/autogencap/utility.py index 2083e565ffe9..317e835e9ea7 100644 --- a/samples/apps/cap/py/autogencap/utility.py +++ b/samples/apps/cap/py/autogencap/utility.py @@ -1,4 +1,4 @@ -from autogencap.DebugLog import Error +from autogencap.debug_log import Error from autogencap.proto.CAP_pb2 import Error as ErrorMsg from autogencap.proto.CAP_pb2 import ErrorCode diff --git a/samples/apps/cap/py/autogencap/zmq_directory_svc.py b/samples/apps/cap/py/autogencap/zmq_directory_svc.py index ef1a845562c0..031815e98e9c 100644 --- a/samples/apps/cap/py/autogencap/zmq_directory_svc.py +++ b/samples/apps/cap/py/autogencap/zmq_directory_svc.py @@ -4,11 +4,11 @@ import zmq -from autogencap.Actor import Actor -from autogencap.Broker import Broker -from autogencap.Config import router_url, xpub_url, xsub_url +from autogencap.actor import Actor +from autogencap.broker import Broker +from autogencap.config import router_url, xpub_url, xsub_url from autogencap.constants import Directory_Svc_Topic -from autogencap.DebugLog import Debug, Error, Info +from autogencap.debug_log import Debug, Error, Info from autogencap.proto.CAP_pb2 import ( ActorInfo, ActorInfoCollection, diff --git a/samples/apps/cap/py/autogencap/zmq_runtime.py b/samples/apps/cap/py/autogencap/zmq_runtime.py index c10bff3c1baf..fdf0cb3d719a 100644 --- a/samples/apps/cap/py/autogencap/zmq_runtime.py +++ b/samples/apps/cap/py/autogencap/zmq_runtime.py @@ -6,13 +6,13 @@ from zmq.utils.monitor import recv_monitor_message from autogencap.actor_connector import IActorSender -from autogencap.Config import router_url, xpub_url, xsub_url -from autogencap.DebugLog import Debug, Error, Warn +from autogencap.config import router_url, xpub_url, xsub_url +from autogencap.debug_log import Debug, Error, Warn -from .Actor import Actor +from .actor import Actor from .actor_connector import IActorConnector from .actor_runtime import IRuntime -from .Broker import Broker +from .broker import Broker from .constants import Termination_Topic from .proto.CAP_pb2 import ActorInfo, ActorInfoCollection from .zmq_directory_svc import ZMQDirectorySvc diff --git a/samples/apps/cap/py/demo/App.py b/samples/apps/cap/py/demo/App.py index 19987ab75ca1..99f48e54cafb 100644 --- a/samples/apps/cap/py/demo/App.py +++ b/samples/apps/cap/py/demo/App.py @@ -5,16 +5,15 @@ import argparse import _paths -import autogencap.Config as Config -import autogencap.DebugLog as DebugLog -from AGDemo import ag_demo -from AGGroupChatDemo import ag_groupchat_demo -from CAPAutGenGroupDemo import cap_ag_group_demo -from CAPAutoGenPairDemo import cap_ag_pair_demo -from ComplexActorDemo import complex_actor_demo +import autogencap.config as config +import autogencap.debug_log as debug_log +from ag_demo import ag_demo +from ag_group_chat_demo import ag_groupchat_demo +from cap_autogen_group_demo import cap_ag_group_demo +from cap_autogen_pair_demo import cap_ag_pair_demo +from complex_actor_demo import complex_actor_demo from list_agents import list_agents -from RemoteAGDemo import remote_ag_demo -from SimpleActorDemo import simple_actor_demo +from simple_actor_demo import simple_actor_demo from single_threaded import single_threaded_demo #################################################################################################### @@ -28,8 +27,8 @@ def parse_args(): args = parser.parse_args() # Set the log level # Print log level string based on names in debug_log.py - print(f"Log level: {DebugLog.LEVEL_NAMES[args.log_level]}") - Config.LOG_LEVEL = args.log_level + print(f"Log level: {debug_log.LEVEL_NAMES[args.log_level]}") + config.LOG_LEVEL = args.log_level # Config.IGNORED_LOG_CONTEXTS.extend(["BROKER"]) diff --git a/samples/apps/cap/py/demo/AGDemo.py b/samples/apps/cap/py/demo/ag_demo.py similarity index 100% rename from samples/apps/cap/py/demo/AGDemo.py rename to samples/apps/cap/py/demo/ag_demo.py diff --git a/samples/apps/cap/py/demo/AGGroupChatDemo.py b/samples/apps/cap/py/demo/ag_group_chat_demo.py similarity index 100% rename from samples/apps/cap/py/demo/AGGroupChatDemo.py rename to samples/apps/cap/py/demo/ag_group_chat_demo.py diff --git a/samples/apps/cap/py/demo/app_agents.py b/samples/apps/cap/py/demo/app_agents.py index 8f91de551141..2377ea1aee59 100644 --- a/samples/apps/cap/py/demo/app_agents.py +++ b/samples/apps/cap/py/demo/app_agents.py @@ -4,10 +4,10 @@ to retrieve information. """ -from autogencap.Actor import Actor +from autogencap.actor import Actor from autogencap.actor_connector import IActorConnector from autogencap.actor_runtime import IRuntime -from autogencap.DebugLog import Debug, Info, shorten +from autogencap.debug_log import Debug, Info, shorten class GreeterAgent(Actor): diff --git a/samples/apps/cap/py/demo/cap_autogen_group_demo.py b/samples/apps/cap/py/demo/cap_autogen_group_demo.py index aab35d7bb859..4bc8411019b1 100644 --- a/samples/apps/cap/py/demo/cap_autogen_group_demo.py +++ b/samples/apps/cap/py/demo/cap_autogen_group_demo.py @@ -1,6 +1,6 @@ from autogencap.ag_adapter.cap_group_chat import CAPGroupChat from autogencap.ag_adapter.cap_group_chat_manager import CAPGroupChatManager -from autogencap.DebugLog import Info +from autogencap.debug_log import Info from autogencap.runtime_factory import RuntimeFactory from autogen import AssistantAgent, UserProxyAgent, config_list_from_json diff --git a/samples/apps/cap/py/demo/CAPAutoGenPairDemo.py b/samples/apps/cap/py/demo/cap_autogen_pair_demo.py similarity index 85% rename from samples/apps/cap/py/demo/CAPAutoGenPairDemo.py rename to samples/apps/cap/py/demo/cap_autogen_pair_demo.py index 77323ddf8707..eac1f0e40208 100644 --- a/samples/apps/cap/py/demo/CAPAutoGenPairDemo.py +++ b/samples/apps/cap/py/demo/cap_autogen_pair_demo.py @@ -1,15 +1,15 @@ import time -import autogencap.DebugLog as DebugLog -from autogencap.ag_adapter.CAPPair import CAPPair -from autogencap.DebugLog import ConsoleLogger, Info +import autogencap.debug_log as debug_log +from autogencap.ag_adapter.cap_pair import CAPPair +from autogencap.debug_log import ConsoleLogger, Info from autogencap.runtime_factory import RuntimeFactory from autogen import AssistantAgent, UserProxyAgent, config_list_from_json def cap_ag_pair_demo(): - DebugLog.LOGGER = ConsoleLogger(use_color=False) + debug_log.LOGGER = ConsoleLogger(use_color=False) config_list = config_list_from_json(env_or_file="OAI_CONFIG_LIST") assistant = AssistantAgent("assistant", llm_config={"config_list": config_list}) diff --git a/samples/apps/cap/py/demo/ComplexActorDemo.py b/samples/apps/cap/py/demo/complex_actor_demo.py similarity index 100% rename from samples/apps/cap/py/demo/ComplexActorDemo.py rename to samples/apps/cap/py/demo/complex_actor_demo.py diff --git a/samples/apps/cap/py/demo/list_agents.py b/samples/apps/cap/py/demo/list_agents.py index ca02006df2b7..7adfa833b343 100644 --- a/samples/apps/cap/py/demo/list_agents.py +++ b/samples/apps/cap/py/demo/list_agents.py @@ -2,7 +2,7 @@ from typing import List from AppAgents import FidelityAgent, GreeterAgent -from autogencap.DebugLog import Info +from autogencap.debug_log import Info from autogencap.proto.CAP_pb2 import ActorInfo from autogencap.runtime_factory import RuntimeFactory diff --git a/samples/apps/cap/py/demo/RemoteAGDemo.py b/samples/apps/cap/py/demo/remote_autogen_demo.py similarity index 100% rename from samples/apps/cap/py/demo/RemoteAGDemo.py rename to samples/apps/cap/py/demo/remote_autogen_demo.py diff --git a/samples/apps/cap/py/demo/SimpleActorDemo.py b/samples/apps/cap/py/demo/simple_actor_demo.py similarity index 100% rename from samples/apps/cap/py/demo/SimpleActorDemo.py rename to samples/apps/cap/py/demo/simple_actor_demo.py diff --git a/samples/apps/cap/py/demo/single_threaded.py b/samples/apps/cap/py/demo/single_threaded.py index f4c1fdfb633f..c74bd1043f17 100644 --- a/samples/apps/cap/py/demo/single_threaded.py +++ b/samples/apps/cap/py/demo/single_threaded.py @@ -1,6 +1,6 @@ import _paths from AppAgents import GreeterAgent -from autogencap.DebugLog import Error +from autogencap.debug_log import Error from autogencap.proto.CAP_pb2 import Ping from autogencap.runtime_factory import RuntimeFactory diff --git a/samples/apps/cap/py/demo/standalone/Broker.py b/samples/apps/cap/py/demo/standalone/Broker.py index f61064eb8e55..a7062554e7aa 100644 --- a/samples/apps/cap/py/demo/standalone/Broker.py +++ b/samples/apps/cap/py/demo/standalone/Broker.py @@ -1,5 +1,5 @@ import _paths -from autogencap.Broker import main +from autogencap.broker import main if __name__ == "__main__": main() diff --git a/samples/apps/cap/py/demo/standalone/UserProxy.py b/samples/apps/cap/py/demo/standalone/UserProxy.py index c2eb4bf42385..ece4b86820de 100644 --- a/samples/apps/cap/py/demo/standalone/UserProxy.py +++ b/samples/apps/cap/py/demo/standalone/UserProxy.py @@ -1,9 +1,9 @@ import time import _paths -from autogencap.ag_adapter.CAP2AG import CAP2AG -from autogencap.Config import IGNORED_LOG_CONTEXTS -from autogencap.DebugLog import Info +from autogencap.ag_adapter.cap_to_ag import CAP2AG +from autogencap.config import IGNORED_LOG_CONTEXTS +from autogencap.debug_log import Info from autogencap.runtime_factory import RuntimeFactory from autogen import UserProxyAgent, config_list_from_json diff --git a/samples/apps/cap/py/demo/standalone/assistant.py b/samples/apps/cap/py/demo/standalone/assistant.py index 162071e60898..bb2ce19fea09 100644 --- a/samples/apps/cap/py/demo/standalone/assistant.py +++ b/samples/apps/cap/py/demo/standalone/assistant.py @@ -1,8 +1,8 @@ import time import _paths -from autogencap.ag_adapter.CAP2AG import CAP2AG -from autogencap.DebugLog import Info +from autogencap.ag_adapter.cap_to_ag import CAP2AG +from autogencap.debug_log import Info from autogencap.runtime_factory import RuntimeFactory from autogen import AssistantAgent, config_list_from_json diff --git a/samples/apps/cap/py/demo/standalone/user_proxy.py b/samples/apps/cap/py/demo/standalone/user_proxy.py index d1183a7b7a6e..8acf39704588 100644 --- a/samples/apps/cap/py/demo/standalone/user_proxy.py +++ b/samples/apps/cap/py/demo/standalone/user_proxy.py @@ -2,7 +2,7 @@ import _paths from autogencap.ag_adapter.agent import Agent -from autogencap.Config import IGNORED_LOG_CONTEXTS +from autogencap.config import IGNORED_LOG_CONTEXTS from autogencap.runtime_factory import RuntimeFactory from autogen import UserProxyAgent diff --git a/samples/apps/cap/py/demo/zmq_tests.py b/samples/apps/cap/py/demo/zmq_tests.py index 8550ce6c2c8e..cef0780a890e 100644 --- a/samples/apps/cap/py/demo/zmq_tests.py +++ b/samples/apps/cap/py/demo/zmq_tests.py @@ -4,7 +4,7 @@ import _paths import zmq -from autogencap.Config import dealer_url, router_url, xpub_url, xsub_url +from autogencap.config import dealer_url, router_url, xpub_url, xsub_url from zmq.utils.monitor import recv_monitor_message From 16ab32cd649d9546bc53056f9c381eea8b53043a Mon Sep 17 00:00:00 2001 From: Rajan Date: Wed, 7 Aug 2024 18:16:31 -0400 Subject: [PATCH 16/29] rename files to lower _case --- samples/apps/cap/py/autogencap/{Actor.py => _actor.py} | 0 samples/apps/cap/py/autogencap/{Broker.py => _broker.py} | 0 samples/apps/cap/py/autogencap/actor_runtime.py | 2 +- samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py | 2 +- samples/apps/cap/py/autogencap/zmq_directory_svc.py | 4 ++-- samples/apps/cap/py/autogencap/zmq_runtime.py | 4 ++-- samples/apps/cap/py/demo/standalone/{Broker.py => _broker.py} | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) rename samples/apps/cap/py/autogencap/{Actor.py => _actor.py} (100%) rename samples/apps/cap/py/autogencap/{Broker.py => _broker.py} (100%) rename samples/apps/cap/py/demo/standalone/{Broker.py => _broker.py} (59%) diff --git a/samples/apps/cap/py/autogencap/Actor.py b/samples/apps/cap/py/autogencap/_actor.py similarity index 100% rename from samples/apps/cap/py/autogencap/Actor.py rename to samples/apps/cap/py/autogencap/_actor.py diff --git a/samples/apps/cap/py/autogencap/Broker.py b/samples/apps/cap/py/autogencap/_broker.py similarity index 100% rename from samples/apps/cap/py/autogencap/Broker.py rename to samples/apps/cap/py/autogencap/_broker.py diff --git a/samples/apps/cap/py/autogencap/actor_runtime.py b/samples/apps/cap/py/autogencap/actor_runtime.py index ad3b25566030..03d67d632e30 100644 --- a/samples/apps/cap/py/autogencap/actor_runtime.py +++ b/samples/apps/cap/py/autogencap/actor_runtime.py @@ -1,7 +1,7 @@ from abc import ABC, abstractmethod from typing import List -from .actor import Actor +from ._actor import Actor from .actor_connector import IActorConnector from .proto.CAP_pb2 import ActorInfo diff --git a/samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py b/samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py index accb6acf6df4..98144191e545 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py @@ -1,6 +1,6 @@ import zmq -from autogencap.actor import Actor +from autogencap._actor import Actor from autogencap.constants import Termination_Topic from autogencap.debug_log import Debug diff --git a/samples/apps/cap/py/autogencap/zmq_directory_svc.py b/samples/apps/cap/py/autogencap/zmq_directory_svc.py index 031815e98e9c..80417247f510 100644 --- a/samples/apps/cap/py/autogencap/zmq_directory_svc.py +++ b/samples/apps/cap/py/autogencap/zmq_directory_svc.py @@ -4,8 +4,8 @@ import zmq -from autogencap.actor import Actor -from autogencap.broker import Broker +from autogencap._actor import Actor +from autogencap._broker import Broker from autogencap.config import router_url, xpub_url, xsub_url from autogencap.constants import Directory_Svc_Topic from autogencap.debug_log import Debug, Error, Info diff --git a/samples/apps/cap/py/autogencap/zmq_runtime.py b/samples/apps/cap/py/autogencap/zmq_runtime.py index fdf0cb3d719a..cc8faf951b0c 100644 --- a/samples/apps/cap/py/autogencap/zmq_runtime.py +++ b/samples/apps/cap/py/autogencap/zmq_runtime.py @@ -9,10 +9,10 @@ from autogencap.config import router_url, xpub_url, xsub_url from autogencap.debug_log import Debug, Error, Warn -from .actor import Actor +from ._actor import Actor from .actor_connector import IActorConnector from .actor_runtime import IRuntime -from .broker import Broker +from ._broker import Broker from .constants import Termination_Topic from .proto.CAP_pb2 import ActorInfo, ActorInfoCollection from .zmq_directory_svc import ZMQDirectorySvc diff --git a/samples/apps/cap/py/demo/standalone/Broker.py b/samples/apps/cap/py/demo/standalone/_broker.py similarity index 59% rename from samples/apps/cap/py/demo/standalone/Broker.py rename to samples/apps/cap/py/demo/standalone/_broker.py index a7062554e7aa..b6693b6aa477 100644 --- a/samples/apps/cap/py/demo/standalone/Broker.py +++ b/samples/apps/cap/py/demo/standalone/_broker.py @@ -1,5 +1,5 @@ import _paths -from autogencap.broker import main +from autogencap._broker import main if __name__ == "__main__": main() From ce37d8ea8a89b1e2cff0a50361cfb0b7eb94a1ea Mon Sep 17 00:00:00 2001 From: Rajan Date: Wed, 7 Aug 2024 18:17:13 -0400 Subject: [PATCH 17/29] rename files to _lowercase --- samples/apps/cap/py/demo/{App.py => _app.py} | 0 samples/apps/cap/py/demo/app_agents.py | 2 +- .../apps/cap/py/demo/standalone/UserProxy.py | 58 ------------------- 3 files changed, 1 insertion(+), 59 deletions(-) rename samples/apps/cap/py/demo/{App.py => _app.py} (100%) delete mode 100644 samples/apps/cap/py/demo/standalone/UserProxy.py diff --git a/samples/apps/cap/py/demo/App.py b/samples/apps/cap/py/demo/_app.py similarity index 100% rename from samples/apps/cap/py/demo/App.py rename to samples/apps/cap/py/demo/_app.py diff --git a/samples/apps/cap/py/demo/app_agents.py b/samples/apps/cap/py/demo/app_agents.py index 2377ea1aee59..eb9df9fa941e 100644 --- a/samples/apps/cap/py/demo/app_agents.py +++ b/samples/apps/cap/py/demo/app_agents.py @@ -4,7 +4,7 @@ to retrieve information. """ -from autogencap.actor import Actor +from autogencap._actor import Actor from autogencap.actor_connector import IActorConnector from autogencap.actor_runtime import IRuntime from autogencap.debug_log import Debug, Info, shorten diff --git a/samples/apps/cap/py/demo/standalone/UserProxy.py b/samples/apps/cap/py/demo/standalone/UserProxy.py deleted file mode 100644 index ece4b86820de..000000000000 --- a/samples/apps/cap/py/demo/standalone/UserProxy.py +++ /dev/null @@ -1,58 +0,0 @@ -import time - -import _paths -from autogencap.ag_adapter.cap_to_ag import CAP2AG -from autogencap.config import IGNORED_LOG_CONTEXTS -from autogencap.debug_log import Info -from autogencap.runtime_factory import RuntimeFactory - -from autogen import UserProxyAgent, config_list_from_json - - -# Starts the Broker and the Assistant. The UserProxy is started separately. -class StandaloneUserProxy: - def __init__(self): - pass - - def run(self): - print("Running the StandaloneUserProxy") - - user_proxy = UserProxyAgent( - "user_proxy", - code_execution_config={"work_dir": "coding"}, - is_termination_msg=lambda x: "TERMINATE" in x.get("content"), - ) - # Composable Agent Network adapter - ensemble = RuntimeFactory.get_runtime("ZMQ") - user_proxy_adptr = CAP2AG(ag_agent=user_proxy, the_other_name="assistant", init_chat=True, self_recursive=True) - ensemble.register(user_proxy_adptr) - ensemble.connect() - - # Send a message to the user_proxy - user_proxy_conn = ensemble.find_by_name("user_proxy") - example = "Plot a chart of MSFT daily closing prices for last 1 Month." - print(f"Example: {example}") - try: - user_input = input("Please enter your command: ") - if user_input == "": - user_input = example - print(f"Sending: {user_input}") - user_proxy_conn.send_txt_msg(user_input) - - # Hang around for a while - while user_proxy_adptr.run: - time.sleep(0.5) - except KeyboardInterrupt: - print("Interrupted by user, shutting down.") - ensemble.disconnect() - Info("StandaloneUserProxy", "App Exit") - - -def main(): - IGNORED_LOG_CONTEXTS.extend(["BROKER", "DirectorySvc"]) - assistant = StandaloneUserProxy() - assistant.run() - - -if __name__ == "__main__": - main() From 3d7209c5165c8f53ec7a0206986cc57fe4edcee1 Mon Sep 17 00:00:00 2001 From: Rajan Date: Wed, 7 Aug 2024 18:20:28 -0400 Subject: [PATCH 18/29] removed _ --- samples/apps/cap/py/autogencap/{_actor.py => actor.py} | 0 samples/apps/cap/py/autogencap/actor_runtime.py | 2 +- samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py | 2 +- samples/apps/cap/py/autogencap/{_broker.py => broker.py} | 0 samples/apps/cap/py/autogencap/zmq_directory_svc.py | 4 ++-- samples/apps/cap/py/autogencap/zmq_runtime.py | 4 ++-- samples/apps/cap/py/demo/{_app.py => app.py} | 0 samples/apps/cap/py/demo/app_agents.py | 2 +- samples/apps/cap/py/demo/standalone/{_broker.py => broker.py} | 2 +- 9 files changed, 8 insertions(+), 8 deletions(-) rename samples/apps/cap/py/autogencap/{_actor.py => actor.py} (100%) rename samples/apps/cap/py/autogencap/{_broker.py => broker.py} (100%) rename samples/apps/cap/py/demo/{_app.py => app.py} (100%) rename samples/apps/cap/py/demo/standalone/{_broker.py => broker.py} (59%) diff --git a/samples/apps/cap/py/autogencap/_actor.py b/samples/apps/cap/py/autogencap/actor.py similarity index 100% rename from samples/apps/cap/py/autogencap/_actor.py rename to samples/apps/cap/py/autogencap/actor.py diff --git a/samples/apps/cap/py/autogencap/actor_runtime.py b/samples/apps/cap/py/autogencap/actor_runtime.py index 03d67d632e30..ad3b25566030 100644 --- a/samples/apps/cap/py/autogencap/actor_runtime.py +++ b/samples/apps/cap/py/autogencap/actor_runtime.py @@ -1,7 +1,7 @@ from abc import ABC, abstractmethod from typing import List -from ._actor import Actor +from .actor import Actor from .actor_connector import IActorConnector from .proto.CAP_pb2 import ActorInfo diff --git a/samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py b/samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py index 98144191e545..accb6acf6df4 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py @@ -1,6 +1,6 @@ import zmq -from autogencap._actor import Actor +from autogencap.actor import Actor from autogencap.constants import Termination_Topic from autogencap.debug_log import Debug diff --git a/samples/apps/cap/py/autogencap/_broker.py b/samples/apps/cap/py/autogencap/broker.py similarity index 100% rename from samples/apps/cap/py/autogencap/_broker.py rename to samples/apps/cap/py/autogencap/broker.py diff --git a/samples/apps/cap/py/autogencap/zmq_directory_svc.py b/samples/apps/cap/py/autogencap/zmq_directory_svc.py index 80417247f510..031815e98e9c 100644 --- a/samples/apps/cap/py/autogencap/zmq_directory_svc.py +++ b/samples/apps/cap/py/autogencap/zmq_directory_svc.py @@ -4,8 +4,8 @@ import zmq -from autogencap._actor import Actor -from autogencap._broker import Broker +from autogencap.actor import Actor +from autogencap.broker import Broker from autogencap.config import router_url, xpub_url, xsub_url from autogencap.constants import Directory_Svc_Topic from autogencap.debug_log import Debug, Error, Info diff --git a/samples/apps/cap/py/autogencap/zmq_runtime.py b/samples/apps/cap/py/autogencap/zmq_runtime.py index cc8faf951b0c..fdf0cb3d719a 100644 --- a/samples/apps/cap/py/autogencap/zmq_runtime.py +++ b/samples/apps/cap/py/autogencap/zmq_runtime.py @@ -9,10 +9,10 @@ from autogencap.config import router_url, xpub_url, xsub_url from autogencap.debug_log import Debug, Error, Warn -from ._actor import Actor +from .actor import Actor from .actor_connector import IActorConnector from .actor_runtime import IRuntime -from ._broker import Broker +from .broker import Broker from .constants import Termination_Topic from .proto.CAP_pb2 import ActorInfo, ActorInfoCollection from .zmq_directory_svc import ZMQDirectorySvc diff --git a/samples/apps/cap/py/demo/_app.py b/samples/apps/cap/py/demo/app.py similarity index 100% rename from samples/apps/cap/py/demo/_app.py rename to samples/apps/cap/py/demo/app.py diff --git a/samples/apps/cap/py/demo/app_agents.py b/samples/apps/cap/py/demo/app_agents.py index eb9df9fa941e..2377ea1aee59 100644 --- a/samples/apps/cap/py/demo/app_agents.py +++ b/samples/apps/cap/py/demo/app_agents.py @@ -4,7 +4,7 @@ to retrieve information. """ -from autogencap._actor import Actor +from autogencap.actor import Actor from autogencap.actor_connector import IActorConnector from autogencap.actor_runtime import IRuntime from autogencap.debug_log import Debug, Info, shorten diff --git a/samples/apps/cap/py/demo/standalone/_broker.py b/samples/apps/cap/py/demo/standalone/broker.py similarity index 59% rename from samples/apps/cap/py/demo/standalone/_broker.py rename to samples/apps/cap/py/demo/standalone/broker.py index b6693b6aa477..a7062554e7aa 100644 --- a/samples/apps/cap/py/demo/standalone/_broker.py +++ b/samples/apps/cap/py/demo/standalone/broker.py @@ -1,5 +1,5 @@ import _paths -from autogencap._broker import main +from autogencap.broker import main if __name__ == "__main__": main() From b4e3f93f5b6b9f670d0b6ef878bd2d98b1e474e4 Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 21 Oct 2024 02:07:45 -0400 Subject: [PATCH 19/29] Refactored to make Actor zmq agnostic --- samples/apps/cap/py/autogencap/Config.py | 1 + samples/apps/cap/py/autogencap/actor.py | 73 +++---- .../apps/cap/py/autogencap/actor_connector.py | 34 +-- .../apps/cap/py/autogencap/actor_runtime.py | 71 ++++++- .../cap/py/autogencap/ag_adapter/ag_actor.py | 11 +- .../ag_adapter/autogen_connector.py | 2 +- .../ag_adapter/cap_group_chat_manager.py | 12 +- .../cap/py/autogencap/ag_adapter/cap_to_ag.py | 10 +- samples/apps/cap/py/autogencap/debug_log.py | 3 +- .../cap/py/autogencap/zmq_actor_connector.py | 163 ++++++++++++++ .../cap/py/autogencap/zmq_directory_svc.py | 18 +- .../cap/py/autogencap/zmq_msg_receiver.py | 48 +++++ samples/apps/cap/py/autogencap/zmq_runtime.py | 199 +++--------------- samples/apps/cap/py/demo/app.py | 1 + samples/apps/cap/py/demo/app_agents.py | 12 +- .../cap/py/demo/cap_autogen_group_demo.py | 2 +- .../apps/cap/py/demo/complex_actor_demo.py | 18 +- 17 files changed, 384 insertions(+), 294 deletions(-) create mode 100644 samples/apps/cap/py/autogencap/zmq_actor_connector.py create mode 100644 samples/apps/cap/py/autogencap/zmq_msg_receiver.py diff --git a/samples/apps/cap/py/autogencap/Config.py b/samples/apps/cap/py/autogencap/Config.py index 5584a8d29cb4..0e49d98b49d7 100644 --- a/samples/apps/cap/py/autogencap/Config.py +++ b/samples/apps/cap/py/autogencap/Config.py @@ -5,3 +5,4 @@ xsub_url: str = "tcp://127.0.0.1:5556" router_url: str = "tcp://127.0.0.1:5557" dealer_url: str = "tcp://127.0.0.1:5558" +USE_COLOR_LOGGING = True diff --git a/samples/apps/cap/py/autogencap/actor.py b/samples/apps/cap/py/autogencap/actor.py index 4f1cfab89b23..ab1bbc307c31 100644 --- a/samples/apps/cap/py/autogencap/actor.py +++ b/samples/apps/cap/py/autogencap/actor.py @@ -1,57 +1,36 @@ import threading import traceback +from .actor_runtime import IMsgActor, IRuntime, IMessageReceiver +from .debug_log import Debug, Info -import zmq - -from .config import xpub_url -from .debug_log import Debug, Error, Info - - -class Actor: +class Actor(IMsgActor): def __init__(self, agent_name: str, description: str, start_thread: bool = True): + """Initialize the Actor with a name, description, and threading option.""" self.actor_name: str = agent_name self.agent_description: str = description self.run = False self._start_event = threading.Event() self._start_thread = start_thread + self._msg_receiver: IMessageReceiver = None + self._runtime: IRuntime = None - def on_connect(self, network): - Debug(self.actor_name, f"is connecting to {network}") + def on_connect(self): + """Connect the actor to the runtime.""" + Debug(self.actor_name, f"is connecting to {self._runtime}") Debug(self.actor_name, "connected") def on_txt_msg(self, msg: str, msg_type: str, receiver: str, sender: str) -> bool: + """Handle incoming text messages.""" Info(self.actor_name, f"InBox: {msg}") return True def on_bin_msg(self, msg: bytes, msg_type: str, receiver: str, sender: str) -> bool: + """Handle incoming binary messages.""" Info(self.actor_name, f"Msg: receiver=[{receiver}], msg_type=[{msg_type}]") return True - def _msg_loop_init(self): - Debug(self.actor_name, "recv thread started") - self._socket: zmq.Socket = self._context.socket(zmq.SUB) - self._socket.setsockopt(zmq.RCVTIMEO, 500) - self._socket.connect(xpub_url) - str_topic = f"{self.actor_name}" - Debug(self.actor_name, f"subscribe to: {str_topic}") - self._socket.setsockopt_string(zmq.SUBSCRIBE, f"{str_topic}") - self._start_event.set() - - def get_message(self): - try: - topic, msg_type, sender_topic, msg = self._socket.recv_multipart() - topic = topic.decode("utf-8") # Convert bytes to string - msg_type = msg_type.decode("utf-8") # Convert bytes to string - sender_topic = sender_topic.decode("utf-8") # Convert bytes to string - except zmq.Again: - return None # No message received, continue to next iteration - except Exception as e: - Error(self.actor_name, f"recv thread encountered an error: {e}") - traceback.print_exc() - return None - return topic, msg_type, sender_topic, msg - def dispatch_message(self, message): + """Dispatch the received message based on its type.""" if message is None: return topic, msg_type, sender_topic, msg = message @@ -65,40 +44,50 @@ def dispatch_message(self, message): if not self.on_bin_msg(msg, msg_type, topic, sender_topic): self.run = False + def get_message(self): + """Retrieve a message from the runtime implementation.""" + return self._msg_receiver.get_message() + def _msg_loop(self): + """Main message loop for receiving and dispatching messages.""" try: - self._msg_loop_init() + self._msg_receiver = self._runtime.get_new_msg_receiver() + self._msg_receiver.init(self.actor_name) + self._start_event.set() while self.run: - message = self.get_message() + message = self._msg_receiver.get_message() self.dispatch_message(message) except Exception as e: Debug(self.actor_name, f"recv thread encountered an error: {e}") traceback.print_exc() finally: - self.run = False # In case there was an exception at startup signal # the main thread. self._start_event.set() + self.run = False Debug(self.actor_name, "recv thread ended") - def on_start(self, context: zmq.Context): - self._context = context - self.run: bool = True + def on_start(self, runtime: IRuntime): + """Start the actor and its message receiving thread if applicable.""" + self._runtime = runtime # Save the runtime + self.run = True if self._start_thread: self._thread = threading.Thread(target=self._msg_loop) self._thread.start() self._start_event.wait() else: - self._msg_loop_init() + self._msg_receiver = self._runtime.get_new_msg_receiver() + self._msg_receiver.init(self.actor_name) def disconnect_network(self, network): + """Disconnect the actor from the network.""" Debug(self.actor_name, f"is disconnecting from {network}") Debug(self.actor_name, "disconnected") self.stop() def stop(self): + """Stop the actor and its message receiver.""" self.run = False if self._start_thread: self._thread.join() - self._socket.setsockopt(zmq.LINGER, 0) - self._socket.close() + self._msg_receiver.stop() diff --git a/samples/apps/cap/py/autogencap/actor_connector.py b/samples/apps/cap/py/autogencap/actor_connector.py index 240c9625cae2..bec026f6ce3e 100644 --- a/samples/apps/cap/py/autogencap/actor_connector.py +++ b/samples/apps/cap/py/autogencap/actor_connector.py @@ -1,43 +1,27 @@ -# Agent_Sender takes a zmq context, Topic and creates a -# socket that can publish to that topic. It exposes this functionality -# using send_msg method from abc import ABC, abstractmethod +from typing import Any, Tuple, Optional - -class IActorSender(ABC): +class IActorConnector(ABC): @abstractmethod - def send_txt_msg(self, msg): + def send_txt_msg(self, msg: str) -> None: pass @abstractmethod - def send_bin_msg(self, msg_type: str, msg): + def send_bin_msg(self, msg_type: str, msg: bytes) -> None: pass @abstractmethod - def send_recv_msg(self, msg_type: str, msg, resp_topic: str): + def send_proto_msg(self, msg: Any) -> None: pass @abstractmethod - def close(self): + def send_recv_proto_msg(self, msg: Any, num_attempts: int = 5) -> Tuple[Optional[str], Optional[str], Optional[bytes]]: pass - -class IActorConnector(ABC): @abstractmethod - def send_txt_msg(self, msg): + def send_recv_msg(self, msg_type: str, msg: bytes, num_attempts: int = 5) -> Tuple[Optional[str], Optional[str], Optional[bytes]]: pass - def send_bin_msg(self, msg_type: str, msg): - pass - - def send_proto_msg(self, msg): - pass - - def send_recv_proto_msg(self, msg, num_attempts=5): - pass - - def send_recv_msg(self, msg_type: str, msg, num_attempts=5): - pass - - def close(self): + @abstractmethod + def close(self) -> None: pass diff --git a/samples/apps/cap/py/autogencap/actor_runtime.py b/samples/apps/cap/py/autogencap/actor_runtime.py index ad3b25566030..37786225e3a9 100644 --- a/samples/apps/cap/py/autogencap/actor_runtime.py +++ b/samples/apps/cap/py/autogencap/actor_runtime.py @@ -1,36 +1,99 @@ from abc import ABC, abstractmethod from typing import List - -from .actor import Actor from .actor_connector import IActorConnector from .proto.CAP_pb2 import ActorInfo +class IMsgActor(ABC): + @abstractmethod + def on_connect(self, runtime: 'IRuntime'): + """Called when the actor connects to the runtime.""" + pass + + @abstractmethod + def on_txt_msg(self, msg: str, msg_type: str, receiver: str, sender: str) -> bool: + """Handle incoming text messages.""" + pass + + @abstractmethod + def on_bin_msg(self, msg: bytes, msg_type: str, receiver: str, sender: str) -> bool: + """Handle incoming binary messages.""" + pass + + @abstractmethod + def on_start(self): + """Called when the actor starts.""" + pass + + @abstractmethod + def stop(self): + """Stop the actor.""" + pass + + @abstractmethod + def dispatch_message(self, message): + """Dispatch the received message based on its type.""" + pass + +# Abstract base class for message receivers +class IMessageReceiver(ABC): + @abstractmethod + def init(self, actor_name: str): + """Initialize the message receiver.""" + pass + + @abstractmethod + def add_listener(self, topic: str): + """Add a topic to the message receiver.""" + pass + + @abstractmethod + def get_message(self): + """Retrieve a message from the runtime implementation.""" + pass + + @abstractmethod + def stop(self): + """Stop the message receiver.""" + pass +# Abstract base class for the runtime environment class IRuntime(ABC): @abstractmethod - def register(self, actor: Actor): + def register(self, actor: IMsgActor): + """Register an actor with the runtime.""" + pass + + @abstractmethod + def get_new_msg_receiver(self) -> IMessageReceiver: + """Create and return a new message receiver.""" pass @abstractmethod def connect(self): + """Connect the runtime to the messaging system.""" pass @abstractmethod def disconnect(self): + """Disconnect the runtime from the messaging system.""" pass @abstractmethod def find_by_topic(self, topic: str) -> IActorConnector: + """Find an actor connector by topic.""" pass @abstractmethod def find_by_name(self, name: str) -> IActorConnector: + """Find an actor connector by name.""" pass @abstractmethod def find_termination(self) -> IActorConnector: + """Find the termination actor connector.""" pass @abstractmethod - def find_by_name_regex(self, name_regex) -> List[ActorInfo]: + def find_by_name_regex(self, name_regex) -> List['ActorInfo']: + """Find actors by name using a regular expression.""" pass diff --git a/samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py b/samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py index accb6acf6df4..7ad87e901e3a 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py @@ -1,13 +1,10 @@ -import zmq - from autogencap.actor import Actor from autogencap.constants import Termination_Topic from autogencap.debug_log import Debug - class AGActor(Actor): - def on_start(self, context: zmq.Context): - super().on_start(context) + def on_start(self, runtime): + super().on_start(runtime) str_topic = Termination_Topic - Debug(self.actor_name, f"subscribe to: {str_topic}") - self._socket.setsockopt_string(zmq.SUBSCRIBE, f"{str_topic}") + self._msg_receiver.add_listener(str_topic) + Debug(self.actor_name, f"subscribe to: {str_topic}") \ No newline at end of file diff --git a/samples/apps/cap/py/autogencap/ag_adapter/autogen_connector.py b/samples/apps/cap/py/autogencap/ag_adapter/autogen_connector.py index 97efd18b2e57..d2baa9020e1d 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/autogen_connector.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/autogen_connector.py @@ -3,7 +3,7 @@ from autogen import Agent -from ..actor_runtime import IActorConnector +from ..actor_connector import IActorConnector from ..proto.Autogen_pb2 import GenReplyReq, GenReplyResp, PrepChat, ReceiveReq, Terminate diff --git a/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat_manager.py b/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat_manager.py index 7031c5a98cee..44f43d3d33f4 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat_manager.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat_manager.py @@ -1,7 +1,7 @@ import time from autogen import GroupChatManager -from autogencap.actor_runtime import IActorConnector +from autogencap.actor_connector import IActorConnector from autogencap.ag_adapter.cap_to_ag import CAP2AG from autogencap.ag_adapter.cap_group_chat import CAPGroupChat @@ -9,8 +9,8 @@ class CAPGroupChatManager: - def __init__(self, groupchat: CAPGroupChat, llm_config: dict, network: IRuntime): - self._ensemble: IRuntime = network + def __init__(self, groupchat: CAPGroupChat, llm_config: dict, runtime: IRuntime): + self._runtime: IRuntime = runtime self._cap_group_chat: CAPGroupChat = groupchat self._ag_group_chat_manager: GroupChatManager = GroupChatManager( groupchat=self._cap_group_chat, llm_config=llm_config @@ -21,11 +21,11 @@ def __init__(self, groupchat: CAPGroupChat, llm_config: dict, network: IRuntime) init_chat=False, self_recursive=True, ) - self._ensemble.register(self._cap_proxy) + self._runtime.register(self._cap_proxy) def initiate_chat(self, txt_msg: str) -> None: - self._ensemble.connect() - user_proxy_conn: IActorConnector = self._ensemble.find_by_name(self._cap_group_chat.chat_initiator) + self._runtime.connect() + user_proxy_conn: IActorConnector = self._runtime.find_by_name(self._cap_group_chat.chat_initiator) user_proxy_conn.send_txt_msg(txt_msg) self._wait_for_user_exit() diff --git a/samples/apps/cap/py/autogencap/ag_adapter/cap_to_ag.py b/samples/apps/cap/py/autogencap/ag_adapter/cap_to_ag.py index 4f94936b37e3..09e1fcb5cdc4 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/cap_to_ag.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/cap_to_ag.py @@ -1,9 +1,7 @@ import json from enum import Enum from typing import Optional - from autogen import ConversableAgent - from ..actor_runtime import IRuntime from ..debug_log import Debug, Error, Info, Warn, shorten from ..proto.Autogen_pb2 import GenReplyReq, GenReplyResp, PrepChat, ReceiveReq, Terminate @@ -27,15 +25,13 @@ def __init__(self, ag_agent: ConversableAgent, the_other_name: str, init_chat: b self.STATE = self.States.INIT self._can2ag_name: str = self.actor_name + ".can2ag" self._self_recursive: bool = self_recursive - self._ensemble: IRuntime = None self._connectors = {} - def on_connect(self, ensemble: IRuntime): + def on_connect(self): """ Connect to the AutoGen system. """ - self._ensemble = ensemble - self._ag2can_other_agent = AG2CAP(self._ensemble, self._other_agent_name) + self._ag2can_other_agent = AG2CAP(self._runtime, self._other_agent_name) Debug(self._can2ag_name, "connected to {ensemble}") def disconnect_network(self, ensemble: IRuntime): @@ -117,7 +113,7 @@ def get_actor_connector(self, topic: str): if topic in self._connectors: return self._connectors[topic] else: - connector = self._ensemble.find_by_topic(topic) + connector = self._runtime.find_by_topic(topic) self._connectors[topic] = connector return connector diff --git a/samples/apps/cap/py/autogencap/debug_log.py b/samples/apps/cap/py/autogencap/debug_log.py index 000457b6a013..1e2a6bf2a00e 100644 --- a/samples/apps/cap/py/autogencap/debug_log.py +++ b/samples/apps/cap/py/autogencap/debug_log.py @@ -34,7 +34,7 @@ def WriteLog(self, level, context, msg): class ConsoleLogger(BaseLogger): - def __init__(self, use_color=True): + def __init__(self, use_color=config.USE_COLOR_LOGGING): super().__init__() self._use_color = use_color @@ -56,6 +56,7 @@ def WriteLog(self, level, context, msg): print(f"{thread_id} {timestamp} {level_name}: [{context}] {msg}") +# Modify this line to disable color logging by default LOGGER = ConsoleLogger() diff --git a/samples/apps/cap/py/autogencap/zmq_actor_connector.py b/samples/apps/cap/py/autogencap/zmq_actor_connector.py new file mode 100644 index 000000000000..a93a6d15aff2 --- /dev/null +++ b/samples/apps/cap/py/autogencap/zmq_actor_connector.py @@ -0,0 +1,163 @@ +# Agent_Sender takes a zmq context, Topic and creates a +# socket that can publish to that topic. It exposes this functionality +# using send_msg method +import time +import uuid +from typing import Any, Dict + +import zmq +from zmq.utils.monitor import recv_monitor_message + +from .config import router_url, xpub_url, xsub_url +from .debug_log import Debug, Error, Info +from .actor_connector import IActorConnector + + +class ZMQActorSender: + def __init__(self, context, topic): + self._context = context + self._topic = topic + self._connect_pub_socket() + + def _connect_pub_socket(self): + Debug("ActorSender", f"Connecting pub socket {self._topic}") + self._pub_socket = self._context.socket(zmq.PUB) + monitor = self._pub_socket.get_monitor_socket() + self._pub_socket.setsockopt(zmq.LINGER, 0) + self._pub_socket.connect(xsub_url) + # Monitor handshake on the pub socket + while monitor.poll(): + evt: Dict[str, Any] = {} + mon_evt = recv_monitor_message(monitor) + evt.update(mon_evt) + if evt["event"] == zmq.EVENT_HANDSHAKE_SUCCEEDED: + Debug("ActorSender", "Handshake received") + break + elif evt["event"] == zmq.EVENT_MONITOR_STOPPED: + Debug("ActorSender", "Monitor stopped") + break + self._pub_socket.disable_monitor() + monitor.close() + self._send_recv_router_msg() + + def _send_recv_router_msg(self): + # Send a request to the router and wait for a response + req_socket = self._context.socket(zmq.REQ) + req_socket.connect(router_url) + try: + Debug("ActorSender", "Broker Check Request Sent") + req_socket.send_string("Request") + _ = req_socket.recv_string() + Debug("ActorSender", "Broker Check Response Received") + finally: + req_socket.close() + + def send_txt_msg(self, msg): + Debug("ActorSender", f"[{self._topic}] send_txt_msg: {msg}") + self._pub_socket.send_multipart( + [self._topic.encode("utf8"), "text".encode("utf8"), "no_resp".encode("utf8"), msg.encode("utf8")] + ) + + def send_bin_msg(self, msg_type: str, msg): + Debug("ActorSender", f"[{self._topic}] send_bin_msg: {msg_type}") + self._pub_socket.send_multipart( + [self._topic.encode("utf8"), msg_type.encode("utf8"), "no_resp".encode("utf8"), msg] + ) + + def send_bin_request_msg(self, msg_type: str, msg, resp_topic: str): + Debug("ActorSender", f"[{self._topic}] send_bin_request_msg: {msg_type}") + self._pub_socket.send_multipart( + [self._topic.encode("utf8"), msg_type.encode("utf8"), resp_topic.encode("utf8"), msg] + ) + + def close(self): + self._pub_socket.close() + + +class ZMQActorConnector(IActorConnector): + def __init__(self, context, topic): + self._context = context + self._topic = topic + self._connect_sub_socket() + self._sender = ZMQActorSender(context, topic) + time.sleep(0.1) # Wait for the socket to connect + + def _connect_sub_socket(self): + self._resp_socket = self._context.socket(zmq.SUB) + monitor = self._resp_socket.get_monitor_socket() + self._resp_socket.setsockopt(zmq.LINGER, 0) + self._resp_socket.setsockopt(zmq.RCVTIMEO, 250) + self._resp_socket.connect(xpub_url) + self._resp_topic = str(uuid.uuid4()) + Debug("ActorConnector", f"subscribe to: {self._resp_topic}") + self._resp_socket.setsockopt_string(zmq.SUBSCRIBE, f"{self._resp_topic}") + while monitor.poll(): + evt: Dict[str, Any] = {} + mon_evt = recv_monitor_message(monitor) + evt.update(mon_evt) + Debug("ActorConnector", evt) + if evt["event"] == zmq.EVENT_MONITOR_STOPPED or evt["event"] == zmq.EVENT_HANDSHAKE_SUCCEEDED: + Debug("ActorConnector", "Handshake received (Or Monitor stopped)") + break + self._resp_socket.disable_monitor() + monitor.close() + self._send_recv_router_msg() + + def _send_recv_router_msg(self): + # Send a request to the router and wait for a response + req_socket = self._context.socket(zmq.REQ) + req_socket.connect(router_url) + try: + Debug("ActorConnector", "Broker Check Request Sent") + req_socket.send_string("Request") + _ = req_socket.recv_string() + Debug("ActorConnector", "Broker Check Response Received") + finally: + req_socket.close() + + def send_txt_msg(self, msg): + self._sender.send_txt_msg(msg) + + def send_bin_msg(self, msg_type: str, msg): + self._sender.send_bin_msg(msg_type, msg) + + def send_proto_msg(self, msg): + bin_msg = msg.SerializeToString() + class_type = type(msg) + self._sender.send_bin_msg(class_type.__name__, bin_msg) + + def send_recv_proto_msg(self, msg, num_attempts=5): + bin_msg = msg.SerializeToString() + class_type = type(msg) + return self.send_recv_msg(class_type.__name, bin_msg, num_attempts) + + def send_recv_msg(self, msg_type: str, msg, num_attempts=5): + original_timeout: int = 0 + if num_attempts == -1: + original_timeout = self._resp_socket.getsockopt(zmq.RCVTIMEO) + self._resp_socket.setsockopt(zmq.RCVTIMEO, 1000) + + try: + self._sender.send_bin_request_msg(msg_type, msg, self._resp_topic) + while num_attempts == -1 or num_attempts > 0: + try: + topic, resp_msg_type, _, resp = self._resp_socket.recv_multipart() + return topic, resp_msg_type, resp + except zmq.Again: + Debug( + "ActorConnector", + f"{self._topic}: No response received. retry_count={num_attempts}, max_retry={num_attempts}", + ) + time.sleep(0.01) + if num_attempts != -1: + num_attempts -= 1 + finally: + if num_attempts == -1: + self._resp_socket.setsockopt(zmq.RCVTIMEO, original_timeout) + + Error("ActorConnector", f"{self._topic}: No response received. Giving up.") + return None, None, None + + def close(self): + self._sender.close() + self._resp_socket.close() diff --git a/samples/apps/cap/py/autogencap/zmq_directory_svc.py b/samples/apps/cap/py/autogencap/zmq_directory_svc.py index 031815e98e9c..34efd28f3744 100644 --- a/samples/apps/cap/py/autogencap/zmq_directory_svc.py +++ b/samples/apps/cap/py/autogencap/zmq_directory_svc.py @@ -5,8 +5,8 @@ import zmq from autogencap.actor import Actor +from autogencap.zmq_actor_connector import ZMQActorConnector, ZMQActorSender from autogencap.broker import Broker -from autogencap.config import router_url, xpub_url, xsub_url from autogencap.constants import Directory_Svc_Topic from autogencap.debug_log import Debug, Error, Info from autogencap.proto.CAP_pb2 import ( @@ -30,10 +30,11 @@ class ZMQDirectoryActor(Actor): - def __init__(self, topic: str, name: str): + def __init__(self, topic: str, name: str, context: zmq.Context): super().__init__(topic, name) self._registered_actors = {} self._network_prefix = "" + self._context = context def on_bin_msg(self, msg: bytes, msg_type: str, topic: str, sender: str) -> bool: if msg_type == ActorRegistration.__name__: @@ -116,12 +117,12 @@ def _no_other_directory(self) -> bool: return True return False - def start(self): + def start(self, runtime): Debug("DirectorySvc", "Starting.") self._directory_connector = ZMQActorConnector(self._context, Directory_Svc_Topic) if self._no_other_directory(): - self._directory_actor = ZMQDirectoryActor(Directory_Svc_Topic, "Directory Service") - self._directory_actor.on_start(self._context) + self._directory_actor = ZMQDirectoryActor(Directory_Svc_Topic, "Directory Service", self._context) # Update this line + self._directory_actor.on_start(runtime) Info("DirectorySvc", "Directory service started.") else: Info("DirectorySvc", "Another directory service is running. This instance will not start.") @@ -178,13 +179,6 @@ def main(): # Start the directory service directory_svc = ZMQDirectorySvc(context) directory_svc.start() - # # How do you register an actor? - # directory_svc.register_actor_by_name("my_actor") - # - # # How do you look up an actor? - # actor: ActorInfo = directory_svc.lookup_actor_by_name("my_actor") - # if actor is not None: - # Info("main", f"Found actor: {actor.name}") # DirectorySvc is running in a separate thread. Here we are watching the # status and printing status every few seconds. This is diff --git a/samples/apps/cap/py/autogencap/zmq_msg_receiver.py b/samples/apps/cap/py/autogencap/zmq_msg_receiver.py new file mode 100644 index 000000000000..60fed9776824 --- /dev/null +++ b/samples/apps/cap/py/autogencap/zmq_msg_receiver.py @@ -0,0 +1,48 @@ +# ZMQ implementation of the message receiver +from autogencap.DebugLog import Debug, Error +from autogencap.actor_runtime import IMessageReceiver +from autogencap.config import xpub_url +import zmq +import threading + +class ZMQMsgReceiver(IMessageReceiver): + def __init__(self, context: zmq.Context): + self._socket = None + self._context = context + self._start_event = threading.Event() + self.run = False + + def init(self, actor_name: str): + """Initialize the ZMQ message receiver.""" + self.actor_name = actor_name + self._socket = self._context.socket(zmq.SUB) + self._socket.setsockopt(zmq.RCVTIMEO, 500) + self._socket.connect(xpub_url) + str_topic = f"{self.actor_name}" + self.add_listener(str_topic) + self._start_event.set() + + def add_listener(self, topic: str): + """Add a topic to the message receiver.""" + Debug(self.actor_name, f"subscribe to: {topic}") + self._socket.setsockopt_string(zmq.SUBSCRIBE, f"{topic}") + + def get_message(self): + """Retrieve a message from the ZMQ socket.""" + try: + topic, msg_type, sender_topic, msg = self._socket.recv_multipart() + topic = topic.decode("utf-8") # Convert bytes to string + msg_type = msg_type.decode("utf-8") # Convert bytes to string + sender_topic = sender_topic.decode("utf-8") # Convert bytes to string + except zmq.Again: + return None # No message received, continue to next iteration + except Exception as e: + Error(self.actor_name, f"recv thread encountered an error: {e}") + return None + return topic, msg_type, sender_topic, msg + + def stop(self): + """Stop the ZMQ message receiver.""" + self.run = False + self._socket.setsockopt(zmq.LINGER, 0) + self._socket.close() \ No newline at end of file diff --git a/samples/apps/cap/py/autogencap/zmq_runtime.py b/samples/apps/cap/py/autogencap/zmq_runtime.py index fdf0cb3d719a..c78a9d2fc029 100644 --- a/samples/apps/cap/py/autogencap/zmq_runtime.py +++ b/samples/apps/cap/py/autogencap/zmq_runtime.py @@ -1,184 +1,35 @@ import time -import uuid -from typing import Any, Dict, List +from typing import List import zmq -from zmq.utils.monitor import recv_monitor_message - -from autogencap.actor_connector import IActorSender -from autogencap.config import router_url, xpub_url, xsub_url -from autogencap.debug_log import Debug, Error, Warn +from autogencap.debug_log import Debug, Warn from .actor import Actor -from .actor_connector import IActorConnector -from .actor_runtime import IRuntime +from .actor_runtime import IRuntime, IMessageReceiver from .broker import Broker from .constants import Termination_Topic -from .proto.CAP_pb2 import ActorInfo, ActorInfoCollection +from .debug_log import Debug, Warn from .zmq_directory_svc import ZMQDirectorySvc - - -class ZMQActorSender(IActorSender): - def __init__(self, context, topic): - self._context = context - self._topic = topic - self._connect_pub_socket() - - def _connect_pub_socket(self): - Debug("ActorSender", f"Connecting pub socket {self._topic}") - self._pub_socket = self._context.socket(zmq.PUB) - monitor = self._pub_socket.get_monitor_socket() - self._pub_socket.setsockopt(zmq.LINGER, 0) - self._pub_socket.connect(xsub_url) - # Monitor handshake on the pub socket - while monitor.poll(): - evt: Dict[str, Any] = {} - mon_evt = recv_monitor_message(monitor) - evt.update(mon_evt) - if evt["event"] == zmq.EVENT_HANDSHAKE_SUCCEEDED: - Debug("ActorSender", "Handshake received") - break - elif evt["event"] == zmq.EVENT_MONITOR_STOPPED: - Debug("ActorSender", "Monitor stopped") - break - self._pub_socket.disable_monitor() - monitor.close() - self._send_recv_router_msg() - - def _send_recv_router_msg(self): - # Send a request to the router and wait for a response - req_socket = self._context.socket(zmq.REQ) - req_socket.connect(router_url) - try: - Debug("ActorSender", "Broker Check Request Sent") - req_socket.send_string("Request") - _ = req_socket.recv_string() - Debug("ActorSender", "Broker Check Response Received") - finally: - req_socket.close() - - def send_txt_msg(self, msg): - Debug("ActorSender", f"[{self._topic}] send_txt_msg: {msg}") - self._pub_socket.send_multipart( - [self._topic.encode("utf8"), "text".encode("utf8"), "no_resp".encode("utf8"), msg.encode("utf8")] - ) - - def send_bin_msg(self, msg_type: str, msg): - Debug("ActorSender", f"[{self._topic}] send_bin_msg: {msg_type}") - self._pub_socket.send_multipart( - [self._topic.encode("utf8"), msg_type.encode("utf8"), "no_resp".encode("utf8"), msg] - ) - - def send_recv_msg(self, msg_type: str, msg, resp_topic: str): - Debug("ActorSender", f"[{self._topic}] send_bin_request_msg: {msg_type}") - self._pub_socket.send_multipart( - [self._topic.encode("utf8"), msg_type.encode("utf8"), resp_topic.encode("utf8"), msg] - ) - - def close(self): - self._pub_socket.close() - - -class ZMQActorConnector(IActorConnector): - def __init__(self, context, topic): - self._context = context - self._topic = topic - self._connect_sub_socket() - self._sender = ZMQActorSender(context, topic) - time.sleep(0.1) # Wait for the socket to connect - - def _connect_sub_socket(self): - self._resp_socket = self._context.socket(zmq.SUB) - monitor = self._resp_socket.get_monitor_socket() - self._resp_socket.setsockopt(zmq.LINGER, 0) - self._resp_socket.setsockopt(zmq.RCVTIMEO, 250) - self._resp_socket.connect(xpub_url) - self._resp_topic = str(uuid.uuid4()) - Debug("ActorConnector", f"subscribe to: {self._resp_topic}") - self._resp_socket.setsockopt_string(zmq.SUBSCRIBE, f"{self._resp_topic}") - while monitor.poll(): - evt: Dict[str, Any] = {} - mon_evt = recv_monitor_message(monitor) - evt.update(mon_evt) - Debug("ActorConnector", evt) - if evt["event"] == zmq.EVENT_MONITOR_STOPPED or evt["event"] == zmq.EVENT_HANDSHAKE_SUCCEEDED: - Debug("ActorConnector", "Handshake received (Or Monitor stopped)") - break - self._resp_socket.disable_monitor() - monitor.close() - self._send_recv_router_msg() - - def _send_recv_router_msg(self): - # Send a request to the router and wait for a response - req_socket = self._context.socket(zmq.REQ) - req_socket.connect(router_url) - try: - Debug("ActorConnector", "Broker Check Request Sent") - req_socket.send_string("Request") - _ = req_socket.recv_string() - Debug("ActorConnector", "Broker Check Response Received") - finally: - req_socket.close() - - def send_txt_msg(self, msg): - self._sender.send_txt_msg(msg) - - def send_bin_msg(self, msg_type: str, msg): - self._sender.send_bin_msg(msg_type, msg) - - def send_proto_msg(self, msg): - bin_msg = msg.SerializeToString() - class_type = type(msg) - self._sender.send_bin_msg(class_type.__name__, bin_msg) - - def send_recv_proto_msg(self, msg, num_attempts=5): - bin_msg = msg.SerializeToString() - class_type = type(msg) - return self.send_recv_msg(class_type.__name, bin_msg, num_attempts) - - def send_recv_msg(self, msg_type: str, msg, num_attempts=5): - original_timeout: int = 0 - if num_attempts == -1: - original_timeout = self._resp_socket.getsockopt(zmq.RCVTIMEO) - self._resp_socket.setsockopt(zmq.RCVTIMEO, 1000) - - try: - self._sender.send_recv_msg(msg_type, msg, self._resp_topic) - while num_attempts == -1 or num_attempts > 0: - try: - topic, resp_msg_type, _, resp = self._resp_socket.recv_multipart() - return topic, resp_msg_type, resp - except zmq.Again: - Debug( - "ActorConnector", - f"{self._topic}: No response received. retry_count={num_attempts}, max_retry={num_attempts}", - ) - time.sleep(0.01) - if num_attempts != -1: - num_attempts -= 1 - finally: - if num_attempts == -1: - self._resp_socket.setsockopt(zmq.RCVTIMEO, original_timeout) - - Error("ActorConnector", f"{self._topic}: No response received. Giving up.") - return None, None, None - - def close(self): - self._sender.close() - self._resp_socket.close() +from .proto.CAP_pb2 import ActorInfo, ActorInfoCollection +from .actor_connector import IActorConnector +from .zmq_actor_connector import ZMQActorConnector class ZMQRuntime(IRuntime): - def __init__(self, name: str = "Local Actor Network", start_broker: bool = True): + def __init__(self, start_broker: bool = True): self.local_actors = {} - self.name: str = name self._context: zmq.Context = zmq.Context() self._start_broker: bool = start_broker self._broker: Broker = None self._directory_svc: ZMQDirectorySvc = None + self._log_name = self.__class__.__name__ def __str__(self): - return f"{self.name}" + return f" \ +{self._log_name}\n \ +is_broker: {self._broker is not None}\n \ +is_directory_svc: {self._directory_svc is not None}\n \ +local_actors: {self.local_actors}\n" def _init_runtime(self): if self._start_broker and self._broker is None: @@ -188,22 +39,24 @@ def _init_runtime(self): self._broker = None if self._directory_svc is None: self._directory_svc = ZMQDirectorySvc(self._context) - self._directory_svc.start() + self._directory_svc.start(self) time.sleep(0.25) # Process queued thread events in Broker and Directory def register(self, actor: Actor): self._init_runtime() - # Get actor's name and description and add to a dictionary so - # that we can look up the actor by name self._directory_svc.register_actor_by_name(actor.actor_name) self.local_actors[actor.actor_name] = actor - actor.on_start(self._context) - Debug("Local_Actor_Network", f"{actor.actor_name} registered in the network.") + actor.on_start(self) # Pass self (the runtime) to on_start + Debug(self._log_name, f"{actor.actor_name} registered in the network.") + + def get_new_msg_receiver(self) -> IMessageReceiver: + from .zmq_msg_receiver import ZMQMsgReceiver + return ZMQMsgReceiver(self._context) def connect(self): self._init_runtime() for actor in self.local_actors.values(): - actor.on_connect(self) + actor.on_connect() def disconnect(self): for actor in self.local_actors.values(): @@ -219,9 +72,9 @@ def find_by_topic(self, topic: str) -> IActorConnector: def find_by_name(self, name: str) -> IActorConnector: actor_info: ActorInfo = self._directory_svc.lookup_actor_by_name(name) if actor_info is None: - Warn("Local_Actor_Network", f"{name}, not found in the network.") + Warn(self._log_name, f"{name}, not found in the network.") return None - Debug("Local_Actor_Network", f"[{name}] found in the network.") + Debug(self._log_name, f"[{name}] found in the network.") return self.find_by_topic(name) def find_termination(self) -> IActorConnector: @@ -231,9 +84,9 @@ def find_termination(self) -> IActorConnector: def find_by_name_regex(self, name_regex) -> List[ActorInfo]: actor_info: ActorInfoCollection = self._directory_svc.lookup_actor_info_by_name(name_regex) if actor_info is None: - Warn("Local_Actor_Network", f"{name_regex}, not found in the network.") + Warn(self._log_name, f"{name_regex}, not found in the network.") return None - Debug("Local_Actor_Network", f"[{name_regex}] found in the network.") + Debug(self._log_name, f"[{name_regex}] found in the network.") actor_list = [] for actor in actor_info.info_coll: actor_list.append(actor) diff --git a/samples/apps/cap/py/demo/app.py b/samples/apps/cap/py/demo/app.py index 99f48e54cafb..1db876c7e281 100644 --- a/samples/apps/cap/py/demo/app.py +++ b/samples/apps/cap/py/demo/app.py @@ -15,6 +15,7 @@ from list_agents import list_agents from simple_actor_demo import simple_actor_demo from single_threaded import single_threaded_demo +from remote_autogen_demo import remote_ag_demo #################################################################################################### diff --git a/samples/apps/cap/py/demo/app_agents.py b/samples/apps/cap/py/demo/app_agents.py index 2377ea1aee59..f8095ba18674 100644 --- a/samples/apps/cap/py/demo/app_agents.py +++ b/samples/apps/cap/py/demo/app_agents.py @@ -136,18 +136,18 @@ def __init__( self.quant: IActorConnector = None self.risk_manager: IActorConnector = None - def on_connect(self, network: IRuntime): + def on_connect(self): """ Connects the personal assistant to the specified local actor network. Args: network (LocalActorNetwork): The local actor network to connect to. """ - Debug(self.actor_name, f"is connecting to {network}") - self.fidelity = network.find_by_name("Fidelity") - self.financial_planner = network.find_by_name("Financial Planner") - self.quant = network.find_by_name("Quant") - self.risk_manager = network.find_by_name("Risk Manager") + Debug(self.actor_name, f"is connecting to {self._runtime}") + self.fidelity = self._runtime.find_by_name("Fidelity") + self.financial_planner = self._runtime.find_by_name("Financial Planner") + self.quant = self._runtime.find_by_name("Quant") + self.risk_manager = self._runtime.find_by_name("Risk Manager") Debug(self.actor_name, "connected") def disconnect_network(self, network: IRuntime): diff --git a/samples/apps/cap/py/demo/cap_autogen_group_demo.py b/samples/apps/cap/py/demo/cap_autogen_group_demo.py index 4bc8411019b1..600763aab8f1 100644 --- a/samples/apps/cap/py/demo/cap_autogen_group_demo.py +++ b/samples/apps/cap/py/demo/cap_autogen_group_demo.py @@ -35,7 +35,7 @@ def cap_ag_group_demo(): cap_groupchat = CAPGroupChat( agents=[user_proxy, coder, pm], messages=[], max_round=12, ensemble=ensemble, chat_initiator=user_proxy.name ) - manager = CAPGroupChatManager(groupchat=cap_groupchat, llm_config=gpt4_config, network=ensemble) + manager = CAPGroupChatManager(groupchat=cap_groupchat, llm_config=gpt4_config, runtime=ensemble) manager.initiate_chat("Find a latest paper about gpt-4 on arxiv and find its potential applications in software.") ensemble.disconnect() Info("App", "App Exit") diff --git a/samples/apps/cap/py/demo/complex_actor_demo.py b/samples/apps/cap/py/demo/complex_actor_demo.py index b82d457cc67b..1bc4b5a94fd5 100644 --- a/samples/apps/cap/py/demo/complex_actor_demo.py +++ b/samples/apps/cap/py/demo/complex_actor_demo.py @@ -14,17 +14,17 @@ def complex_actor_demo(): sends them to the personal assistant agent, and terminates when the user enters "quit". """ - ensemble = RuntimeFactory.get_runtime("ZMQ") + runtime = RuntimeFactory.get_runtime("ZMQ") # Register agents - ensemble.register(PersonalAssistant()) - ensemble.register(FidelityAgent()) - ensemble.register(FinancialPlannerAgent()) - ensemble.register(RiskManager()) - ensemble.register(QuantAgent()) + runtime.register(PersonalAssistant()) + runtime.register(FidelityAgent()) + runtime.register(FinancialPlannerAgent()) + runtime.register(RiskManager()) + runtime.register(QuantAgent()) # Tell agents to connect to other agents - ensemble.connect() + runtime.connect() # Get a channel to the personal assistant agent - pa = ensemble.find_by_name(PersonalAssistant.cls_agent_name) + pa = runtime.find_by_name(PersonalAssistant.cls_agent_name) info_msg = """ This is an imaginary personal assistant agent scenario. Five actors are connected in a self-determined graph. The user @@ -48,4 +48,4 @@ def complex_actor_demo(): # Cleanup pa.close() - ensemble.disconnect() + runtime.disconnect() From 98278483658cc35e9a62ddf96e5aa961e8cf8a07 Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 21 Oct 2024 02:10:37 -0400 Subject: [PATCH 20/29] fix for refactor --- samples/apps/cap/py/autogencap/zmq_msg_receiver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/apps/cap/py/autogencap/zmq_msg_receiver.py b/samples/apps/cap/py/autogencap/zmq_msg_receiver.py index 60fed9776824..e5a4c2205070 100644 --- a/samples/apps/cap/py/autogencap/zmq_msg_receiver.py +++ b/samples/apps/cap/py/autogencap/zmq_msg_receiver.py @@ -1,5 +1,5 @@ # ZMQ implementation of the message receiver -from autogencap.DebugLog import Debug, Error +from autogencap.debug_log import Debug, Error from autogencap.actor_runtime import IMessageReceiver from autogencap.config import xpub_url import zmq From 9d0c04f3908ed09fe4803291bdb0e20d0594c6e5 Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 21 Oct 2024 02:30:21 -0400 Subject: [PATCH 21/29] fix refactor, circular dependency --- samples/apps/cap/py/autogencap/zmq_actor_connector.py | 3 --- samples/apps/cap/py/autogencap/zmq_directory_svc.py | 3 +-- samples/apps/cap/py/autogencap/zmq_runtime.py | 4 ++-- samples/apps/cap/py/demo/complex_actor_demo.py | 2 +- samples/apps/cap/py/demo/list_agents.py | 2 +- samples/apps/cap/py/demo/simple_actor_demo.py | 2 +- samples/apps/cap/py/demo/single_threaded.py | 2 +- 7 files changed, 7 insertions(+), 11 deletions(-) diff --git a/samples/apps/cap/py/autogencap/zmq_actor_connector.py b/samples/apps/cap/py/autogencap/zmq_actor_connector.py index a93a6d15aff2..94ecfe2a1415 100644 --- a/samples/apps/cap/py/autogencap/zmq_actor_connector.py +++ b/samples/apps/cap/py/autogencap/zmq_actor_connector.py @@ -1,6 +1,3 @@ -# Agent_Sender takes a zmq context, Topic and creates a -# socket that can publish to that topic. It exposes this functionality -# using send_msg method import time import uuid from typing import Any, Dict diff --git a/samples/apps/cap/py/autogencap/zmq_directory_svc.py b/samples/apps/cap/py/autogencap/zmq_directory_svc.py index 34efd28f3744..fa3141f551a2 100644 --- a/samples/apps/cap/py/autogencap/zmq_directory_svc.py +++ b/samples/apps/cap/py/autogencap/zmq_directory_svc.py @@ -5,7 +5,6 @@ import zmq from autogencap.actor import Actor -from autogencap.zmq_actor_connector import ZMQActorConnector, ZMQActorSender from autogencap.broker import Broker from autogencap.constants import Directory_Svc_Topic from autogencap.debug_log import Debug, Error, Info @@ -23,7 +22,7 @@ Error as ErrorMsg, ) from autogencap.utility import report_error_msg -from autogencap.zmq_runtime import ZMQActorConnector, ZMQActorSender +from autogencap.zmq_actor_connector import ZMQActorConnector, ZMQActorSender # TODO (Future DirectorySv PR) use actor description, network_id, other properties to make directory # service more generic and powerful diff --git a/samples/apps/cap/py/autogencap/zmq_runtime.py b/samples/apps/cap/py/autogencap/zmq_runtime.py index c78a9d2fc029..7ed89f2b6f05 100644 --- a/samples/apps/cap/py/autogencap/zmq_runtime.py +++ b/samples/apps/cap/py/autogencap/zmq_runtime.py @@ -9,7 +9,6 @@ from .broker import Broker from .constants import Termination_Topic from .debug_log import Debug, Warn -from .zmq_directory_svc import ZMQDirectorySvc from .proto.CAP_pb2 import ActorInfo, ActorInfoCollection from .actor_connector import IActorConnector from .zmq_actor_connector import ZMQActorConnector @@ -21,7 +20,7 @@ def __init__(self, start_broker: bool = True): self._context: zmq.Context = zmq.Context() self._start_broker: bool = start_broker self._broker: Broker = None - self._directory_svc: ZMQDirectorySvc = None + self._directory_svc = None self._log_name = self.__class__.__name__ def __str__(self): @@ -38,6 +37,7 @@ def _init_runtime(self): self._start_broker = False # Don't try to start the broker again self._broker = None if self._directory_svc is None: + from .zmq_directory_svc import ZMQDirectorySvc self._directory_svc = ZMQDirectorySvc(self._context) self._directory_svc.start(self) time.sleep(0.25) # Process queued thread events in Broker and Directory diff --git a/samples/apps/cap/py/demo/complex_actor_demo.py b/samples/apps/cap/py/demo/complex_actor_demo.py index 1bc4b5a94fd5..ec34b309b384 100644 --- a/samples/apps/cap/py/demo/complex_actor_demo.py +++ b/samples/apps/cap/py/demo/complex_actor_demo.py @@ -1,6 +1,6 @@ import time -from AppAgents import FidelityAgent, FinancialPlannerAgent, PersonalAssistant, QuantAgent, RiskManager +from app_agents import FidelityAgent, FinancialPlannerAgent, PersonalAssistant, QuantAgent, RiskManager from autogencap.runtime_factory import RuntimeFactory from termcolor import colored diff --git a/samples/apps/cap/py/demo/list_agents.py b/samples/apps/cap/py/demo/list_agents.py index 7adfa833b343..4785ef34231e 100644 --- a/samples/apps/cap/py/demo/list_agents.py +++ b/samples/apps/cap/py/demo/list_agents.py @@ -1,7 +1,7 @@ import time from typing import List -from AppAgents import FidelityAgent, GreeterAgent +from app_agents import FidelityAgent, GreeterAgent from autogencap.debug_log import Info from autogencap.proto.CAP_pb2 import ActorInfo from autogencap.runtime_factory import RuntimeFactory diff --git a/samples/apps/cap/py/demo/simple_actor_demo.py b/samples/apps/cap/py/demo/simple_actor_demo.py index afc398297268..cb6b9a597684 100644 --- a/samples/apps/cap/py/demo/simple_actor_demo.py +++ b/samples/apps/cap/py/demo/simple_actor_demo.py @@ -1,4 +1,4 @@ -from AppAgents import GreeterAgent +from app_agents import GreeterAgent from autogencap.runtime_factory import RuntimeFactory diff --git a/samples/apps/cap/py/demo/single_threaded.py b/samples/apps/cap/py/demo/single_threaded.py index c74bd1043f17..b087eba5e6bb 100644 --- a/samples/apps/cap/py/demo/single_threaded.py +++ b/samples/apps/cap/py/demo/single_threaded.py @@ -1,5 +1,5 @@ import _paths -from AppAgents import GreeterAgent +from app_agents import GreeterAgent from autogencap.debug_log import Error from autogencap.proto.CAP_pb2 import Ping from autogencap.runtime_factory import RuntimeFactory From ba2a18d5f381d590d2bbec559f5fe9f3dd5cd228 Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 21 Oct 2024 02:32:28 -0400 Subject: [PATCH 22/29] pre-commit fixes --- samples/apps/cap/py/autogencap/actor.py | 1 + samples/apps/cap/py/autogencap/actor_connector.py | 9 +++++++-- samples/apps/cap/py/autogencap/actor_runtime.py | 9 ++++++--- samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py | 3 ++- samples/apps/cap/py/autogencap/zmq_directory_svc.py | 4 +++- samples/apps/cap/py/autogencap/zmq_msg_receiver.py | 3 ++- samples/apps/cap/py/autogencap/zmq_runtime.py | 2 ++ 7 files changed, 23 insertions(+), 8 deletions(-) diff --git a/samples/apps/cap/py/autogencap/actor.py b/samples/apps/cap/py/autogencap/actor.py index ab1bbc307c31..6d2e8496128a 100644 --- a/samples/apps/cap/py/autogencap/actor.py +++ b/samples/apps/cap/py/autogencap/actor.py @@ -3,6 +3,7 @@ from .actor_runtime import IMsgActor, IRuntime, IMessageReceiver from .debug_log import Debug, Info + class Actor(IMsgActor): def __init__(self, agent_name: str, description: str, start_thread: bool = True): """Initialize the Actor with a name, description, and threading option.""" diff --git a/samples/apps/cap/py/autogencap/actor_connector.py b/samples/apps/cap/py/autogencap/actor_connector.py index bec026f6ce3e..5a6c93664b74 100644 --- a/samples/apps/cap/py/autogencap/actor_connector.py +++ b/samples/apps/cap/py/autogencap/actor_connector.py @@ -1,6 +1,7 @@ from abc import ABC, abstractmethod from typing import Any, Tuple, Optional + class IActorConnector(ABC): @abstractmethod def send_txt_msg(self, msg: str) -> None: @@ -15,11 +16,15 @@ def send_proto_msg(self, msg: Any) -> None: pass @abstractmethod - def send_recv_proto_msg(self, msg: Any, num_attempts: int = 5) -> Tuple[Optional[str], Optional[str], Optional[bytes]]: + def send_recv_proto_msg( + self, msg: Any, num_attempts: int = 5 + ) -> Tuple[Optional[str], Optional[str], Optional[bytes]]: pass @abstractmethod - def send_recv_msg(self, msg_type: str, msg: bytes, num_attempts: int = 5) -> Tuple[Optional[str], Optional[str], Optional[bytes]]: + def send_recv_msg( + self, msg_type: str, msg: bytes, num_attempts: int = 5 + ) -> Tuple[Optional[str], Optional[str], Optional[bytes]]: pass @abstractmethod diff --git a/samples/apps/cap/py/autogencap/actor_runtime.py b/samples/apps/cap/py/autogencap/actor_runtime.py index 37786225e3a9..ee81c8695102 100644 --- a/samples/apps/cap/py/autogencap/actor_runtime.py +++ b/samples/apps/cap/py/autogencap/actor_runtime.py @@ -3,9 +3,10 @@ from .actor_connector import IActorConnector from .proto.CAP_pb2 import ActorInfo + class IMsgActor(ABC): @abstractmethod - def on_connect(self, runtime: 'IRuntime'): + def on_connect(self, runtime: "IRuntime"): """Called when the actor connects to the runtime.""" pass @@ -34,13 +35,14 @@ def dispatch_message(self, message): """Dispatch the received message based on its type.""" pass + # Abstract base class for message receivers class IMessageReceiver(ABC): @abstractmethod def init(self, actor_name: str): """Initialize the message receiver.""" pass - + @abstractmethod def add_listener(self, topic: str): """Add a topic to the message receiver.""" @@ -56,6 +58,7 @@ def stop(self): """Stop the message receiver.""" pass + # Abstract base class for the runtime environment class IRuntime(ABC): @abstractmethod @@ -94,6 +97,6 @@ def find_termination(self) -> IActorConnector: pass @abstractmethod - def find_by_name_regex(self, name_regex) -> List['ActorInfo']: + def find_by_name_regex(self, name_regex) -> List["ActorInfo"]: """Find actors by name using a regular expression.""" pass diff --git a/samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py b/samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py index 7ad87e901e3a..410a042b8ae7 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py @@ -2,9 +2,10 @@ from autogencap.constants import Termination_Topic from autogencap.debug_log import Debug + class AGActor(Actor): def on_start(self, runtime): super().on_start(runtime) str_topic = Termination_Topic self._msg_receiver.add_listener(str_topic) - Debug(self.actor_name, f"subscribe to: {str_topic}") \ No newline at end of file + Debug(self.actor_name, f"subscribe to: {str_topic}") diff --git a/samples/apps/cap/py/autogencap/zmq_directory_svc.py b/samples/apps/cap/py/autogencap/zmq_directory_svc.py index fa3141f551a2..eb0f2ee37924 100644 --- a/samples/apps/cap/py/autogencap/zmq_directory_svc.py +++ b/samples/apps/cap/py/autogencap/zmq_directory_svc.py @@ -120,7 +120,9 @@ def start(self, runtime): Debug("DirectorySvc", "Starting.") self._directory_connector = ZMQActorConnector(self._context, Directory_Svc_Topic) if self._no_other_directory(): - self._directory_actor = ZMQDirectoryActor(Directory_Svc_Topic, "Directory Service", self._context) # Update this line + self._directory_actor = ZMQDirectoryActor( + Directory_Svc_Topic, "Directory Service", self._context + ) # Update this line self._directory_actor.on_start(runtime) Info("DirectorySvc", "Directory service started.") else: diff --git a/samples/apps/cap/py/autogencap/zmq_msg_receiver.py b/samples/apps/cap/py/autogencap/zmq_msg_receiver.py index e5a4c2205070..387ce7ef5578 100644 --- a/samples/apps/cap/py/autogencap/zmq_msg_receiver.py +++ b/samples/apps/cap/py/autogencap/zmq_msg_receiver.py @@ -5,6 +5,7 @@ import zmq import threading + class ZMQMsgReceiver(IMessageReceiver): def __init__(self, context: zmq.Context): self._socket = None @@ -45,4 +46,4 @@ def stop(self): """Stop the ZMQ message receiver.""" self.run = False self._socket.setsockopt(zmq.LINGER, 0) - self._socket.close() \ No newline at end of file + self._socket.close() diff --git a/samples/apps/cap/py/autogencap/zmq_runtime.py b/samples/apps/cap/py/autogencap/zmq_runtime.py index 7ed89f2b6f05..e52e97446709 100644 --- a/samples/apps/cap/py/autogencap/zmq_runtime.py +++ b/samples/apps/cap/py/autogencap/zmq_runtime.py @@ -38,6 +38,7 @@ def _init_runtime(self): self._broker = None if self._directory_svc is None: from .zmq_directory_svc import ZMQDirectorySvc + self._directory_svc = ZMQDirectorySvc(self._context) self._directory_svc.start(self) time.sleep(0.25) # Process queued thread events in Broker and Directory @@ -51,6 +52,7 @@ def register(self, actor: Actor): def get_new_msg_receiver(self) -> IMessageReceiver: from .zmq_msg_receiver import ZMQMsgReceiver + return ZMQMsgReceiver(self._context) def connect(self): From 2f54a02cb74949486522b3d5376e35008d9c5226 Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 21 Oct 2024 02:35:59 -0400 Subject: [PATCH 23/29] document classes --- samples/apps/cap/py/autogencap/actor_runtime.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/samples/apps/cap/py/autogencap/actor_runtime.py b/samples/apps/cap/py/autogencap/actor_runtime.py index ee81c8695102..f83c61701a2c 100644 --- a/samples/apps/cap/py/autogencap/actor_runtime.py +++ b/samples/apps/cap/py/autogencap/actor_runtime.py @@ -5,6 +5,8 @@ class IMsgActor(ABC): + """Abstract base class for message based actors.""" + @abstractmethod def on_connect(self, runtime: "IRuntime"): """Called when the actor connects to the runtime.""" @@ -36,8 +38,9 @@ def dispatch_message(self, message): pass -# Abstract base class for message receivers class IMessageReceiver(ABC): + """Abstract base class for message receivers. Implementations are runtime specific.""" + @abstractmethod def init(self, actor_name: str): """Initialize the message receiver.""" @@ -61,6 +64,8 @@ def stop(self): # Abstract base class for the runtime environment class IRuntime(ABC): + """Abstract base class for the actor runtime environment.""" + @abstractmethod def register(self, actor: IMsgActor): """Register an actor with the runtime.""" From f9a8aacf2861c16e29320293152c19e7b81107ec Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 21 Oct 2024 02:41:22 -0400 Subject: [PATCH 24/29] pre-commit ruff --- samples/apps/cap/py/autogencap/actor.py | 3 ++- samples/apps/cap/py/autogencap/actor_connector.py | 2 +- samples/apps/cap/py/autogencap/actor_runtime.py | 1 + .../py/autogencap/ag_adapter/cap_group_chat_manager.py | 2 +- samples/apps/cap/py/autogencap/ag_adapter/cap_to_ag.py | 4 +++- samples/apps/cap/py/autogencap/zmq_actor_connector.py | 2 +- samples/apps/cap/py/autogencap/zmq_msg_receiver.py | 8 +++++--- samples/apps/cap/py/autogencap/zmq_runtime.py | 5 +++-- samples/apps/cap/py/demo/app.py | 2 +- 9 files changed, 18 insertions(+), 11 deletions(-) diff --git a/samples/apps/cap/py/autogencap/actor.py b/samples/apps/cap/py/autogencap/actor.py index 6d2e8496128a..9b954f8461be 100644 --- a/samples/apps/cap/py/autogencap/actor.py +++ b/samples/apps/cap/py/autogencap/actor.py @@ -1,6 +1,7 @@ import threading import traceback -from .actor_runtime import IMsgActor, IRuntime, IMessageReceiver + +from .actor_runtime import IMessageReceiver, IMsgActor, IRuntime from .debug_log import Debug, Info diff --git a/samples/apps/cap/py/autogencap/actor_connector.py b/samples/apps/cap/py/autogencap/actor_connector.py index 5a6c93664b74..2d83d0be540c 100644 --- a/samples/apps/cap/py/autogencap/actor_connector.py +++ b/samples/apps/cap/py/autogencap/actor_connector.py @@ -1,5 +1,5 @@ from abc import ABC, abstractmethod -from typing import Any, Tuple, Optional +from typing import Any, Optional, Tuple class IActorConnector(ABC): diff --git a/samples/apps/cap/py/autogencap/actor_runtime.py b/samples/apps/cap/py/autogencap/actor_runtime.py index f83c61701a2c..bd1e31a339a6 100644 --- a/samples/apps/cap/py/autogencap/actor_runtime.py +++ b/samples/apps/cap/py/autogencap/actor_runtime.py @@ -1,5 +1,6 @@ from abc import ABC, abstractmethod from typing import List + from .actor_connector import IActorConnector from .proto.CAP_pb2 import ActorInfo diff --git a/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat_manager.py b/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat_manager.py index 44f43d3d33f4..3934715028b6 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat_manager.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/cap_group_chat_manager.py @@ -2,8 +2,8 @@ from autogen import GroupChatManager from autogencap.actor_connector import IActorConnector -from autogencap.ag_adapter.cap_to_ag import CAP2AG from autogencap.ag_adapter.cap_group_chat import CAPGroupChat +from autogencap.ag_adapter.cap_to_ag import CAP2AG from ..actor_runtime import IRuntime diff --git a/samples/apps/cap/py/autogencap/ag_adapter/cap_to_ag.py b/samples/apps/cap/py/autogencap/ag_adapter/cap_to_ag.py index 09e1fcb5cdc4..30f5b52354fb 100644 --- a/samples/apps/cap/py/autogencap/ag_adapter/cap_to_ag.py +++ b/samples/apps/cap/py/autogencap/ag_adapter/cap_to_ag.py @@ -1,12 +1,14 @@ import json from enum import Enum from typing import Optional + from autogen import ConversableAgent + from ..actor_runtime import IRuntime from ..debug_log import Debug, Error, Info, Warn, shorten from ..proto.Autogen_pb2 import GenReplyReq, GenReplyResp, PrepChat, ReceiveReq, Terminate -from .ag_to_cap import AG2CAP from .ag_actor import AGActor +from .ag_to_cap import AG2CAP class CAP2AG(AGActor): diff --git a/samples/apps/cap/py/autogencap/zmq_actor_connector.py b/samples/apps/cap/py/autogencap/zmq_actor_connector.py index 94ecfe2a1415..6b5b30f4446f 100644 --- a/samples/apps/cap/py/autogencap/zmq_actor_connector.py +++ b/samples/apps/cap/py/autogencap/zmq_actor_connector.py @@ -5,9 +5,9 @@ import zmq from zmq.utils.monitor import recv_monitor_message +from .actor_connector import IActorConnector from .config import router_url, xpub_url, xsub_url from .debug_log import Debug, Error, Info -from .actor_connector import IActorConnector class ZMQActorSender: diff --git a/samples/apps/cap/py/autogencap/zmq_msg_receiver.py b/samples/apps/cap/py/autogencap/zmq_msg_receiver.py index 387ce7ef5578..b6a2a27fa64b 100644 --- a/samples/apps/cap/py/autogencap/zmq_msg_receiver.py +++ b/samples/apps/cap/py/autogencap/zmq_msg_receiver.py @@ -1,9 +1,11 @@ # ZMQ implementation of the message receiver -from autogencap.debug_log import Debug, Error +import threading + +import zmq + from autogencap.actor_runtime import IMessageReceiver from autogencap.config import xpub_url -import zmq -import threading +from autogencap.debug_log import Debug, Error class ZMQMsgReceiver(IMessageReceiver): diff --git a/samples/apps/cap/py/autogencap/zmq_runtime.py b/samples/apps/cap/py/autogencap/zmq_runtime.py index e52e97446709..de724b9cb735 100644 --- a/samples/apps/cap/py/autogencap/zmq_runtime.py +++ b/samples/apps/cap/py/autogencap/zmq_runtime.py @@ -2,15 +2,16 @@ from typing import List import zmq + from autogencap.debug_log import Debug, Warn from .actor import Actor -from .actor_runtime import IRuntime, IMessageReceiver +from .actor_connector import IActorConnector +from .actor_runtime import IMessageReceiver, IRuntime from .broker import Broker from .constants import Termination_Topic from .debug_log import Debug, Warn from .proto.CAP_pb2 import ActorInfo, ActorInfoCollection -from .actor_connector import IActorConnector from .zmq_actor_connector import ZMQActorConnector diff --git a/samples/apps/cap/py/demo/app.py b/samples/apps/cap/py/demo/app.py index 1db876c7e281..7f44730ee50f 100644 --- a/samples/apps/cap/py/demo/app.py +++ b/samples/apps/cap/py/demo/app.py @@ -13,9 +13,9 @@ from cap_autogen_pair_demo import cap_ag_pair_demo from complex_actor_demo import complex_actor_demo from list_agents import list_agents +from remote_autogen_demo import remote_ag_demo from simple_actor_demo import simple_actor_demo from single_threaded import single_threaded_demo -from remote_autogen_demo import remote_ag_demo #################################################################################################### From 4c6b44579fc1a5cd2f83457294135cee1f09b684 Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 21 Oct 2024 02:44:55 -0400 Subject: [PATCH 25/29] fix ruff issues --- samples/apps/cap/py/autogencap/zmq_runtime.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/samples/apps/cap/py/autogencap/zmq_runtime.py b/samples/apps/cap/py/autogencap/zmq_runtime.py index de724b9cb735..6693db7d41a0 100644 --- a/samples/apps/cap/py/autogencap/zmq_runtime.py +++ b/samples/apps/cap/py/autogencap/zmq_runtime.py @@ -3,8 +3,6 @@ import zmq -from autogencap.debug_log import Debug, Warn - from .actor import Actor from .actor_connector import IActorConnector from .actor_runtime import IMessageReceiver, IRuntime From 23dc8d06a98b5a627bb9ed8eb37994fe85b31d21 Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 21 Oct 2024 02:49:26 -0400 Subject: [PATCH 26/29] ruff fixes --- samples/apps/cap/py/autogencap/zmq_runtime.py | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/apps/cap/py/autogencap/zmq_runtime.py b/samples/apps/cap/py/autogencap/zmq_runtime.py index 6693db7d41a0..d98092cebd7d 100644 --- a/samples/apps/cap/py/autogencap/zmq_runtime.py +++ b/samples/apps/cap/py/autogencap/zmq_runtime.py @@ -3,6 +3,7 @@ import zmq + from .actor import Actor from .actor_connector import IActorConnector from .actor_runtime import IMessageReceiver, IRuntime From d38fda500087cc4d70af866b212abfc96c77fdbf Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 21 Oct 2024 02:51:29 -0400 Subject: [PATCH 27/29] ruff fixes --- samples/apps/cap/py/autogencap/zmq_runtime.py | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/apps/cap/py/autogencap/zmq_runtime.py b/samples/apps/cap/py/autogencap/zmq_runtime.py index d98092cebd7d..6693db7d41a0 100644 --- a/samples/apps/cap/py/autogencap/zmq_runtime.py +++ b/samples/apps/cap/py/autogencap/zmq_runtime.py @@ -3,7 +3,6 @@ import zmq - from .actor import Actor from .actor_connector import IActorConnector from .actor_runtime import IMessageReceiver, IRuntime From 380644e6c8244aae3792d42b3d897895a79bc820 Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 21 Oct 2024 02:56:02 -0400 Subject: [PATCH 28/29] actor connector documentation --- .../apps/cap/py/autogencap/actor_connector.py | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/samples/apps/cap/py/autogencap/actor_connector.py b/samples/apps/cap/py/autogencap/actor_connector.py index 2d83d0be540c..bf96dd1f54c9 100644 --- a/samples/apps/cap/py/autogencap/actor_connector.py +++ b/samples/apps/cap/py/autogencap/actor_connector.py @@ -3,30 +3,80 @@ class IActorConnector(ABC): + """ + Abstract base class for actor connectors. + Provides an interface for sending and receiving messages between actors. + """ + @abstractmethod def send_txt_msg(self, msg: str) -> None: + """ + Send a text message to the actor. + + Args: + msg (str): The text message to send. + """ pass @abstractmethod def send_bin_msg(self, msg_type: str, msg: bytes) -> None: + """ + Send a binary message to the actor. + + Args: + msg_type (str): The type of the binary message. + msg (bytes): The binary message to send. + """ pass @abstractmethod def send_proto_msg(self, msg: Any) -> None: + """ + Send a protocol buffer message to the actor. + + Args: + msg (Any): The protocol buffer message to send. + """ pass @abstractmethod def send_recv_proto_msg( self, msg: Any, num_attempts: int = 5 ) -> Tuple[Optional[str], Optional[str], Optional[bytes]]: + """ + Send a protocol buffer message and receive a response from the actor. + + Args: + msg (Any): The protocol buffer message to send. + num_attempts (int, optional): Number of attempts to send and receive. Defaults to 5. + + Returns: + Tuple[Optional[str], Optional[str], Optional[bytes]]: A tuple containing the topic, + message type, and response message, or None if no response is received. + """ pass @abstractmethod def send_recv_msg( self, msg_type: str, msg: bytes, num_attempts: int = 5 ) -> Tuple[Optional[str], Optional[str], Optional[bytes]]: + """ + Send a binary message and receive a response from the actor. + + Args: + msg_type (str): The type of the binary message. + msg (bytes): The binary message to send. + num_attempts (int, optional): Number of attempts to send and receive. Defaults to 5. + + Returns: + Tuple[Optional[str], Optional[str], Optional[bytes]]: A tuple containing the topic, + message type, and response message, or None if no response is received. + """ pass @abstractmethod def close(self) -> None: + """ + Close the actor connector and release any resources. + """ pass From 735d5fbab9e4e3475767ff72582bc874944088e5 Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 21 Oct 2024 02:59:12 -0400 Subject: [PATCH 29/29] better docs --- samples/apps/cap/py/autogencap/actor_connector.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/samples/apps/cap/py/autogencap/actor_connector.py b/samples/apps/cap/py/autogencap/actor_connector.py index bf96dd1f54c9..700d8ba655c2 100644 --- a/samples/apps/cap/py/autogencap/actor_connector.py +++ b/samples/apps/cap/py/autogencap/actor_connector.py @@ -4,8 +4,9 @@ class IActorConnector(ABC): """ - Abstract base class for actor connectors. - Provides an interface for sending and receiving messages between actors. + Abstract base class for actor connectors. Each runtime will have a different implementation. + Obtain an instance of the correct connector from the runtime by calling the runtime's find_by_xyz + method. """ @abstractmethod