Example: Customizing User Interface Using Custom Lightning Types with Top-Level Editor and Top-Level Renderer Overrides
This example explains how to override the default user interface to create a customized appearance of responses on the custom agent’s action input and output with custom Lightning types.
In this example, you specify an editor override and a renderer override for the custom Lightning type that you created.
Example Apex Class for Retrieving Flight Information
Use these Apex classes together to create a custom agent action that finds flights. The main FlightAgent class contains the invocable method, and the other classes define the complex data structures for the request and response.
When you create your custom agent action, select the method Find Flights.
FlightAgent Class
This class is the main class that contains the logic for the Find Flights agent action. It also defines the FlightRequest and FlightResponse inner classes to handle the action’s input and output.
1global class FlightAgent{23 @InvocableMethod(label='Find Flights' description='Finds available flights')4 global static List<FlightResponse>findFlights(List<FlightRequest>req){5 List<FlightResponse>flightResponses = new List<FlightResponse>();67 // For example, we hardcode the data and don’t focus on how we retrieve it.8 // However, consider that we receive available flight data from a service9 // and then iterate through the data to generate the final response.1011 List<Flight>flights = new List<Flight>();12 Flight f1 = new Flight('IX 2814', 1, false, 1000l, 20.20d, 70);13 Flight f2 = new Flight('6E 488', 2, false, 2000l, 15.15d, 120);14 Flight f3 = new Flight('6E 523', 1, false, 3000l, 13.14d, 75);15 Flight f4 = new Flight('6E 6166', 2, false, 4000l, 14.14d, 130);16 flights.add(f1); flights.add(f2); flights.add(f3); flights.add(f4);17 AvailableFlight availableFlights = new AvailableFlight();18 availableFlights.flights = flights;1920 FlightResponse fr = new FlightResponse();21 fr.aFlight = availableFlights;22 flightResponses.add(fr);2324 return flightResponses;25}2627 @JsonAccess(serializable='always' deserializable='always')28 global class FlightRequest{2930 @InvocableVariable31 global String originCity;3233 @InvocableVariable34 global String destinationCity;3536 @InvocableVariable37 global Date dateOfTravel;3839 @InvocableVariable40 global FlightRequestFilter filters;41}4243 @JsonAccess(serializable='always' deserializable='always')44 global class FlightResponse{4546 @InvocableVariable47 global AvailableFlight aFlight;48}49}
AvailableFlight Class
This class defines a list that holds multiple Flight objects.
1@JsonAccess(serializable='always' deserializable='always')2global class AvailableFlight{34 @AuraEnabled5 global List<Flight>flights;6}
Flight Class
This class defines the data structure for flight details.
1@JsonAccess(serializable='always' deserializable='always')2global class Flight{34 @AuraEnabled5 global String flightId;67 @AuraEnabled8 global Integer numLayovers;910 @AuraEnabled11 global Boolean isPetAllowed;1213 @AuraEnabled14 global Long price;1516 @AuraEnabled17 global Double discountPercentage;1819 @AuraEnabled20 global Integer durationInMin;2122 global Flight(String flightId, Integer numLayovers, Boolean isPetAllowed,23 Long price, Double discountPercentage, Integer durationInMin){24 this.flightId = flightId;25 this.numLayovers = numLayovers;26 this.isPetAllowed = isPetAllowed;27 this.price = price;28 this.discountPercentage = discountPercentage;29 this.durationInMin = durationInMin;30}31}
FlightRequestFilter
This class defines the data structure for the optional filters a user can apply when searching for flights.
1@JsonAccess(serializable='always' deserializable='always')2global class FlightRequestFilter{34 @AuraEnabled5 global Long price;67 @AuraEnabled8 global Double discountPercentage;9}
The Apex class FlightAgent accepts the flight search criteria, including the origin city, destination city, and date of travel, and then returns a list of available flights.
For this example, flight availability data is already included in the FlightAgent Apex class. However, in a real-time scenario, flight information is fetched from an external service, and the Apex class processes that data to generate the final response.
Create a custom Lightning type named flightResponse to enhance the visibility of the information in the output UI.
Override Default UI for Output With Custom Lightning Types
Override the agent’s action UI for output to enhance the user experience by using Custom Lightning Types (CLTs). With CLTs, you can add your own Lightning Web Components (LWC) to present data in a more structured and intuitive format.
Configure the renderer.json file to override the default UI of a custom Lightning type in the agent action.
Here’s an example showing a lightningTypes folder for a custom Lightning type named flightResponse.
This example uses lightningDesktopGenAi to configure the custom Lightning type. To configure the type for the enhancedWebChat channel, create the renderer.json file in the corresponding channel folder.
Note
The custom Lightning type flightResponse includes a schema.json file and a renderer.json file. The renderer.json file controls how the data is displayed to the user in the agent action output.
This sample code shows the contents of the schema.json file.
1{2 "title": "My Flight Response",3 "description": "My Flight Response",4 "lightning:type": "@apexClassType/c__AvailableFlight"5}
This sample code shows the contents of the renderer.json file.
Build Output Components with Lightning Web Components
This section explains how the components are created and deployed for agent action output.
This image shows the Lightning Web Component (LWC) folder structure.
The LWC component includes HTML markup designed to represent the data that the agent returns for @apexClassType/c__AvailableFlight. This HTML markup ensures that the data is displayed in an intuitive and customized format.
This sample code shows the contents of the flightDetails.js-meta.xml file.
When you create an LWC component to override the UI for action input, use lightning__AgentforceInput as the target. For output, use lightning__AgentforceOutput. For information about LWC target types, see lightning__AgentforceInput Target and lightning__AgentforceOutputTarget.
Note
This sample code shows the contents of the flightDetails.html file.
Integrate Custom Lightning Type into Agent Action Output
To add a custom Lightning type to the agent action, complete these steps.
Open the agent action.
Edit the Output Rendering parameter of the agent action output for aFlight.
Select the custom lightning type flightResponse.
Save the agent action.
The Unsupported Data Type message appears in the Map to Variable parameter. You see this message when you refer to types such as @apexClassType and custom Lightning types in an agent action’s Output Rendering parameter. This message doesn’t affect your saved work and can be safely ignored.
This image shows the custom Lightning type that you created.
Customized Output UI
Before executing the agent action that you modified, reload the agent page. The agent prompts you to provide input and then generate the output. The output provides a new UI experience.
This image shows how the custom agent action’s output appears in an agent conversation.
Customize UI for Input
Create a custom Lightning type named flightFilter to show filters in the input UI that suits your business needs.
Override Default UI for Input with Custom Lightning Types
Override the agent’s action UI for input to enhance the user experience by using Custom Lightning Types (CLTs). With CLTs, you can add your own Lightning Web Components (LWC) to present data in a more structured and intuitive format
Configure the editor.json file to override the default UI of a custom Lightning type in the agent action.
Here’s an example that shows a lightningTypes folder for a custom Lightning type named flightFilter.
This example uses lightningDesktopGenAi to configure the custom Lightning type. To configure the type for the enhancedWebChat channel, create the editor.json file in the corresponding channel folder.
Note
The custom Lightning type flightFilter includes a schema.json file and an editor.json file. The editor.json file controls how the data is displayed to the user in the agent action input.
This sample code shows the contents of the schema.json file.
Build Input Components with Lightning Web Components
This section explains how the components are created and deployed for agent action input.
This image shows the Lightning Web Component (LWC) folder structure.
The LWC component includes HTML markup designed to accept input for @apexClassType/c__FlightRequestFilter. This HTML markup ensures that the data is displayed in an intuitive and customized format.
This sample code shows the contents of the flightRequestFilter.js-meta.xml file.
When you create an LWC component to override the UI for action input, use lightning__AgentforceInput as the target. For output, use lightning__AgentforceOutput. For information about LWC target types, see lightning__AgentforceInput Target and lightning__AgentforceOutput Target.
Note
This sample code shows the contents of the flightRequestFilter.html file.
You must include the handleInputChange() function to capture user input, update the component’s state, and notify the parent component (planner component) by using the valuechange event. The function ensures real-time data binding and prevents unwanted event propagation.
Integrate Custom Lightning Type into Agent Action Input
To add a custom Lightning type to the agent action, complete these steps.
Open the agent action.
Edit the Input Rendering parameter of the agent action input for filters.
Select the custom lightning type flightFilter.
Save the agent action.
The Unsupported Data Type message appears in the Map to Variable parameter. You see this message when you refer to types such as @apexClassType and custom Lightning types in an agent action’s Input Rendering parameter. This message doesn’t affect your saved work and can be safely ignored.
This image shows the custom Lightning type that you created.
Customized Input UI
Before executing the agent action that you modified, reload the agent page. The agent prompts you to provide input and then generate the output. The input provides a new UI experience.
This image shows how the custom agent action’s input appears in an agent conversation.
In certain instances the large language model (LLM) requests input as text, so make sure to accurately update the subagent instructions for the correct selection of the Override Input component. For example, when you enter a prompt to find flights, the agent executes the Find Flight action. The Find Flight action executes by taking input through a UI form, and not in the form of Text because it includes a price and discount range.