Agentverse Functions: register a dice roll agent as a Function 🎲

Agentverse Functions: register a dice roll agent as a Function 🎲


In the previous section ↗ī¸ you have got familiar with the creation of a coin toss agent function that can be registered as a Function and then used via DeltaV ↗ī¸.

In this example we are going to try out another use case: a dice roll agent.


Checkout the Agentverse Functions ↗ī¸ guide for additional information needed for Agents Functions registration on the Agentverse and Fetch network.

Create your dice roll agent!

For this navigate to the Agentverse: My Agents ↗ī¸ (opens in a new tab) tab and click on the Use case button:

When the dialog is open, select the DeltaV compatible Dice Roll Agent use case:

Now, a new agent has been created for you:

Run your dice roll agent!

After clicking on the row of your newly created agent, you should be able to see the source code of your dice roll agent in the editor view:
# Here we demonstrate how we can create a simple dice roll agent that is compatible with DeltaV.
# After running this agent, it can be registered to DeltaV on Agentverse My Agents tab. For registration you will have to use the agent's address.
import random
# third party modules used in this example
from pydantic import Field
from ai_engine import UAgentResponse, UAgentResponseType
class DiceRoll(Model):
    num_rolls: int = Field(description="Number of rolls.")
dice_roll_protocol = Protocol("DiceRoll")
@dice_roll_protocol.on_message(model=DiceRoll, replies={UAgentResponse})
async def roll_dice(ctx: Context, sender: str, msg: DiceRoll):
    result = ", ".join([str(random.randint(1, 6)) for _ in range(msg.num_rolls)])
    message = f"Dice roll results: {result}"
    await ctx.send(
        sender, UAgentResponse(message=message, type=UAgentResponseType.FINAL)
agent.include(dice_roll_protocol, publish_manifest=True)

Now click on the Run button in the upper right corner of the editor so that you have your dice roll agent up and running!

Register your dice roll agent Function!

Similar to the Agentverse Functions: register a coin toss agent as a Function đŸĒ™ ↗ī¸, let's navigate to the Agentverse: My Agents ↗ī¸ (opens in a new tab) tab. Here, click on your agent to show the Agent Editor and then click on the Deploy tab to start registering your agent function. Fill the form out as follows:

  • Function title: just the name of your Agent Function. In this example let's call it Dice roll service.
  • Description: super important to be as detailed as you can, as reasoning engine looks at descriptions to understand what your function does. In this example we can specify something like this: Dice roll Function that rolls a dice. The number of rolls is specified by the user.
  • Application, Protocol, Model and Field descriptions will be automatically populated based on the source code of your dice roll agent ↗ī¸

Let's find our Function on DeltaV

Now, head to DeltaV ↗ī¸ (opens in a new tab) and sign in.

First, in the What function would you like to assemble bar you can provide a predefined objective; let's type Roll a dice.

After navigating to the chat interface, you will be asked to select a primary function. As your objective (Roll a dice) specified on the previous screen contained words related to the description of your dice roll agent ↗ī¸, your DiceRoll Function is listed as an option. Let's select it.

After selecting the task, you will be asked about the number of rolls you want to do. The AI Engine behind DeltaV asks this question based on the description Number of rolls. that was specified in the predefined use case before ↗ī¸. Send the number of rolls in the input field at the bottom of the screen - in this case let's stick with 10.

Then, you can confirm or reject the context that the AI Engine is planning to execute. Let's confirm it!

After your service has been executed you can see your dice roll results.

With that, you have gotten a dice roll function which can be discovered and contacted with DeltaV. Awesome!

Was this page helpful?