Greeter Receiver Cycle

This example demonstrates a simple distributed agent system using agentopera.

It includes:

  • A DistAgentEngine Server that coordinates communication between agents.

  • Two agents: GreeterAgent and ReceiveAgent.

  • A feedback communication cycle between them.

1️⃣ Start the Distributed Agent Server

This server listens on localhost:50051 and handles all agent communication.

import asyncio
import os
from agentopera.engine.runtime.distributed import DistAgentEngineSrv

async def start_server():
    service = DistAgentEngineSrv(address="localhost:50051")
    service.start()
    try:
        if os.name == "nt":
            await asyncio.Event().wait()
        else:
            await service.stop_when_signal()
    except KeyboardInterrupt:
        print("Stopping service...")
    finally:
        await service.stop()

Run this cell manually in a separate notebook or terminal!

asyncio.run(start_server())

2️⃣ Define Agents and Message Types

Here we define the GreeterAgent and ReceiveAgent, and the data messages they'll exchange.

3️⃣ Run the Distributed Engine & Start Agents

In this step, we start the GreeterAgent and ReceiveAgent and send the first message.

Last updated