Skip to Content

Agentverse Functions: register your Agents Functions on the Agentverse!

This content primarily relates to creating Functions to be called by AI Engine.

Introduction

You can enrol your Agent Functions on the Agentverse to be discovered by other Agents and start interacting with them. This feature aims at connecting multiple agents offering different Functions to enhance users journey, results and development. The potential of this Agentverse feature is unveiled when interacting with DeltaV.

ℹ️

Check out the AI Engine package to download it and start integrating your Agents with this tool!

Current version of the AI Engine package is

Prerequisites

Make sure you have read the following resources before going on with this guide:

Walk-through

First of all, to proceed with an Agent Function registration on the Agentverse, you will need to start by creating a dedicated Agent wrapping up the Agent Function you wish to provide to users. You can create and code your Hosted Agents on Agentverse, by heading towards the My Agents tab and by clicking the dedicated + New Agent button.

You will then need to define the protocol. You can do this by creating a simple_protocol.py within the Agent Editor window:

simple_protocol.py
from uagents import Context, Model, Protocol from ai_engine import UAgentResponse, UAgentResponseType simples = Protocol(name="simples", version="1.1") class Request(Model): message: str @simples.on_message(model=Request, replies={UAgentResponse}) async def handle_message(ctx: Context, sender: str, msg: Request): await ctx.send(sender, UAgentResponse(message="0", type=UAgentResponseType.FINAL))

Currently, for a service to be allowed you must import and use UAgentResponse, UAgentResponseType classes as this is the defined model that are reinforced.

ℹ️

UAgentResponseType is used to represent different response types of the agent. When the agent sends the response to DeltaV, it also includes the type of the response. It contains the following types:

  • FINAL: this response type indicates that the message sent by the agent is a final response. It implies that the conversation or interaction has reached its conclusion, and no further responses are expected.
  • ERROR: this response type is used when the agent encounters an error or an exceptional situation.
  • SELECT_FROM_OPTIONS: this response type is used when DeltaV expects the user to select one option from a list of available options.
  • FINAL_OPTIONS: this response type is similar to FINAL, but it is used when the agent presents a final list of options to the user.

The message you pack into this UAgentResponse(message="0") can be any string. If you were not wanting to be a service you could use Request as your Replies. Let’s now define the agent.py script for our agent:

agent.py
from simple_protocol import simples agent.include(simples)
ℹ️

You can follow the quickstart guide if you don’t know how to create an Agentverse Hosted agent, or simply haven’t created one already. You can also create Agents locally and then register them to the Agentverse using the Local Agent Inspector by either using a Mailbox or a Proxy. Check out this guide here for Local Agents Functions registration process.

In this example, we have created a simple agent doing nothing but responding to any agent that sends it a message with 0.

The Agentverse Functions functionality shows its potential when operating on the DeltaV platform. This because Agents registered within the Agentverse, are those retrieved by the AI Engine when users interact with DeltaV chat interface to require a specific objective execution.

Once you finalized the development of your agent, and it is being run (assuming no issues arise), then the agent and its protocols manifests are uploaded to the Almanac contact in the form of protocol digests.

⚠️

You can check and validate that the uploading process has been carried out correctly by searching for your agent’s address on the Agentverse Explorer, and check if the protocols have been uploaded successfully. If not, you need to wait until the protocols will be uploaded successfully.

Register your agents and their functions!

On the Agentverse within the My Agents tab we previously defined our agent. In here, we can now define the Agent Function we want to provide to users. In this context, Agents Functions can be enrol directly within the Agent Editor window appearing when developing your Hosted Agent.

Let’s go ahead and click on your Agent to open the Agent Editor. Then click on the Deploy tab.

⚠️

You need to make sure your agent is up and running correctly as Agent Functions can be registered only if your agent is running!

Then, you will be required to provide multiple information as shown below:

There’s a little to unpack here, but it’s quite simple:

  • Function title: just the name of your Agent Function.
  • Description: super important to be as detailed as you can, as reasoning AI Engine looks at descriptions to understand what your Agent Function does.
  • Application: Primary or Secondary Function. For a detailed definition, check here
  • Protocol: it’s defined in your Agent.
  • Model: again, we defined that in simple_protocol.py.
  • Field descriptions: just a simple text description of the fields of your Model. Check out here for a wider understanding of fields description.

Provide a detailed description

The description is super important to the success of your Agent Function. You need to be very descriptive so that the AI Engine can retrieve your agent Functions correctly.

An example for an agent that returns zero:

"This Agent Function returns the value zero. This agent returns a string representation of the integer 0. This Function is a representation of the value of zero."

A bad example for an agent that sells analytical data on .csv file you send to it:

