mirror of
https://github.com/microsoft/autogen.git
synced 2025-09-27 17:20:08 +00:00

* Core CAP components + Autogen adapter + Demo * Cleanup Readme * C# folder * Cleanup readme * summary_method bug fix * CAN -> CAP * pre-commit fixes * pre-commit fixes * modification of sys path should ignore E402 * fix pre-commit check issues * Updated docs * Clean up docs * more refactoring * better packaging refactor * Refactoring for package changes * Run demo app without autogencap installed or in the path * Remove debug related sleep() * removed CAP in some class names * Investigate a logging framework that supports color in windows * added type hints * remove circular dependency * fixed pre-commit issues * pre-commit ruff issues * removed circular definition * pre-commit fixes * Fix pre-commit issues * pre-commit fixes * updated for _prepare_chat signature changes * Better instructions for demo and some minor refactoring * Added details that explain CAP * Reformat Readme * More ReadMe Formatting * Readme edits * Agent -> Actor * Broker can startup on it's own * Remote AutoGen Agents * Updated docs * 1) StandaloneBroker in demo 2) Removed Autogen only demo options * 1) Agent -> Actor refactor 2) init broker as early * rename user_proxy -> user_proxy_conn * Add DirectorySvc * Standalone demo refactor * Get ActorInfo from DirectorySvc when searching for Actor * Broker cleanup * Proper cleanup and remove debug sleep() * Run one directory service only. * fix paths to run demo apps from command line * Handle keyboard interrupt * Wait for Broker and Directory to start up * Move Terminate AGActor * Accept input from the user in UserProxy * Move sleeps close to operations that bind or connect * Comments * Created an encapsulated CAP Pair for AutoGen pair communication * pre-commit checks * fix pre-commit * Pair should not make assumptions about who is first and who is second * Use task passed into InitiateChat * Standalone directory svc * Fix broken LFS files * Long running DirectorySvc * DirectorySvc does not have a status * Exit DirectorySvc Loop * Debugging Remoting * Reduce frequency of status messages * Debugging remote Actor * roll back git-lfs updates * rollback git-lfs changes * Debug network connectivity * pre-commit fixes * Create a group chat interface familiar to AutoGen GroupChat users * pre-commit fixes
72 lines
2.6 KiB
Python
72 lines
2.6 KiB
Python
import zmq
|
|
from .DebugLog import Debug, Warn
|
|
from .ActorConnector import ActorConnector
|
|
from .Broker import Broker
|
|
from .DirectorySvc import DirectorySvc
|
|
from .Constants import Termination_Topic
|
|
from .Actor import Actor
|
|
from .proto.CAP_pb2 import ActorInfo
|
|
import time
|
|
|
|
# TODO: remove time import
|
|
|
|
|
|
class LocalActorNetwork:
|
|
def __init__(self, name: str = "Local Actor Network", 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: DirectorySvc = None
|
|
|
|
def __str__(self):
|
|
return f"{self.name}"
|
|
|
|
def _init_runtime(self):
|
|
if self._start_broker and self._broker is None:
|
|
self._broker = Broker(self._context)
|
|
if not self._broker.start():
|
|
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.start()
|
|
|
|
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.start(self._context)
|
|
Debug("Local_Actor_Network", f"{actor.actor_name} registered in the network.")
|
|
|
|
def connect(self):
|
|
self._init_runtime()
|
|
for actor in self.local_actors.values():
|
|
actor.connect_network(self)
|
|
|
|
def disconnect(self):
|
|
for actor in self.local_actors.values():
|
|
actor.disconnect_network(self)
|
|
if self._directory_svc:
|
|
self._directory_svc.stop()
|
|
if self._broker:
|
|
self._broker.stop()
|
|
|
|
def actor_connector_by_topic(self, topic: str) -> ActorConnector:
|
|
return ActorConnector(self._context, topic)
|
|
|
|
def lookup_actor(self, name: str) -> ActorConnector:
|
|
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.")
|
|
return None
|
|
Debug("Local_Actor_Network", f"[{name}] found in the network.")
|
|
return self.actor_connector_by_topic(name)
|
|
|
|
def lookup_termination(self) -> ActorConnector:
|
|
termination_topic: str = Termination_Topic
|
|
return self.actor_connector_by_topic(termination_topic)
|