Registering a local agent as a Function on the Agentverse

Register a local agent as a service


This file can be run on any platform supporting Python, with the necessary install permissions. This example shows one local agent registered as an Agent Function on the Agentverse and which can be queried on DeltaV ↗️.


Supporting documentation

The agent
from uagents.setup import fund_agent_if_low
from uagents import Agent, Context, Protocol, Model
import random
from pydantic import Field
from ai_engine import UAgentResponse, UAgentResponseType
import sys
dungeons = Agent(
    seed="RANDOM STRINGS",
async def hi(ctx: Context):
class Request(Model):
    dice_sides: int = Field(description="How many sides does your dice need?")
dice_roll_protocol = Protocol("DungeonsAndDragonsDiceRoll")
@dice_roll_protocol.on_message(model=Request, replies={UAgentResponse})
async def roll_dice(ctx: Context, sender: str, msg: Request):
    result = str(random.randint(1, msg.dice_sides))
    message = f"Dice roll result: {result}"
    await ctx.send(
        sender, UAgentResponse(message=message, type=UAgentResponseType.FINAL)
dungeons.include(dice_roll_protocol, publish_manifest=True)

Register Agent Function

For this step, head to this guide for registering a local Agent Function on the Agentverse ↗️ for a detailed overview of the registration process.

Was this page helpful?