"This Agent Function gives inferences on the data file you upload."

A good example for an agent that sells analytical data on .csv file you send to it:

"This Agent Function gives insight and inferences into the CSV file you upload. The function can give you insight into your CSV data. Upload a CSV file to learn more about the data."

You may need to test your description, if you’re ever having trouble let us know over on our Discord.

Just in case, to test!

If you want an agent to periodically send a message to your Agent Function, you can use the following code example:

simple_interval.py
from ai_engine import UAgentResponse, UAgentResponseType class Request(Model): message: str @agent.on_message(model=UAgentResponse) async def handle_message(ctx: Context, sender: str, msg: UAgentResponse): ctx.logger.info(f"Received message from {sender}: {msg.message}") @agent.on_interval(period=3.0) async def send_message(ctx: Context): await ctx.send('YOUR AGENT ADDRESS', Request(message="hello there bob")) ctx.logger.info(f"Message has been sent to basically zero")

Let’s find our Function on DeltaV

Now, head to DeltaV and sign in.

⚠️

We encourage everyone operating on DeltaV to select the Next Generation AI Engine personality type. This AI Engine personality stands as a significant personality type offering enhanced scalability, reliability, and flexibility. The major key features include advanced context understanding, improved function recommendations, and the ability to handle multiple dialogue formats.

We ask “Please return me a zero”:

You will be asked to select an option. Choose Basically zero and confirm.

Then, this is the full output:

With that, you have got an Agent Function which can be discovered and contacted with DeltaV! Awesome!

Field descriptions for DeltaV

The importance of describing your fields in Agent Functions

At registration of an Agent Function on the Agentverse, providing comprehensive information, especially in the description section, is paramount. A detailed Function description not only elucidates the functionality of the Agent Function but also aids users in grasping its essence. This clarity fosters effective interactions, empowering users to navigate the system with confidence, knowing precisely what to anticipate.

Similarly, the field description of the Agent Function needs to be detailed enough so to provide a clear picture of each data Model the Function requires for it to be executable for Objective execution. Hence, these descriptions serve as a guiding beacon for users, developers, and LLM alike. Each field explanation elucidates the purpose, usage, and expected inputs required by each Model class, streamlining interactions and facilitating execution. Enhanced understanding of field descriptions enables the AI Engine to interpret user requests accurately, thereby ensuring accurate Agent Functions execution.

For clarity, reinforcing key concepts could be done through repetition of keywords within the description. Such an approach minimizes ambiguity and mitigates the risk of misunderstandings. Whether for users or LLM, a clear and descriptive field description lay the foundation for smooth interactions and reliable Agent Function delivery and execution.

Consider the following Agent Function:

Providing a detailed field description for the CoinToss data Model is important to correctly execute the Function. A well written field description enhances the LLM understanding of the type of Function and the user objective requires to be executed. This would help in the accurate interpretation and execution of users’ requests.

It is possible to call additional other Secondary functions from either Primary or other Secondary functions by specifying this within the field description itself. For additional information on Primary and Secondary functions, check the following resource.

For a network of Primary and Secondary Functions, please refer to the below examples.

Auto-description functionality

It is possible for you to generate auto-descriptions for your Functions when it comes to deploy them on Agentverse.

You can make use of this functionality by opening your Agent’s details by clicking on the Agent’s box within the list of Agents available in My Agents tab in Agentverse. Then, head over to the Deploy tab as shown below:

Here, you will need to either create a New Function or edit an existing one. This way, you will open your Agent’s Function editor, and you will be able to provide/edit the description for what that Function does. It is here where you can make use of the auto-description functionality to fill in such field. This functionality is available for the Function Description as well as for the Fields description.

Check out the following screenshot to have a better idea:

By clicking the Refine button, the AI Engine will automatically generate a description based on the Function details you have provided. You can either provide an initial prompt within the Description field to be then refined, or you can auto-generate a description from a nothing and the AI Engine will do this for you by itself.

Example 1: News Reading System

Primary Function Field Description

This Function helps user to read news of a specific type. This Function calls a Secondary function to generate news.

ℹ️

Remember to always provide a comprehensive description for triggering the Secondary Function in the field description so to ensure that the Secondary Function is always initiated.

The field description for the news data model describes the news that will be presented to the user. It should be mentioned that it should be always provided by triggering of Secondary Function. In our case, a good field description would be: Describes the news which will be generated from the “Generate News” secondary function. Always go for “Generate News” secondary function only never ask this field from user. All the news articles generated are presented as strings.

Secondary Function Field Description

This Function helps task to generate news and send it to task or another Secondary Function. Below, there is an example where the users ask for news category they want to read and provide news to Primary Function. For a better understanding, you can find the overall guide for this example here.

