Multiple agents communication
Bookmark

Multiple agents communication

Introduction

This file can be run on any platform supporting Python, with the necessary install permissions. This example shows how to create two different agents and make them communicate using the uAgents Python library.

Supporting documentation

The agent

agents.py
from uagents import Agent, Bureau, Context
 
alice = Agent(name="alice")
bob = Agent(name="bob")
 
@alice.on_interval(period=2.0)
async def introduce_alice(ctx: Context):
    ctx.logger.info(f"Hello, I'm agent {ctx.name}.")
 
@bob.on_interval(period=2.0)
async def introduce_bob(ctx: Context):
    ctx.logger.info(f"Hello, I'm agent {ctx.name}.")
 
bureau = Bureau()
bureau.add(alice)
bureau.add(bob)
 
if __name__ == "__main__":
    bureau.run()

Was this page helpful?

Bookmark