autogen/samples/apps/cap/py/demo/ComplexActorDemo.py
Rajan 466c851743
[CAP] Added a factory for runtime (#3216)
* Added Runtime Factory to support multiple implementations

* Rename to ComponentEnsemble to ZMQRuntime

* rename zmq_runtime

* rename zmq_runtime

* pre-commit fixes

* pre-commit fix

* pre-commit fixes and default runtime

* pre-commit fixes

* Rename constants

* Rename Constants

---------

Co-authored-by: Li Jiang <bnujli@gmail.com>
2024-08-02 00:36:04 +00:00

52 lines
1.8 KiB
Python

import time
from AppAgents import FidelityAgent, FinancialPlannerAgent, PersonalAssistant, QuantAgent, RiskManager
from autogencap.runtime_factory import RuntimeFactory
from termcolor import colored
def complex_actor_demo():
"""
This function demonstrates the usage of a complex actor system.
It creates a local actor graph, registers various agents,
connects them, and interacts with a personal assistant agent.
The function continuously prompts the user for input messages,
sends them to the personal assistant agent, and terminates
when the user enters "quit".
"""
ensemble = RuntimeFactory.get_runtime("ZMQ")
# Register agents
ensemble.register(PersonalAssistant())
ensemble.register(FidelityAgent())
ensemble.register(FinancialPlannerAgent())
ensemble.register(RiskManager())
ensemble.register(QuantAgent())
# Tell agents to connect to other agents
ensemble.connect()
# Get a channel to the personal assistant agent
pa = ensemble.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
can interact with the personal assistant agent by entering
their name. The personal assistant agent will then enlist
the other four agents to create a financial plan.
Start by entering your name.
"""
print(colored(info_msg, "blue"))
while True:
# For aesthetic reasons, better to let network messages complete
time.sleep(0.1)
# Get a message from the user
msg = input(colored("Enter your name (or quit): ", "light_red"))
# Send the message to the personal assistant agent
pa.send_txt_msg(msg)
if msg.lower() == "quit":
break
# Cleanup
pa.close()
ensemble.disconnect()