Registering a dice roll agent as a Function

Register a dice roll agent as a Function


This file can be run on any platform supporting Python, with the necessary install permissions. To enable this on DeltaV ↗️ you will need to create and register a Function. You will need to run this file on a device you are able to open a port on.


Supporting documentation

The agent
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)

Was this page helpful?