mirror of
https://github.com/microsoft/autogen.git
synced 2025-10-04 20:46:11 +00:00

* First pass: message loop in main thread * pypi version bump * Fix readme * Better example * Fixed docs * pre-commit fixes * Convenience methods for protobufs * support non-color consoles * Non-color console and allow user input * Minor update to single_threaded_demo * new pypi version * pre-commit fixes * change pypi name --------- Co-authored-by: Qingyun Wu <qingyun0327@gmail.com>
45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
import _paths
|
|
from AppAgents import GreeterAgent
|
|
from autogencap.ComponentEnsemble import ComponentEnsemble
|
|
from autogencap.DebugLog import Error
|
|
from autogencap.proto.CAP_pb2 import Ping
|
|
|
|
|
|
def single_threaded_demo():
|
|
"""
|
|
Demonstrates the usage of the CAP platform by registering an actor, connecting to the actor,
|
|
sending a message, and performing cleanup operations.
|
|
"""
|
|
# CAP Platform
|
|
ensemble = ComponentEnsemble()
|
|
agent = GreeterAgent(start_thread=False)
|
|
ensemble.register(agent)
|
|
ensemble.connect()
|
|
greeter_link = ensemble.find_by_name("Greeter")
|
|
greeter_link.send_txt_msg("Hello World!")
|
|
|
|
no_msg = 0
|
|
|
|
# This is where we process the messages in this thread
|
|
# instead of using a separate thread
|
|
|
|
# 5 consecutive times with no message received
|
|
# will break the loop
|
|
while no_msg < 5:
|
|
# Get the message for the actor
|
|
message = agent.get_message()
|
|
# Let the actor process the message
|
|
agent.dispatch_message(message)
|
|
# If no message is received, increment the counter otherwise reset it
|
|
no_msg = no_msg + 1 if message is None else 0
|
|
|
|
ensemble.disconnect()
|
|
|
|
|
|
def main():
|
|
single_threaded_demo()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|