Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CAP] Abstraction of actor_connector to go along with runtime factory and runtime abstraction #3296

Merged
merged 42 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
8f8a0bd
Added Runtime Factory to support multiple implementations
rajan-chari Jul 25, 2024
a241bdc
Rename to ComponentEnsemble to ZMQRuntime
rajan-chari Jul 25, 2024
b372e77
rename zmq_runtime
rajan-chari Jul 25, 2024
15b715e
rename zmq_runtime
rajan-chari Jul 25, 2024
d91d478
pre-commit fixes
rajan-chari Jul 26, 2024
9f27b79
pre-commit fix
rajan-chari Jul 26, 2024
b040b1d
Merge branch 'main' into rajan/cap-factory
rajan-chari Jul 26, 2024
3357b3e
Merge branch 'main' into rajan/cap-factory
rajan-chari Jul 29, 2024
83d9ae0
pre-commit fixes and default runtime
rajan-chari Jul 29, 2024
0e5cb67
pre-commit fixes
rajan-chari Jul 29, 2024
7a593f9
Rename constants
rajan-chari Jul 29, 2024
7aef126
Rename Constants
rajan-chari Jul 29, 2024
3d4af24
Merge branch 'main' into rajan/cap-factory
rajan-chari Jul 29, 2024
32965d8
Merge branch 'main' into rajan/cap-factory
rajan-chari Jul 29, 2024
a92bc04
Merge branch 'main' into rajan/cap-factory
thinkall Aug 1, 2024
fefa3cd
Merge branch 'microsoft:main' into rajan/cap-factory
rajan-chari Aug 5, 2024
81b1d92
Create interfaces for connectors
rajan-chari Aug 5, 2024
1dd77b8
pre-commit fixes
rajan-chari Aug 5, 2024
5e3ffad
pre-commit fixes
rajan-chari Aug 5, 2024
5480efb
pre-commit fixes
rajan-chari Aug 5, 2024
e8bbf7a
Merge branch 'main' into rajan/cap-factory
rajan-chari Aug 6, 2024
ec0387f
Merge branch 'main' into rajan/cap-factory
sonichi Aug 6, 2024
8944dfc
Merge branch 'main' into rajan/cap-factory
rajan-chari Aug 7, 2024
a89675e
lower case file names
rajan-chari Aug 7, 2024
4df6805
Merge branch 'rajan/cap-factory' of https://github.com/rajan-chari/au…
rajan-chari Aug 7, 2024
16ab32c
rename files to lower _case
rajan-chari Aug 7, 2024
ce37d8e
rename files to _lowercase
rajan-chari Aug 7, 2024
3d7209c
removed _
rajan-chari Aug 7, 2024
86cfb7a
Merge branch '0.2' into rajan/cap-factory
rysweet Oct 12, 2024
b4e3f93
Refactored to make Actor zmq agnostic
rajan-chari Oct 21, 2024
9827848
fix for refactor
rajan-chari Oct 21, 2024
9d0c04f
fix refactor, circular dependency
rajan-chari Oct 21, 2024
ba2a18d
pre-commit fixes
rajan-chari Oct 21, 2024
2f54a02
document classes
rajan-chari Oct 21, 2024
f9a8aac
pre-commit ruff
rajan-chari Oct 21, 2024
4c6b445
fix ruff issues
rajan-chari Oct 21, 2024
23dc8d0
ruff fixes
rajan-chari Oct 21, 2024
d38fda5
ruff fixes
rajan-chari Oct 21, 2024
380644e
actor connector documentation
rajan-chari Oct 21, 2024
735d5fb
better docs
rajan-chari Oct 21, 2024
af0912d
Merge branch '0.2' into rajan/cap-factory
rysweet Oct 21, 2024
ef17d54
Merge branch '0.2' into rajan/cap-factory
ekzhu Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 0 additions & 162 deletions samples/apps/cap/py/autogencap/ActorConnector.py

This file was deleted.

43 changes: 43 additions & 0 deletions samples/apps/cap/py/autogencap/actor_connector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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


class IActorSender(ABC):
rysweet marked this conversation as resolved.
Show resolved Hide resolved
@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
8 changes: 4 additions & 4 deletions samples/apps/cap/py/autogencap/actor_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion samples/apps/cap/py/autogencap/ag_adapter/AG2CAP.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
rysweet marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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
from autogencap.ag_adapter.cap_group_chat import CAPGroupChat

from ..actor_runtime import IRuntime

Expand All @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import zmq

from autogencap.Actor import Actor
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
Expand All @@ -24,12 +23,13 @@
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


class DirectoryActor(Actor):
class ZMQDirectoryActor(Actor):
def __init__(self, topic: str, name: str):
super().__init__(topic, name)
self._registered_actors = {}
Expand All @@ -50,7 +50,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):
Expand All @@ -67,7 +67,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)

Expand Down Expand Up @@ -96,16 +96,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")
Expand All @@ -118,9 +118,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:
Expand Down Expand Up @@ -176,7 +176,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")
Expand Down
Loading
Loading