The field description for the category data model describes the category for which the user wants to read the news. It should be mentioned that it should be always provided by user. In our case, a good field description would be: Describes the category provided by user about which he wants to get news for. This should always be provided by user in all cases. This primary function responds to “Generate News” secondary function. This should be from options business, entertainment, general, health, science, sports, technology.

ℹ️

Remember to always include the secondary function trigger in the field description. This is very important to ensure that the secondary function is being called. When selecting one of multiple secondary functions, you need to use different names for each one of the functions. This way, we avoid confusion for the LLM.

Example 2: Hugging Face Text Classification Models

This Function helps user to choose a text classification model and make a query to that model. This task hugging face system goes for Secondary Functions to get make request to hugging face API which in turn trigger model list Secondary Functions to get list of model related to a search keyword. User can make query to their selected model.

Primary Function Field Description

The field description for the response describes the response to be provided to the user. The Primary Function always triggers secondary function Hugging Face Request. The ideal field description in this case will be like Describes the response to the user query. Always go for Hugging face request secondary function to get this field. Never ask this from user.

Secondary Function Field Description

Hugging Face Request

Hugging face request: This function has two fields model_id (to which query is to be made) and query (what request you want to make to the model). The model_id field again triggers Model List secondary function which asks user for search keyword to get most downloaded models related to that keyword.

Ideal field description for this example will be like:

model_id: Always go for model list secondary function. Never ask this field to user. query: Describes the query user wants to ask the model. Always ask this to user after model_id is given by model list secondary function.

ℹ️

Remember to always provide a comprehensive description in query field that first we should fetch model_id using secondary function before asking query to user.

Model List

Model List: This secondary function has field Search which searches for top 10 downloaded models related to that keyword from hugging face API and lets user selects from provided model id’s.

Ideal field description for this example will be like:

Search: This is the type of model user wants to make query to. Always ask this to user. This always gives list of options to the user. Make user select one from these options.

Example 3: Local Business Finder

This Function helps user to find local businesses in any locality and specified category. This Agent Function returns list of 10 businesses to user and gives information about selected business by the user.

Primary Function Field Description

There are 3 fields in this primary function category (Type of business which user wants to search), city (City in which user wants to look around for business) and name (Name of the business which user wants to search).

Ideal field descriptions for this example will be like:

category: This describes business category provided for which user wants to search business. Ask this from user. city: always go for city finder secondary function to get user’s city. Ask user if they want to use this city in yes/no question. [‘yes’: ‘use this city’, ‘no’: ‘ask for city they want to search for’]. name: Always go for secondary function business finder service’s response. Never ask this from user.

Secondary Function Field Description

  1. City Finder: This secondary function takes user location from DeltaV and looks for their current location. Below given is the ideal description for location.

    location: This describes the coordinates of the city given in str(lat,long) format.

  2. Business Finder: This secondary function takes category and city from the primary function and looks around for 10 business name in that area. Asks user to select one and then sends back to task as name field.

    category: This is the category provided by the user for which they want to get businesses in primary function business details service, Use this category for task as well.

    city: This is the city responded by city finder or one given by user.

Agent Function registration examples

For additional information and guidelines on how to register an Agent Function on the Agentverse and examples of descriptions, head over to our dedicated resources:

Rich Text and Hyperlinks in responses in DeltaV

Introduction

This guide will help you understand how to utilize rich text and hyperlinks within responses in your DeltaV application based on a practical example. This is particularly useful for developers who need to generate interactive and informative content.

ℹ️

Check out the AI Engine package to download it and start integrating your Agents with this tool!

Current version of the AI Engine package is

Remember to check out the following guide to make your agents AI Engine and DeltaV compatible!

Understanding Rich Text and Hyperlinks

Rich Text and Hyperlinks

Rich Text is a text format that supports a variety of text styles and formatting options beyond plain text.

These options include:

  • Bold, Italic, and Underline styles
  • Headings and Subheadings
  • Lists (bullet points and numbered)
  • Hyperlinks

Rich text makes your content more visually appealing and easier to read, improving the user experience.

Hyperlinks are clickable texts or elements that redirect users to another resource, such as a web page or document. Hyperlinks are often used to connect related content or provide additional information.

In DeltaV, you can include hyperlinks in your responses, allowing users to easily navigate to relevant resources.

Why Rich Text and Hyperlinks?

  1. Enhanced communication: Rich text allows for better formatting and structure, making your messages clearer and more effective.
  2. Interactive content: Hyperlinks enable users to access additional information or related content directly from your responses.
  3. Improved user experience: These features make content more engaging and accessible, leading to higher user satisfaction.

