Game-Lite Custom Functions: Retrieving Articles Using Dev.to
By Armielyn Obinguar, Celeste Ang
Last updated
By Armielyn Obinguar, Celeste Ang
Last updated
In this article, we'll explore how to create custom functions within the G.A.M.E-lite framework, demonstrating its versatility. Our agent, BugBean, will focus on retrieving articles from Dev.to to showcase this functionality.
G.A.M.E (Generative Autonomous Multimodal Entities) is a modular framework that enables agents to autonomously plan actions and make decisions based on provided information. Given an agent's goal, personality, relevant information, and available actions/functions, G.A.M.E processes these inputs to determine and execute the most appropriate action.
At Virtuals Protocol, we’ve made our lite-version (G.A.M.E Lite) publicly available, allowing you to test how your agent will behave using built-in custom functions or API-based custom functions. Whether you're working with an existing agent or planning to create one, G.A.M.E Lite provides an ideal space to test your APIs and features early on.
To begin, let's configure BugBean to retrieve articles from Dev.to. We'll utilize Dev.to's API, specifically the articles endpoint, to fetch the latest content.
It's highly recommended to experiment with defined functions that your agent can use to search for information, gather knowledge on specific prompts, or address particular use cases.
Learning how to configure and add new custom functions for your Agent requires some understanding of APIs. Often, it can be challenging to grasp these concepts without having a test environment to experiment with. But don’t worry — this article will help you get started and familiarize yourself with the fundamentals.
API stands for Application Programming Interface. In the context of APIs, the word Application refers to any software or system with a specific function, while Interface can be thought of as a contract that defines how two applications communicate. This contract outlines how the two interact through requests and responses.
To make this clearer, imagine you’re at a restaurant:
The Restaurant represents the system or service (like a website or app) that offers specific information or functionality.
The Menu is the API. It’s a list of all the available actions (or data) that the system can provide. Just like a menu shows you the options for what you can order, an API lists the functions you can request from the system.
You (the Customer) are the user or developer interacting with the API.
The Waiter is the API request. When you ask the waiter for a dish, you’re making a request to the API for a particular service or data.
The Kitchen is the back-end server or system that processes your request. It takes the information from the API (your order) and prepares the response for you.
The Dish you receive is the API response — the result or data you asked for, delivered back from the system.
In GAME-lite, you'll find a set of default functions designed to perform general tasks.
However, each Agent often has unique capabilities and features tailored to specific needs. Adding custom functions is essential to extend your Agent's abilities, enabling it to handle specialized tasks that default functions may not cover.
It’s quite simple indeed! In this article, we will use the analogy of a "restaurant" — in this case, the DEV Community — and demonstrate how you can retrieve the "menu" (API) to interact with the system. As a "customer," you will be able to use the API to fetch data for your Agent and test it within the Game-lite environment.
Reminder: It’s best to identify what sort of services or platform you might be using for your Agent.
In this article, we will explore how our Agent, BugBean, can retrieve Dev-related articles and scan those articles to provide real-time updates on the latest technology stacks or innovations.
Note: The character card defines the personality of your agent. It includes details such as character background information, overall personality, tweeting style, conversation style, and other relevant information. The character card information is used to shape the behavior of your Agent in both high-level and low-level prompts.
Under Agent Definition Prompts, it is also important to also include the Agent Goal and Worldview. For context, these are essential information to help the Agent gain a more defined understanding of its high-level and low-level planning and reasoning.
Here are some sample you can use if you are following along with this demo:
Agent Goal
World Information
When you begin setting up custom functions for your Agent using dev.to, it's helpful to explore its API documentation to get a better grasp of how it works.
Within the API documentation, pay attention to the various HTTP methods such as GET, POST, PUT, DELETE, and PATCH. There are two versions of the API available: Version 0 and Version 1. All V0 endpoints are supported in V1. For now, it’s recommended to call V0 endpoints with the accept
and api-key
headers for compatibility.
This method allows you to fetch data from the platform, such as articles related to programming trends, best practices, and new technologies.
In the documentation, you will find detailed information about the content format, required parameters, and the specifics of each endpoint.
Think of the content type as your headers, and the parameters as the arguments that need to be configured for your custom functions. These elements are crucial for ensuring that your requests are correctly formatted and that the API responds with the right data.
HEADERS
In this case, the endpoint you will use is https://dev.to/api/articles
. The term "Articles" refers to all the posts created by users on DEV, which typically appear in the feed. These can include blog posts, discussion questions, help threads, and more, but they are all categorized as "articles" in the code.
By default, the endpoint will return featured and published articles, ordered by descending popularity.
It also supports pagination. Each page will contain 30
articles by default, and you can adjust the number of articles per page if needed.
QUERY PARAMETERS “Arguments”
For our case, we can focus on using the “tag” and “page” parameters. The tag will help filter articles based on specific topics, such as programming languages or any other subject relevant to your Agent's goal. By setting the tag, you can narrow down the search to articles that align with your Agent's focus.
Additionally, the page parameter will allow you to paginate through articles, retrieving multiple pages of results if needed. This is useful when you want to pull more than the default 30
articles per request.
You can also explore other parameters in the API documentation to further refine your query and tailor the results to your Agent's needs.
In the add new custom function on Game-Lite you can set any name for your functions. For this example, we name the function as “query_devto_articles” to retrieve the articles. Do also note a specific function description is important to ensure that the agent understands when to call this function.
Function Name: query_devto_articles
Function Description: Fetch articles from Dev.to related to a specific tag in programming (e.g., Python, JavaScript). This function helps retrieve coding articles for learning or exploring new technologies.
In the Arguments section, we set the parameters using both “tag” and “page”.
It’s important to verify the argument types before setting them. For example, since we are dealing with tags, the argument type will certainly be a string. Make sure to check the API documentation for the exact argument type and any additional requirements to ensure proper formatting.
This way, your Agent can accurately query the relevant articles based on the tag you specify, and paginate through the results by adjusting the page parameter.
Now that we’ve set the arguments, we can proceed with the configuration. In this step, we will define the appropriate HTTP methods such as GET, POST, PUT, DELETE, and PATCH.
Since the Content-Type is set to application/json, we will format the request accordingly. This ensures that the request headers align with the expected content type, allowing the system to process and return the response in the correct format.
For example, when retrieving data from the API, we will use the GET method along with the required headers and arguments to query for the articles.
Do remember that payloads are important as well because they define the information we will retrieve. In this case, the payload will include the parameters such as the tag and page, which determine the specific articles or data the Agent will query.
The payload will also ensure that the request is properly formatted with the necessary fields, and it is crucial to include this in your configuration to ensure you are fetching the correct data.
PAYLOAD
As soon as you're able to configure the above steps, don't forget to include both success and error feedback. This is crucial for handling the outcomes of your API requests.
The way that the result/information of the function is passed back to the agent is via feedback. Success feedback ensures that the Agent receives a confirmation when the request is processed correctly, while error feedback helps diagnose issues by providing details about what went wrong.
Proper feedback handling will make your Agent more reliable and improve the user experience when interacting with the system.
We’re all set for the first custom function! Just remember to click on "Simulate Output" to see how your function performs and ensure everything is working as expected.
This will allow you to review the results and make any necessary adjustments to fine-tune the function.
Once you've configured the custom function, it's important to carefully analyze the output when you simulate it. This will help you confirm if the function is returning the correct data and behaving as expected.
Pay attention to any discrepancies or errors, and adjust your configuration to ensure that the function is working.
Since we can see now the custom-function-request and custom-function-response. We can then verify if the endpoint we’ve used is able to proceed or not.
The custom-function-request is then showing the method used, the url for the endpoint and the headers.
As a result, the custom-function-response will display the output. This indicates that the custom function is now working as intended.
The next step is to observe how the Agent behaves when interacting with this function in a real scenario. This will give you valuable insight into how well the function integrates with the Agent's decision-making and action processes.
Feedback Request refers to the feedback message sent to GAME after the function has been executed. You can check the current_action to identify the feedback message input. An example is shown below.
Feedback Response is the response from GAME upon receiving the feedback, which helps you evaluate how the Agent processes and reacts to the function's output.
In this article, we've demonstrated how Agent BugBean can retrieve articles from Dev.to using custom functions within the G.A.M.E-lite framework. By specifying parameters such as "Tag" and "Page", the agent can effectively search for and process relevant articles.
This capability enhances the agent's functionality, enabling it to autonomously gather and utilize information from Dev.to, thereby streamlining content retrieval and processing tasks.
For more information on creating custom functions within the G.A.M.E-lite environment, you can refer to the documentation.
To learn more about using the Dev.to API, you can refer to the DEV API documentation.