Description
What happened?
Describe the bug
The Autogen core distributed group chat sample (https://github.com/microsoft/autogen/blob/main/python/samples/core_distributed-group-chat) works when running it on local system. The app runs successfully on both Linux and Windows OS when tested locally. However, the problem arises during deployment on Azure Container App. It seems host.stop_when_signal() is not working as expected when app is deployed to Azure Container App. It looks like the issue is related to the event handler—it’s stopping unexpectedly without listening to any events.
To Reproduce
Code referenced from: https://github.com/microsoft/autogen/blob/main/python/samples/core_distributed-group-chat/run_host.py
run_host.py
import os
import asyncio
from autogen_ext.runtimes.grpc import GrpcWorkerAgentRuntimeHost
class Config:
HOST = "0.0.0.0"
PORT = "50051"
async def main():
"""
Initializes and starts the gRPC server GrpcWorkerAgentRuntimeHost.
"""
config = Config()
address = f"{config.HOST}:{config.PORT}"
host = GrpcWorkerAgentRuntimeHost(address)
host.start()
print(f"Distributed Host is now running and listening for connection at {address}")
try:
print(f"Detected OS: {os.name}")
# wait for the service to stop
if os.name == "nt":
# on windows, the signal is not available, so we wait for a new event
print("windows")
await asyncio.Event().wait()
else:
print("other os")
await host.stop_when_signal()
except KeyboardInterrupt:
print("Stopping service due to KeyboardInterrupt..")
finally:
await host.stop()
print("Stopping host")
if __name__ == "__main__":
asyncio.run(main())
Stacktrace:
Traceback (most recent call last):
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/app/main.py", line 40, in main
await host.stop()
File "/usr/local/lib/python3.11/site-packages/autogen_ext/runtimes/grpc/_worker_runtime_host.py", line 42, in stop
raise RuntimeError("Host runtime is not started.")
RuntimeError: Host runtime is not started.
Expected behavior
The runtime host should be listening for events after starting while keeping the GrpcWorkerAgentRuntimeHost running so that other agents can be registered to the given runtime and stop the server only when a signal is received. And the execution of the program should not halt to stop the host runtime. It should continue execution so that other agents can be registered to the host runtime.
Screenshots
Container App Logs:
As you can see below in log its reaching to finally block without waiting to listen for events in the else block.
Which packages was the bug in?
Python Core (autogen-core)
AutoGen library version.
Python 0.4.9
Other library version.
No response
Model used
No response
Model provider
None
Other model provider
No response
Python version
3.11
.NET version
None
Operating system
Ubuntu