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.

Download these sample data files.

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.

AvailableFlight Class

This class defines a list that holds multiple Flight objects.

Flight Class

This class defines the data structure for flight details.

FlightRequestFilter

This class defines the data structure for the optional filters a user can apply when searching for flights.

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.

Before you can add custom Lightning types to agent actions, create the agent and configure it to use your Apex class.

  1. From the Agentforce Studio app, create a new Agentforce Employee Agent or Agentforce Service Agent and name it (for example, Flight Search Agent).
  2. Open your agent, create a new subagent named Flight Search, and open it to add actions.
  3. Add a new action named Find Flights to your subagent, set the Reference Action Type to Apex, and select the Find Flights method from the FlightAgent class you deployed earlier.
  4. Switch to Script mode and add is_user_input: True to each input that the agent collects from the user.
  5. In the Flight Search subagent, add instructions that tell the agent when to use the action and what data to collect. For example: “When a customer asks about flight availability or wants to search for flights, use the {!@actions.Find_Flights} action. Collect the origin city, destination city, and date of travel from the customer before running the action.”

This code shows the Flight_Search subagent and Find_Flights action that the preceding steps create. To create the same configuration directly, add this code to the agent script.

When you add the code directly to the agent script, also add this transition to the Agent Router’s actions section to route flight-search requests to the Flight Search subagent.

This image shows the transition in the Agent Router’s actions section.

Agent Router in Script mode with the go_to_Flight_Search transition in its actions section.

Agent Script identifiers are case-sensitive. The @subagent.Flight_Search reference must match the identifier in the subagent Flight_Search declaration.

See Also

Inputs and outputs for the agent action are defined by using standard Lightning types and Apex classes.

Input:

  • dateOfTravel, destinationCity, and originCity use standard Lightning types such as lightning__dateType and lightning__textType.
  • The filters input is a complex type that references an Apex class.

Output:

  • The output aFlight for the agent action is a complex type that references an Apex class.

Here’s an image that shows the custom agent action created.

Input and output settings for a 'Find Flights' agent action. Inputs: dateOfTravel, destinationCity, filters, originCity. Output: aFlight.

The available flight information is retrieved by using @apexClassType/c__AvailableFlight in the agent action output, where:

  • apexClassType is the bundle name.
  • AvailableFlight is the Apex class.

When you execute this agent action, it prompts you to provide input and then generates the output.

The agent’s action UI collects these details to find available flights.

  • Origin city
  • Destination city
  • Date of travel

Here’s the image that shows how the custom agent action input appears in an agent conversation.

Agent's response to collect flight details. The response lacks filter details for price and discount percentage, making it difficult to filter flight data.

The agent’s action UI returns the available flight details.

Here’s the image that shows how the custom agent action’s output appears in an agent conversation.

Agent's response to a flight details request. The response lacks labels and is presented in a format that is hard to understand.

The agent displays the flight data in the response.

Here’s the sample code that shows the available flight data.

Create a custom Lightning type named flightResponse to enhance the visibility of the information in the output UI.

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.

This image shows an example of the flightResponse folder structure.

The flightResponse folder contains schema.json and the enhancedWebChat and lightningDesktopGenAi folders. Each channel folder contains a renderer.json file.

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.

This sample code shows the contents of the renderer.json file.

See Also

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 folder contains a folder named flightDetails, which is the LWC component. The flightDetails folder includes CSS, HTML, JS, and metadata files.

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.

This sample code shows the contents of the flightDetails.html file.

This sample code shows the contents of the flightDetails.js file.

See Also

After you create a custom Lightning type and Lightning Web Component, configure the agent action to use them.

  1. In Agentforce Builder, open your agent.
  2. In the Explorer panel, go to your subagent and select the Find Flights action.
  3. Switch to Script mode using the toggle at the top of the canvas.
  4. Locate the aFlight output parameter in the action configuration
  5. Replace the existing value of the complex_data_type_name property ‌with c__flightResponse. Custom Lightning types use the c__ namespace prefix.
  6. Click Save.

The script will fail validation if you specify a non-existent custom Lightning type name.

Here’s an image that shows the custom Lightning type configured in Script mode:

The agent action outputs parameter with 'c__flightResponse' selected in the complex_data_type_name property.

See Also

Create a custom Lightning type named flightFilter to show filters in the input UI that suits your business needs.

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.

This image shows an example of the flightFilter folder structure.

The flightFilter folder contains schema.json and the enhancedWebChat and lightningDesktopGenAi folders. Each channel folder contains an editor.json file.

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.

This sample code shows the contents of the editor.json file.

See Also

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 folder contains a folder named flightRequestFilter, which is the LWC component. The flightRequestFilter folder includes CSS, HTML, JS, and metadata files.

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.

This sample code shows the contents of the flightRequestFilter.html file.

This sample code shows the contents of the flightRequestFilter.js 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.

See Also

After you create a custom Lightning type and Lightning Web Component, configure the agent action to use them.

  1. In Agentforce Builder, open your agent.
  2. In the Explorer panel, go to your subagent and select the Find Flights action.
  3. Switch to Script mode using the toggle at the top of the canvas.
  4. Locate the filters input parameter in the action configuration.
  5. Replace the existing value of the complex_data_type_name property with c__flightFilter. Custom Lightning types use the c__ namespace prefix.
  6. Click Save.

The script will fail validation if you specify a non-existent custom Lightning type name.

Here’s an image that shows the custom Lightning type configured in Script mode:

The agent action inputs parameter with 'c__flightFilter' selected in the complex_data_type_name property.

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.

See Also

After you configure the custom Lightning types for both input and output in the agent script, preview the conversation to verify the user experience. Once you’re satisfied with the customized UIs, commit and activate your agent to make it available to users.

  1. In Agentforce Builder, click the Preview tab.

  2. Enter a test utterance, such as “Find flights.”

  3. When the agent prompts for filter details, verify that the custom input form displays the price and discount fields exactly as you designed them in flightFilter.

    This image shows how the custom agent action’s input appears in an agent conversation.

    Agent's response to collect flight details. The response includes filter fields for price and discount percentage, making it easy to filter flight data.

  4. Submit the form and review the agent’s final response to verify that the flight data renders using your custom flightResponse LWC cards.

    This image shows how the custom agent action’s output appears in an agent conversation:

    Agent's response to a flight details request. The response includes clear labels and is presented in a format that is easy to understand.

  5. At the top of the canvas, click Commit Version and then click Commit to confirm.

    To make further changes after this point, you must create a new draft from the committed version.

  6. With the committed version selected, click Activate and confirm the activation to make the agent available to users. The currently active version (if any) is automatically deactivated.

See Also