This example runs a gRPC server using [GrpcWorkerAgentRuntimeHost](../../src/autogen_core/application/_worker_runtime_host.py) and instantiates three distributed runtimes using [GrpcWorkerAgentRuntime](../../src/autogen_core/application/_worker_runtime.py). These runtimes connect to the gRPC server as hosts and facilitate a round-robin distributed group chat. This example leverages the [Azure OpenAI Service](https://azure.microsoft.com/en-us/products/ai-services/openai-service) to implement writer and editor LLM agents. Agents are instructed to provide concise answers, as the primary goal of this example is to showcase the distributed runtime rather than the quality of agent responses.
In the `config.yaml` file, you can configure the `client_config` section to connect the code to the Azure OpenAI Service.
### Authentication
The recommended method for authentication is through Azure Active Directory (AAD), as explained in [Model Clients - Azure AI](https://microsoft.github.io/autogen/dev/user-guide/core-user-guide/framework/model-clients.html#azure-openai). This example works with both the AAD approach (recommended) and by providing the `api_key` in the `config.yaml` file.
## Run
### Run Through Scripts
The [run.sh](./run.sh) file provides commands to run the host and agents using [tmux](https://github.com/tmux/tmux/wiki). The steps for this approach are:
1. Install tmux.
2. Activate the Python environment: `source .venv/bin/activate`.
**Note**: Some `asyncio.sleep` commands have been added to the example code to make the `./run.sh` execution look sequential and visually easy to follow. In practice, these lines are not necessary.
### Run Individual Files
If you prefer to run Python files individually, follow these steps. Note that each step must be run in a different terminal process, and the virtual environment should be activated using `source .venv/bin/activate`.
1.`python run_host.py`: Starts the host and listens for agent connections.
2.`chainlit run run_ui.py --port 8001`: Starts the Chainlit app and UI agent and listens on UI topic to display messages. We're using port 8001 as the default port 8000 is used to run host (assuming using same machine to run all of the agents)
3.`python run_editor_agent.py`: Starts the <imgsrc="./public/avatars/editor.png"width="20"height="20"style="vertical-align:middle"> editor agent and connects it to the host.
4.`python run_writer_agent.py`: Starts the <imgsrc="./public/avatars/writer.png"width="20"height="20"style="vertical-align:middle"> writer agent and connects it to the host.
5.`python run_group_chat_manager.py`: Run chainlit app which starts <imgsrc="./public/avatars/group_chat_manager.png"width="20"height="20"style="vertical-align:middle"> group chat manager agent and sends the initial message to start the conversation.
1. The <imgsrc="./public/avatars/group_chat_manager.png"width="20"height="20"style="vertical-align:middle"> Group Chat Manager, on behalf of <imgsrc="./public/avatars/user.png"width="20"height="20"style="vertical-align:middle">`User`, sends a `RequestToSpeak` request to the <imgsrc="./public/avatars/writer.png"width="20"height="20"style="vertical-align:middle">`writer_agent`.
2. The <imgsrc="./public/avatars/writer.png"width="20"height="20"style="vertical-align:middle">`writer_agent` writes a short sentence into the group chat topic.
3. The <imgsrc="./public/avatars/editor.png"width="20"height="20"style="vertical-align:middle">`editor_agent` receives the message in the group chat topic and updates its memory.
4. The <imgsrc="./public/avatars/group_chat_manager.png"width="20"height="20"style="vertical-align:middle"> Group Chat Manager receives the message sent by the writer into the group chat simultaneously and sends the next participant, the <imgsrc="./public/avatars/editor.png"width="20"height="20"style="vertical-align:middle">`editor_agent`, a `RequestToSpeak` message.
5. The <imgsrc="./public/avatars/editor.png"width="20"height="20"style="vertical-align:middle">`editor_agent` sends its feedback to the group chat topic.
6. The <imgsrc="./public/avatars/writer.png"width="20"height="20"style="vertical-align:middle">`writer_agent` receives the feedback and updates its memory.
7. The <imgsrc="./public/avatars/group_chat_manager.png"width="20"height="20"style="vertical-align:middle"> Group Chat Manager receives the message simultaneously and repeats the loop from step 1.
- [ ] Add streaming to the UI like [this example](https://docs.chainlit.io/advanced-features/streaming) when [this bug](https://github.com/microsoft/autogen/issues/4213) is resolved