autogen/samples/apps/cap/py/demo/list_agents.py
Rajan 1002882f01
[CAP] [Feature] Get list of actors from directory service. (#2073)
* Search directory for list of actors using regex '.*' gets all actors

* docs changes

* pre-commit fixes

* Use ActorInfo from protobuf

* pre-commit

* Added zmq tests to work on removing sleeps

* minor refactor of zmq tests

* 1) Change DirSvr to user Broker.  2) Add req-router to broker 3) In ActorConnector use handshake and req/resp to remove sleep

* 1) Change DirSvr to user Broker.  2) Add req-router to broker 3) In ActorConnector use handshake and req/resp to remove sleep

* move socket creation to thread with recv

* move socket creation to thread with recv

* Better logging for DirectorySvc

* better logging for directory svc

* Use logging config

* Start removing sleeps

* pre-commit

* Cleanup monitor socket
2024-03-27 22:14:39 +00:00

30 lines
973 B
Python

import time
from typing import List
from AppAgents import GreeterAgent, FidelityAgent
from autogencap.LocalActorNetwork import LocalActorNetwork
from autogencap.proto.CAP_pb2 import ActorInfo
def list_agents():
"""
Demonstrates the usage of the CAP platform by registering an actor, connecting to the actor,
sending a message, and performing cleanup operations.
"""
# CAP Platform
network = LocalActorNetwork()
# Register an actor
network.register(GreeterAgent())
# Register an actor
network.register(FidelityAgent())
# Tell actor to connect to other actors
network.connect()
# Get a list of actors
actor_infos: List[ActorInfo] = network.lookup_actor_info(name_regex=".*")
# Print out all actors found
for actor_info in actor_infos:
print(f"Name: {actor_info.name}, Namespace: {actor_info.namespace}, Description: {actor_info.description}")
time.sleep(1)
# Cleanup
network.disconnect()