Skip to Content

Agent Functions

Agents can act as executable functions for ASI-1 Mini. By registering your Agent’s function on the Agentverse platform, ASI-1 Mini can discover, index, and interact with it directly. This enables seamless communication between the LLM and your Agent, allowing it to act autonomously and perform real-world tasks based on AI-driven reasoning.

Check out this example for a better understanding of how to integrate ASI-1 LLM.

Imports needed

Local Agent Function registration

Sometimes you’ll want to run an Agent on your own hardware or infrastructure; luckily this is very easy to do on any system that support Python 3.10. We refer tho these Agents as Local Agents.

Overview

This system is pretty simple and makes you get started as quickly as possible. You can run this Agent on any device you’d like; in this scenario we’re running on a VM, but you could run this on your laptop, raspberry pi or tweak for Agentverse.

On startup our script will register our Agent to the Almanac, and then our Agent will be available to communicate with other Agents.

The Agent

simple_function.py
from uagents.setup import fund_agent_if_low from uagents import Agent, Context, Protocol, Model import random from uagents import Field from ai_engine import UAgentResponse, UAgentResponseType import sys dungeons = Agent( name="dungeonsanddragonsdiceroll", port=6145, seed="RANDOM STRINGS", endpoint=["http://YOUR_IP:6145/submit"], ) fund_agent_if_low(dungeons.wallet.address()) @dungeons.on_event("startup") async def hi(ctx: Context): ctx.logger.info(dungeons.address) 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) dungeons.run()

It is important that you provide the name, port, seed and endpoint for your Agent to correctly run this code.

A few things to note; you’ll need to be running this Agent on infrastructure that allows you to open a port, in our example we run on port 6145. The agent is initialized with an endpoint, and a port - this is so that we can receive messages, and other Agents know where to send them. On the Testnet, you can use the fund_agent_if_low to get some funds, if you need them to register your Agent to the Almanac. We then define the protocol, which is just an int as seen in the Request object.

The on_message doesn’t do much other than return a number between 1 and the defined dice_sides from the message inclusive. However, the response type is of UAgentResponse.

.run() initializes the Agent.

Finally, we run our Agent as follows: python simple_function.py

Expected output:

INFO: [dungeonsanddragonsdiceroll]: Manifest published successfully: DungeonsAndDragonsDiceRoll INFO: [dungeonsanddragonsdiceroll]: Registration on Almanac API successful INFO: [dungeonsanddragonsdiceroll]: Registering on almanac contract... INFO: [dungeonsanddragonsdiceroll]: Registering on almanac contract...complete INFO: [dungeonsanddragonsdiceroll]: Agent inspector available at https://agentverse.ai/inspect/?uri=http%3A//127.0.0.1%3A6145&address=agent1qvwk0ntr38yyghccrg530hnnm88r5uske4hdcalsa7gqp7sjgx42k4mp62r INFO: [dungeonsanddragonsdiceroll]: agent1qvh76795enwgnzkrjpedlnqxwv83d8wxnkkcszs9z46zc3qpfs3yvzc5kuw INFO: [dungeonsanddragonsdiceroll]: Starting server on http://0.0.0.0:6145 (Press CTRL+C to quit)

Register a local Agent Function on the Agentverse

For this example we set up a really simple Agent Function.

For further information on Agent Functions and registration process on the Agentverse, see the Register Agent Functions on the Agentverse resource.

To register Local Agents and Functions, you will first need to head over to the local Agent Inspector available by clicking on the dedicated link presented within your terminal output after running the above local Agent. Once you do so, click on Connect button and select Mailbox. Follow the steps closely and provide all needed data required.

After this, click Connect.

At this point, you do not need to do anything else. Click Finish.

Once your agent is connected via the Mailbox correctly, you will see a box depicting it within the My Agents tab.

Click on it and head over to the Deploy tab and click on + New Function.

Here, you can now provide the needed details for your Agent Function in the dedicated fields. Remember to provide detailed descriptions for what your Agent Function does and the Fields for data Models expected. understanding of Functions fields descriptions.

It’s recommended you alter the contract slightly, and follow the above steps so that you can run an Agent, create a function for the Agent and then have that Agent accessible on Agentverse.

Description of your Agent Function

The Description is super important to the success of your Agent Function. The ASI-1 LLM will catalogue descriptions and parse these into its understanding. Make sure to be descriptive of what your Agent Function does, and be sure to reinforce keywords with repetition.

Read more and see examples on how to properly set field descriptions by heading over to: Field descriptions guide.

Primary and Secondary Functions

Primary and Secondary functions are different but have strong similarities.

The first one is the primary Agent Function and for instance, it could be an agent that would respond to a user. Primary Functions are expected to fully or partially fulfill an objective provided by users.

Similarly, a Secondary function is an Agent Sub-function providing secondary functionalities that likely need additional context or information to carry out the Primary Function. Secondary Functions are executed in combination with the Objective task. If that’s the case, the system would see that the Agent Primary Function can be fulfilled by executing a Secondary Function, thus, it will contact this latter one which may or may not require gaining context directly from the user.

ℹ️

You can include hyperlinks using standard HTML tags for clickable links. For more details, refer to the guide on rich text and hyperlinks.

Functions registration resources

For further information and examples on how to register an Agent Function on Agentverse and make it discoverable to ASI-1 Mini, check out our dedicated resource: Register Agentverse Functions.

For any additional questions, the Team is waiting for you on Discord and Telegram channels.

Last updated on