You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

LocalActorNetwork.py 3.2 kB

Feature: Composable Actor Platform for AutoGen (#1655) * 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
2 years ago
Feature: Composable Actor Platform for AutoGen (#1655) * 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
2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import zmq
  2. from .DebugLog import Debug, Warn
  3. from .ActorConnector import ActorConnector
  4. from .Broker import Broker
  5. from .DirectorySvc import DirectorySvc
  6. from .Constants import Termination_Topic
  7. from .Actor import Actor
  8. from .proto.CAP_pb2 import ActorInfo, ActorInfoCollection
  9. from typing import List
  10. import time
  11. # TODO: remove time import
  12. class LocalActorNetwork:
  13. def __init__(self, name: str = "Local Actor Network", start_broker: bool = True):
  14. self.local_actors = {}
  15. self.name: str = name
  16. self._context: zmq.Context = zmq.Context()
  17. self._start_broker: bool = start_broker
  18. self._broker: Broker = None
  19. self._directory_svc: DirectorySvc = None
  20. def __str__(self):
  21. return f"{self.name}"
  22. def _init_runtime(self):
  23. if self._start_broker and self._broker is None:
  24. self._broker = Broker(self._context)
  25. if not self._broker.start():
  26. self._start_broker = False # Don't try to start the broker again
  27. self._broker = None
  28. if self._directory_svc is None:
  29. self._directory_svc = DirectorySvc(self._context)
  30. self._directory_svc.start()
  31. def register(self, actor: Actor):
  32. self._init_runtime()
  33. # Get actor's name and description and add to a dictionary so
  34. # that we can look up the actor by name
  35. self._directory_svc.register_actor_by_name(actor.actor_name)
  36. self.local_actors[actor.actor_name] = actor
  37. actor.start(self._context)
  38. Debug("Local_Actor_Network", f"{actor.actor_name} registered in the network.")
  39. def connect(self):
  40. self._init_runtime()
  41. for actor in self.local_actors.values():
  42. actor.connect_network(self)
  43. def disconnect(self):
  44. for actor in self.local_actors.values():
  45. actor.disconnect_network(self)
  46. if self._directory_svc:
  47. self._directory_svc.stop()
  48. if self._broker:
  49. self._broker.stop()
  50. def actor_connector_by_topic(self, topic: str) -> ActorConnector:
  51. return ActorConnector(self._context, topic)
  52. def lookup_actor(self, name: str) -> ActorConnector:
  53. actor_info: ActorInfo = self._directory_svc.lookup_actor_by_name(name)
  54. if actor_info is None:
  55. Warn("Local_Actor_Network", f"{name}, not found in the network.")
  56. return None
  57. Debug("Local_Actor_Network", f"[{name}] found in the network.")
  58. return self.actor_connector_by_topic(name)
  59. def lookup_termination(self) -> ActorConnector:
  60. termination_topic: str = Termination_Topic
  61. return self.actor_connector_by_topic(termination_topic)
  62. def lookup_actor_info(self, name_regex) -> List[ActorInfo]:
  63. actor_info: ActorInfoCollection = self._directory_svc.lookup_actor_info_by_name(name_regex)
  64. if actor_info is None:
  65. Warn("Local_Actor_Network", f"{name_regex}, not found in the network.")
  66. return None
  67. Debug("Local_Actor_Network", f"[{name_regex}] found in the network.")
  68. actor_list = []
  69. for actor in actor_info.info_coll:
  70. actor_list.append(actor)
  71. return actor_list