Set Up Your App for Agent Creation
Introduction
This guide describes the shared setup steps for the example IT helpdesk agent. Complete these steps before choosing one of three implementation approaches. For more information about the agent use case and implementation options, see Creating Your First Agent.
This guide walks you through the following:
- Setting up your application with the required modules and configuration to use Mendix Agents Kit
- Generating ticket data and ingesting historical information into a knowledge base
- Creating a domain model and user interface for agent interaction
- Building function microflows that the agent can call to retrieve data
After you complete these steps, continue to one of the implementation approach guides:
- Create an Agent with Agent Editor
- Create an Agent with Agent Commons
- Create an Agent Programmatically
Prerequisites
Before you build an agent in your app, make sure your scenario meets the following requirements:
- An existing app – Use a GenAI starter app such as the Blank GenAI Starter App, or add to an app that you have already built
- Studio Pro 10.24 or above (or Studio Pro 11.9.1 or above if you plan to use Agent Editor)
- Intermediate understanding of Mendix – Knowledge of simple page building, microflow modeling, domain model creation, and import/export mappings
- Basic understanding of GenAI concepts – Review Enrich Your Mendix App with GenAI Capabilities for foundational knowledge and familiarize yourself with the concepts of GenAI and agents
- Basic understanding of function calling and prompt engineering – Learn about Function Calling and Prompt Engineering to use them within the Mendix ecosystem
- Optional – If you are not yet familiar with implementing specific GenAI concepts with Agents Kit, follow these GenAI documents: Grounding Your LLM in Data, Prompt Engineering at Runtime, and Integrate Function Calling into Your Mendix App
- Optional – Basic understanding of the Model Context Protocol and the related Mendix modules: MCP Server module and MCP Client module
Setting Up Your Application
If you are using a GenAI starter app such as the Blank GenAI Starter App, you can skip ahead to Creating the Agent's Functional Prerequisites because the following setup steps are completed by default. Otherwise, follow these steps to add the required modules and configuration to your app:
-
Set your app's security level to Production.
-
Install the GenAI Commons, Agent Commons, Mendix Cloud GenAI Connector, and ConversationalUI modules from Marketplace. You also need to install their dependencies, including MCP Client, Community Commons, and Encryption.
-
Open your app's Security settings and configure the appropriate user roles:
- For the user role responsible for defining agents (typically the Administrator role), assign the AgentAdmin module role from the Agent Commons module.
- For user roles that chat with the agent, assign the User module role from the Conversational UI module.
- Save the security settings.
-
Go to your app's Navigation and add a new Agents item.
- Select an icon, such as
notes-paper-text, from the Atlas icon set. - Set the On click action to Show a page.
- Search for and select the Agent_Overview page, located under AgentCommons > USE_ME > Agent Builder.
- Select an icon, such as
After starting the app, the admin user can configure Mendix GenAI resources and navigate to the Agent Overview page.
Creating the Agent's Functional Prerequisites
The agent interacts with data from a knowledge base and the Mendix app. To make this work from a user interface, complete the following functional prerequisites:
- Populate a knowledge base
- Create a simple user interface that allows the user to trigger the agent from a button
- Define two function microflows for the agent to use while generating a response
Each of these steps is described in the following sections.
To define the agent and generate responses, the steps differ based on your chosen approach and are covered in separate documents.
Ingesting Data Into Knowledge Base
Ingest Mendix ticket data into the knowledge base. For a detailed guide, see Grounding Your LLM in Data. The following steps explain the process at a higher level by modifying logic imported from the GenAI Showcase App. You can find the sample data used in this document in the GenAI Showcase App or use your own data.
-
Go to the domain model of the module where you want to implement this example. (The following instructions use
MyFirstModuleas the module name in examples—replace this with your actual module name.) In your domain model, create aTicketentity with the following attributes:Identifieras StringSubjectas StringDescriptionas String, length 2000ReproductionStepsas String, length 2000Solutionas String, length 2000Statusas Enumeration; create a new EnumerationENUM_Ticket_Statuswith Open, In Progress, and Closed as values
-
From the GenAI Showcase App, copy the following components from the
ExampleMicroflowsmodule. Then, in your app, paste them into the module you are using.ACT_TicketList_LoadAllIntoKnowledgeBaseTickets_CreateDatasetIM_TicketEM_TicketJSON_Ticket
-
Open IM_Ticket, click Select elements, and search for JSON_Ticket in the JSON structure schema source. Select Object and all fields for which you created attributes in the
Ticketentity (do not select Category, because it does not have a corresponding attribute inTicket). Clear the Array checkbox and click OK. -
Open JsonObject, select your
Ticketentity, and then select Map attributes by name to map all fields to your attributes. The completed import mapping looks like this:
-
Open EM_Ticket, click Select elements, and search for the JSON_Ticket in the JSON structure schema source. Select all fields for which you created attributes in the
Ticketentity. Click OK. Open the JsonObject to select yourTicketentity and map all fields to your attributes. -
In
Tickets_CreateDataset, open theRetrieve Ticket from databaseaction and set the entity to your module'sTicketentity. Open theImport from JSONaction and select IM_Ticket. -
In
ACT_TicketList_LoadAllIntoKnowledgeBase:- Edit the first Retrieve object(s) activity to retrieve objects from your module's
Ticketentity. - In the loop, delete the second action, which adds metadata to the
MetadataCollection. - In the last action of the loop,
ChunkCollection_Add KnowledgeBaseChunk, set the Human readable ID field toempty.
- Edit the first Retrieve object(s) activity to retrieve objects from your module's
-
Create a microflow
ACT_CreateDemoData_IngestIntoKnowledgeBase. Add two actions to the new microflow: call theTickets_CreateDatasetmicroflow, then call theACT_TicketList_LoadAllIntoKnowledgeBasemicroflow.
-
Add the admin role under Allowed Roles in the
ACT_CreateDemoData_LoadAllIntoKnowledgeBasemicroflow properties. -
Add the new microflow to your navigation or homepage.
When the microflow is called, the demo data is created and ingested into the knowledge base for later use. This needs to be called only once at the beginning. Make sure to first add a knowledge base resource. For more details, see Configuration.
Setting Up the Domain Model and Creating a User Interface
Create a user interface to test and use the agent. It will look like this:
-
In your domain model, add a new entity
TicketHelperand toggle Persistable to off. Add the following attributes:UserInputas String, length unlimitedModelResponseas String, length unlimited
-
Grant your module role the following entity access:
- Read access for both attributes
- Write access for the UserInput attribute
Also, grant the user entity rights to
Create objects. -
Create a new blank and responsive page TicketHelper_Agent.
-
On the page, add a data view. Change the Form orientation to
Verticaland set Show footer toNo. For Data source, select theTicketHelperentity as context object. Click OK and automatically fill the content. -
Remove the Save and Cancel buttons. Add a new button with the caption Ask the agent below the User input text field.
-
Convert the Model response input field to a Text Area. Then set its Grow automatically option to
Yes. -
In the page properties, add your user and admin role to the Visible for selection.
-
Add a button to your navigation or homepage with the caption Show agent. For the On click event, select
Create object, select theTicketHelperentity, and set the On click page to TicketHelper_Agent.
You have now successfully added a page that allows users to ask an agent questions. You can verify this in the running app by opening the page and entering text into the User input field. However, the button does not do anything yet. You will add logic to the microflow behind the button in your chosen implementation approach.
Creating the Function Microflows
Add two microflows that the agent can use to access live app data:
- Get Number of Tickets in Status counts the tickets in the database that have a specific status
- Get Ticket by Identifier retrieves the details of a specific ticket when the identifier is known
Get Number of Tickets in Status
-
Create a new microflow named
Ticket_GetNumberOfTicketsInStatus. Add a String input parameter calledTicketStatus. The model can now pass a status string to the microflow. -
Convert the input into an enumeration. Add a
Call Microflowactivity and create a new microflow namedTicket_ParseStatus. Use the same input parameter (String inputTicketStatus). -
Inside the
Ticket_ParseStatussub-microflow, add a decision for each enumeration value and return the enumeration value in the End event. For example, the Closed value can be checked like this:toLowerCase(trim($TicketStatus)) = toLowerCase(getCaption(MyFirstModule.ENUM_Ticket_Status.Closed)) or toLowerCase(trim($TicketStatus)) = toLowerCase(getKey(MyFirstModule.ENUM_Ticket_Status.Closed)) -
Return
emptyif none of the decisions return true. This might be important if the model passes an invalid status value. Make sure that the calling microflow passes the string parameter and uses the return enumeration namedENUM_Ticket_Status. -
In Ticket_GetNumberOfTicketsInStatus, add a
Retrieveaction to retrieve the tickets in the given status:- Source:
From database - Entity:
MyFirstModule.Ticket(search for Ticket) - XPath constraint:
[Status = $ENUM_Ticket_Status] - Range:
All - Object name:
TicketList(default)
- Source:
-
After the retrieve, add the
Aggregate listaction to count the TicketList. -
In the End event, return
toString($Count)as String.
Your completed microflow looks like this:
You have now successfully created your first function microflow to link to the agent in your chosen implementation approach. If users ask how many tickets are in the Open status, the model can call the exposed function microflow and base the final answer on your Mendix database.
Get Ticket by Identifier
-
Create a new microflow named
Ticket_GetTicketByID. -
In the new microflow, Add a String input parameter called
Identifier. -
Add a
Retrieveaction to retrieve the ticket of the given identifier:- Source:
From database - Entity:
MyFirstModule.Ticket(search for Ticket) - XPath constraint:
[Identifier = $Identifier] - Range:
All - Object name:
TicketList(default)
- Source:
-
Add an
Export with mappingaction:- Mapping:
EM_Ticket - Parameter:
TicketList(retrieved in previous action) - Store in:
String VariablecalledJSON_Ticket
- Mapping:
-
Right-click the action and click
Set $JSON_Ticket as return value.
Your completed microflow looks like this:
As a result of this function, users can ask for information for a specific ticket by providing a ticket identifier. For example, they can ask What is ticket 42 about?.
Accessing Function Microflows via MCP (Optional)
Instead of configuring functions directly within your application, you can access them via Model Context Protocol (MCP). You can also use both approaches together. This approach requires an MCP server to be running and exposing the desired functions.
To get started:
- Review the MCP Server example in the GenAI showcase app to learn how to expose functions.
- Check the MCP Client showcase for configuration details and implementation guidance.
This method provides greater flexibility in managing and sharing functions across different applications and environments.
Choose an Implementation Approach
You have completed the foundational setup. Continue with your chosen implementation approach:
- Create an Agent with Agent Editor
- Create an Agent with Agent Commons
- Create an Agent Programmatically
For help choosing an approach, see Creating Your First Agent.