Agentverse
Utilising the Agentverse Mailbox Service πŸ“¬

Utilising the Agentverse Mailbox Service πŸ“¬

Introduction

The Mailroom helps you setting up mailboxes for your locally-run uAgents so to avoid having them online all the time to communicate with one another and do not require your constant presence to run them.

Registering in the Mailroom

Through this service, communication between uAgents registered in the Agentverse and communication between these and local agents is made possible. In fact, your locally hosted agents can access the API to retrieve the information needed for communicating with the other agents registered with the Agentverse. You can use the Agentverse Explorer ↗️ (opens in a new tab) to find other agents and register your own. To accomplish this, your local agents will use the Agentverse URL and API keys to collect messages. To do so, after registering your first agent in the Mailbox Server, you can easily create a new secondary agent by selecting + Agent in the Managed Agents section of the Agentverse, and then continue writing the script for this agent by defining the first agent address into it, so for your second agent to be able to send messages towards it.

The first thing to do to use this service is to create an API key. To do so, you need to navigate and click on your account icon in the top right corner and choose API keys. Here, you will need to create your API key by providing a name for it.

Once you created it, you can navigate towards the Mailroom section of the Agentverse and create your first Mailbox Server. Within the Mailroom, click on + Mailbox to register an agent. To create a Mailbox Server for your agent you will need to first select a name for it and provide the agent's address.

Walk-through

To register agents in the Agentverse Mailbox Service:

  1. First of all, you need to sign in at the Agentverse ↗️ (opens in a new tab).

  2. After signing in, you need to head towards the upper right corner and click on your profile icon and select API Keys. Select Create new key and name it. This will generate your own API Key that will allow you to use the Mailbox server.

  3. You would then need to navigate to the Mailroom tab and select + Mailbox to register an agent. First, you need to select a name for it and provide the agent's address. Finally, you will then need to include the Mailbox Server and API key just created within the script for your agent so for your registered agents to start communicating with it. This can be added in the following way:

    # First generate a secure seed phrase (e.g. https://pypi.org/project/mnemonic/)
    SEED_PHRASE = "put_your_seed_phrase_here"
     
    # Copy the address shown below
    print(f"Your agent's address is: {Agent(seed=SEED_PHRASE).address}")
     
    # Then sign up at https://agentverse.ai to get an API key and register your agent
    API_KEY = "put_your_API_key_here"
     
    # Now your agent is ready to join the agentverse!
    agent = Agent(
        name="alice",
        seed=SEED_PHRASE,
        mailbox=f"{API_KEY}@wss://agentverse.ai",
    )

Agentverse and Local Agents

Communication between agentverse uAgents and local uAgents is also possible. All you need to do is provide the target address of the agentverse agent. Your local agents will use the Agentverse URL and API keys to collect messages. To do so, after registering your first agent in the mailbox server, you can easily create a new secondary agent by selecting + Agent in the Managed Agents section of the Agentverse, and then continue writing the script for this agent by defining the first agent address into it, so for your second agent to be able to send messages towards it.

The steps you need to follow are the following:

  1. After registering uAgent alice on the mailbox server, you can easily create a new agentverse agent bob by selecting + Agent on Managed Agents in the Agentverse ↗️ (opens in a new tab).

  2. Then, you would need to add the following code to bob's script:

    class Message(Model):
        message: str
     
    @bob.on_message(model=Message)
    async def handle_message(ctx: Context, sender: str, msg: Message):
        ctx.logger.info(f"Received message from {sender}: {msg.message}")
     
        await ctx.send(sender, Message(message="hello there alice"))
  3. Next, you need to copy bob's address and define it within alice's code under RECIPIENT_ADDRESS.

  4. Once you've done this, run agent bob on the Agentverse ↗️ (opens in a new tab) followed by your local agent alice. You will then be able to send messages back and forth between the two agents, which will be displayed on both alice's and bob's terminals.

For a better understanding and visualisation of the topic, you could have a look at the uAgents Remote Communication: the AgentVerse Mailbox Service section in the Communicating with other uAgents πŸ“±πŸ€– ↗️️ guide.