Creating a simple dice roll Agent on Agentverse
Introduction
The Agentverse provides multiple base templates you can use to start developing agents in a matter of seconds! You can do so by heading to the My Agents tab and click on + New Agent. Here you can choose between a Blank agent and a Skeleton agent, which incorporates some predefined template you can use as a base point for code creation.
In this example we are going to try out the dice roll agent use case.
Prerequisites
Make sure you have read the following resources before going on with this guide:
- Quick Start Guide for uAgents Framework
- Creating your first agent
- Agents address
- Almanac contract
- Register in Almanac
- Agents running on Agentverse
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:
agent.py""" This agent can create a simple dice roll, it is compatible with DeltaV. """ import random from uagents import Agent, Context, Field, Model, Protocol from ai_engine import UAgentResponse, UAgentResponseType agent = Agent() 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): """Simulate a dice roll for the specified number of times and sends the results.""" 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) if __name__ == "__main__": agent.run()
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!
Great! You have just created your agent starting from a predefined template in Agentverse! You are now ready to understand how to enroll your agent on the Agentverse and make it retrievable by the AI Engine and subsequently DeltaV.
Check out the following resources to better grasps all of these concepts:
- Agentverse Functions .
- Agentverse Functions: register your Agents Functions on the Agentverse! .
- Agentverse Functions: register a coin toss agent as a Function .