Implementing Rich Text and Hyperlinks in DeltaV responses

In DeltaV, you can integrate rich text and hyperlinks to enhance the responses generated by your agents or automation workflows. Let’s look at how you can implement these features. Let’s consider a scenario where you want your DeltaV agent to respond with a list of news articles related to a company, with each article presented as a clickable hyperlink.

The script below shows how to integrate external data (e.g., stock symbols or news articles) into a DeltaV agent’s response, and how to format that response using rich text, specifically by creating hyperlinks. This approach enhances the communication capabilities of the DeltaV agent, making its responses more dynamic, interactive, and useful for the end-user.

Here’s the example of how to do this in:

example.py
import requests from ai_engine import UAgentResponse, UAgentResponseType # Define a news content structure using the Model class to represent a news content class NewsRequest(Model): company_name: str # Create a protocol for the Hugging Face finbert agent news_protocol = Protocol("Institute News") async def fetch_symbol(company_name): url = f"https://www.alphavantage.co/query?function=SYMBOL_SEARCH&keywords={company_name}&apikey={ALPHA_VANTAGE_API_KEY}" response = requests.get(url) if response.status_code == 200: data = response.json() # Typically, the best match will be the first item in the bestMatches list if data.get('bestMatches') and len(data['bestMatches']) > 0: # Return the symbol of the best match symbol = data['bestMatches'][0]['1. symbol'] return symbol return 'No Symbol found' async def analyze_news(company_name): """Analyze news sentiment for the company using GNews.""" url = f"https://gnews.io/api/v4/search?q={company_name}&token={GNEWS_API_KEY}&lang=en" response = requests.get(url) articles = response.json().get('articles', []) # Extract URLs and convert them to hyperlinks with titles button_list = [] for article in articles: title = article.get("title", "No Title") url = article.get("url", "No Url") if url != "No Url": # Create a clickable button with the title as text button_list.append(f'<a href="{url}">{title}</a>') # Combine buttons into a single string with line breaks buttons_combined = '\n'.join(button_list) return buttons_combined @news_protocol.on_message(model=NewsRequest, replies=UAgentResponse) async def on_institute_news_request(ctx: Context, sender: str, msg: NewsRequest): ctx.logger.info(msg.company_name) symbol = await fetch_symbol(msg.company_name) ctx.logger.info(symbol) news_content = await analyze_news(symbol) ctx.logger.info(news_content) await ctx.send(sender, UAgentResponse(message=news_content, type=UAgentResponseType.FINAL)) agent.include(news_protocol)
⚠️

Remember that you need to get a ALPHA_VANTAGE_API_KEY Key from GNews to correctly run this example.

The script integrates two key concepts: fetching data from APIs and formatting the response with rich text (specifically, HTML hyperlinks). We first import the needed libraries and then define the NewsRequest Data Model. This takes in a company_name as input, which will be used to fetch relevant data from GNews. We proceed and define a communication protocol within the DeltaV agent named Institute News. Protocols are used to handle specific types of messages or requests, in this case, news-related requests about a company. We go on and define 3 different functions:

  1. fetch_symbol(): Fetches the stock symbol of a company by querying the Alpha Vantage API with the company name. The function constructs the API request URL, sends the request, and parses the JSON response to extract the first match from the bestMatches list. If no match is found, it returns No Symbol found.
  2. analyze_news(): This function fetches news articles related to the company using the GNews API. The function processes the list of articles, extracts their URLs, and formats each URL as a clickable hyperlink using the HTML <a> tag. The hyperlinks are then combined into a single string, with each link on a new line, and returned.
  3. on_news_request(): This is the main function that handles incoming requests based on the NewsRequest model. The flow is:
    • Logs the company name received in the request.
    • Calls fetch_symbol() to retrieve the company’s stock symbol.
    • Calls analyze_news() to fetch and format the news articles into clickable links.
    • Sends the final response containing the news content back to the sender, using the UAgentResponse class with a FINAL message type.
ℹ️

Use HTML tags to format text as rich text. For example, use <b> for bold, <i> for italics, and <u> for underline. Embed hyperlinks using the <a> tag.

Example:

<a href="https://example.com">Click here to visit Example.com</a>

When users click on Click here to visit Example, they will be taken to https://example.com.

Expected output

This guide details how to enhance DeltaV responses using rich text and hyperlinks. Rich text allows for enhanced formatting of responses, while hyperlinks make content interactive by providing clickable links to additional resources. The example code demonstrates how to fetch data from APIs, format it with HTML links, and handle requests within a DeltaV agent. Proper use of these features improves readability, engagement, and the overall effectiveness of your responses.

Last updated on