fetch-logo
ConceptsConceptsGuidesGuidesExamplesExamplesReferencesReferencesAPIsAPIs
GitHub (opens in a new tab)
  • Examples
      • Create your first agent
      • Interval task with Agents
      • Multiple agents communication
      • Local Network Interaction
      • Agents communication
      • Agents storage
      • Table booking service with Agents
      • Cleaning service with Agents
      • Send tokens with Agents
      • Verify messages with Agents
      • Communicating with other agents wallet
      • Agents communication using Agentverse Mailbox service
      • Agents Broadcast
      • Agents Name Service
      • Query an agent using a proxy API
      • Register a dice roll agent as a Function
      • Register a coin toss agent as a Function
      • Register a local agent as a Function
      • Using News API to build network of Primary and Secondary functions
      • Locally Hosted Agent with LangChain Integration
      • Hugging face API agent as a Function
      • On Query decorator example
      • Agents and Functions Creation using APIs
      • Adding Secret to agent using Agentverse API
      • React app with agents 'on_query' decorator
      • Open Dialogue Chit-Chat
      • Predefined Dialogue Chit-Chat
      • Chat API example
      • DeltaV Dialogue Chit-Chat
  • Examples
      • Create your first agent
      • Interval task with Agents
      • Multiple agents communication
      • Local Network Interaction
      • Agents communication
      • Agents storage
      • Table booking service with Agents
      • Cleaning service with Agents
      • Send tokens with Agents
      • Verify messages with Agents
      • Communicating with other agents wallet
        • Introduction
      • Agents communication using Agentverse Mailbox service
      • Agents Broadcast
      • Agents Name Service
      • Query an agent using a proxy API
      • Register a dice roll agent as a Function
      • Register a coin toss agent as a Function
      • Register a local agent as a Function
      • Using News API to build network of Primary and Secondary functions
      • Locally Hosted Agent with LangChain Integration
      • Hugging face API agent as a Function
      • On Query decorator example
      • Agents and Functions Creation using APIs
      • Adding Secret to agent using Agentverse API
      • React app with agents 'on_query' decorator
      • Open Dialogue Chit-Chat
      • Predefined Dialogue Chit-Chat
      • Chat API example
      • DeltaV Dialogue Chit-Chat
Examples
Intermediate topics
Communicating with other agents wallet

Communicating with other agents wallet

Introduction

Communication is an essential feature agent network. It allows agents to work together, exchange information, and forms an organic marketplace. Wallet messaging is feature of agents which makes them able to communicate with other agent's wallet information. This can include sending and receiving payments, querying account balances, and handling other wallet-related tasks.

In this example we will create two agents locally using uagents library and make them share wallet information with each other.

Supporting documentation

  • Creating an agent↗️
  • Creating an interval task ↗️
  • Communicating with other agents ↗️
  • Register in Almanac ↗️
  • Almanac Contract ↗️
  • Agents address ↗️

Script Breakdown

  • Importing required libraries
from uagents import Agent, Bureau, Context
from uagents.wallet_messaging import WalletMessage

This step imports necessary libraries for creating agents and handling wallet messaging.

  • Defining two agents which can communicate to each other.
# Defining agent's seeds
ALICE_SEED = "alice dorado recovery phrase"
BOB_SEED = "bob dorado recovery phrase"
 
# Defining agents
alice = Agent(name="alice", seed=ALICE_SEED, enable_wallet_messaging=True)
bob = Agent(name="bob", seed=BOB_SEED, enable_wallet_messaging=True)

This step defines two agents, Alice and Bob, using predefined seed phrases. These agents will communicate with each other's wallets.

  • Agent 1 wallet message handler:
# Define wallet message handler for alice
@alice.on_wallet_message()
async def reply(ctx: Context, msg: WalletMessage):
    ctx.logger.info(f"Got wallet message: {msg.text}")
    await ctx.send_wallet_message(msg.sender, "hey, thanks for the message")

This step defines a message handler for Alice, which responds to incoming wallet messages from Bob. Upon receiving a message, Alice sends a reply.

  • Agent 2 wallet message handler and on_interval sender:
# Sending message to Alice every 5 seconds
@bob.on_interval(period=5)
async def send_message(ctx: Context):
    ctx.logger.info("Sending message...")
    await ctx.send_wallet_message(alice.address, "hello")
 
# Define wallet message handler for bob
@bob.on_wallet_message()
async def wallet_reply(ctx: Context, msg: WalletMessage):
    ctx.logger.info(f"Got wallet message: {msg.text}")

This step defines a message handler for Bob, which logs incoming wallet messages. Additionally, it sets up an interval function for Bob to send a message to Alice every 5 seconds.

  • Defining Bureau and adding agents:
# Define bureau and adding agents
bureau = Bureau()
bureau.add(alice)
bureau.add(bob)
bureau.run()

This step creates a Bureau, which manages the agents, and adds both Alice and Bob to it. Then, it starts the bureau to begin agent interactions.

Whole Script

This section presents the entire script in one block, allowing users to easily copy and paste it for testing or deployment.

from uagents import Agent, Bureau, Context
from uagents.wallet_messaging import WalletMessage
 
ALICE_SEED = "alice dorado recovery phrase"
BOB_SEED = "bob dorado recovery phrase"
 
alice = Agent(name="alice", seed=ALICE_SEED, enable_wallet_messaging = True)
bob = Agent(name="bob", seed=BOB_SEED, enable_wallet_messaging = True)
 
 
@alice.on_wallet_message()
async def reply(ctx: Context, msg: WalletMessage):
    ctx.logger.info(f"Got wallet message: {msg.text}")
    await ctx.send_wallet_message(msg.sender, "hey, thanks for the message")
 
@bob.on_interval(period=5)
async def send_message(ctx: Context):
    ctx.logger.info("Sending message...")
    await ctx.send_wallet_message(alice.address, "hello")
 
@bob.on_wallet_message()
async def wallet_reply(ctx: Context, msg: WalletMessage):
    ctx.logger.info(f"Got wallet message: {msg.text}")
 
bureau = Bureau()
bureau.add(alice)
bureau.add(bob)
bureau.run()

Script Execution

  • Open terminal and navigate to the folder where wallet_messaging.py is stored.
  • Run pip3 install uagents on your terminal.
  • Execute wallet_messaging.py using python wallet_messaging.py on terminal.

Expected Output

INFO:     [alice]: Connecting to wallet messaging server
INFO:     [  bob]: Sending message...
INFO:     [  bob]: Connecting to wallet messaging server
INFO:     [bureau]: Starting server on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO:     [alice]: Got wallet message: hello
INFO:     [  bob]: Got wallet message: hey, thanks for the message
INFO:     [  bob]: Sending message...
INFO:     [alice]: Got wallet message: hello
INFO:     [  bob]: Got wallet message: hey, thanks for the message

Was this page helpful?

Verify messages with AgentsAgents communication using Agentverse Mailbox service
footer-logo

Main website

Integrations

Events

We’re hiring!

Twitter (opens in a new tab)Telegram (opens in a new tab)Discord (opens in a new tab)GitHub (opens in a new tab)Youtube (opens in a new tab)LinkedIn (opens in a new tab)Reddit (opens in a new tab)
Sign up for developer updates