Integrates generative artificial intelligence capabilities into the applications generated with GeneXus Next. With this object, you can create intelligent agents that interact with users, generate content, and execute complex tasks using natural language processing.
- Natural language interaction with users.
- Dynamic content generation.
- Integration with business logic and external services.
- Contextual information processing.
The Agent object can be applied in various scenarios, including:
- Answering product questions, processing returns, and providing shipping information on e-commerce platforms.
- Generating compelling product descriptions based on technical features, aligned with brand style and market trends.
- Analyzing mobile app user reviews, identifying common issues, classifying them by severity, and suggesting improvements.
- Suggesting and explaining best practices for writing and debugging code in GeneXus Next, thus improving efficiency and readability.
- Generating narrative reports from sales data, identifying trends, and providing comparative and actionable insights.
Agent <AgentName>
{
<Agent Instructions>
#Rules
parm(<Parameters>);
[context(<DataProviders>);]
[use(<Tools>);]
#End
#Variables
<Variable Definitions>
#End
}
Where:
AgentName
This is the unique identifier for the Agent object. It should be a descriptive name following GeneXus naming conventions.
Agent Instructions
This description guides the overall behavior of the Agent.
Rules
This section contains the operational rules for the Agent, including parameters, context, and tools.
parm (Parameters)
Defines the input and output parameters of the Agent.
Syntax: parm(in:&InputParameter, out:&OutputParameter);
context (DataProviders)
Specifies the data providers that the Agent can use to obtain additional information.
Syntax: context(DataProvider(&Parameter));
use (Tools)
Indicates the APIs or external tools that the Agent can use.
Syntax: use(APIName);
Variables
This section defines the variables used by the Agent, specifying their properties.
Syntax:
VariableName
[
DataType = 'DataType',
AverageLength = 'AverageLength',
Collection = 'True/False',
ControlType = 'ControlType'
]
Suppose you need to expand a short text into a detailed description. To do so, you can use an Agent object, defined as follows:
Agent DescriptionsAgent
{
Expand the following short text into a detailed description: "{{&ShortText}}"
#Rules
parm(in:&ShortText, out: &ExpandedText);
#End
#Variables
ShortText
[
DataType = 'VarChar(40)'
]
ExpandedText
[
DataType = 'VarChar(512)'
]
#End
}
The DescriptionsAgent takes a short text (&ShortText) as input and produces an expanded version (&ExpandedText) as output.
The Rules section defines these input and output parameters, while the Variables section specifies the properties of these variables.
ShortText is defined as a 40-character VarChar, which limits the length of the input text, while ExpandedText is a 512-character VarChar, providing enough space for a detailed description.
Suppose you need to identify the category of a product based on its description. To do so, you can define an Agent object as follows:
Agent ProductCategoryAgent
{
Determine the product category with this description: {{&ProductDescription}}.
#Rules
parm(in:&ProductDescription, out:&CategoryId);
context(CategoryList());
#End
#Variables
ProductDescription
[
DataType = 'VarChar(40)',
AverageLength = '0',
Collection = 'False',
ControlType = 'Edit'
]
CategoryId
#End
}
The ProductCategoryAgent receives a product description (&ProductDescription) as input and returns a category identifier (&CategoryId).
In the Rules section, in addition to defining these parameters, a context (CategoryList()) is included that provides the Agent with a list of available categories for sorting.
The Variables section defines ProductDescription as a 40-character VarChar with additional properties such as AverageLength, Collection, and ControlType, suggesting that this variable could be used in a user interface.
CategoryId is declared without specific properties, implying that the context of the application can determine its type and use.
Suppose you want to get product recommendations based on a customer's purchase history and preferences. To achieve this, define an Agent object as shown below:
Agent ProductRecommenderAgent
{
Recommend products based on the customer's purchase history and preferences: "{{&CustomerID}}"
#Rules
parm(in:&CustomerID, out:&RecommendedProducts);
context(CustomerPurchaseHistory(&CustomerID), ProductCatalog());
use(RecommendationEngine);
#End
#Variables
CustomerID
[
DataType = 'Numeric(8,0)',
ControlType = 'Edit'
]
RecommendedProducts
[
DataType = 'VarChar(100)',
Collection = 'True'
]
#End
}
The ProductRecommenderAgent takes a customer ID (&CustomerID) as input and produces a list of recommended products (&RecommendedProducts) as output.
The Rules section defines the input and output parameters, as well as the context and tools used by the Agent. The context includes the customer's purchase history and the product catalog, which provide essential information for making recommendations. The use of RecommendationEngine suggests that an external tool is used to generate the recommendations.
In the Variables section, CustomerID is defined as Numeric(8,0) with an Edit control type, indicating it's an editable numeric field. RecommendedProducts is defined as VarChar(100) with the Collection property set to True, implying it can hold multiple product recommendations.
To use an Agent object, you can call it like any other object. Here's how to do it:
&Result = AgentObjectName(&InputParameter, &OutputMessages)
Where:
AgentObjectName is the name of the Agent object you want to call.
&InputParameter are the input parameters required by the Agent object.
&OutputMessages is a variable that will contain output messages or errors.
If &Result.IsSuccess()
// Process the successful result
&ProcessedData = &Result.Value
Else
// Handle errors
&ErrorMessage = &OutputMessages.ToString()
EndIf
&CustomerID = 12345
&RecommendationResult = ProductRecommenderAgent(&CustomerID, &OutputMessages)
If &RecommendationResult.IsSuccess()
For Each &Product
// Process each recommended product
&ProductName = &Product.Name
&ProductPrice = &Product.Price
// ... do something with the product information
EndFor
Else
Msg(&OutputMessages.ToString())
EndIf
You can add this code in Procedures, Transactions, Web Panels, Business Components, and Data Providers. This means that Agent objects can be seamlessly integrated with other objects like these.
This integration allows you to enhance various aspects of your application with AI capabilities, enabling you to add intelligent processing, decision-making, and dynamic content generation throughout your application.
By leveraging Agent objects in different contexts, you can create more sophisticated and responsive applications that take full advantage of natural language processing and generative AI in your business logic.
- The Use rule is currently not supported.