Create Agent Actions from API Operations

Use an AuraEnabled Apex class retrieved from your org to generate an OpenAPI document and External Services Registration metadata. Then deploy the OpenAPI document to create API operations that you activate for use as agent actions.

Before you generate an OpenAPI spec document from AuraEnabled Apex classes, retrieve the classes into your VS Code project.

The Org Browser displays all the metadata types in your connected org and makes it easy to retrieve any metadata component. Use the org browser to navigate to your existing AuraEnabled Apex classes for which you want to generate the OpenAPI specification (OAS) document. Click the retrieve icon next to the metadata type to quickly retrieve the required classes. The retrieved classes are located in the /force-app/main/default/classes in your Salesforce project. See Org Browser to learn more.

  1. Run SFDX: Create OpenAPI Document from this Class (Beta) from the command palette or the context menu.

  2. In the search bar, enter the folder where you want to store the generated files or accept the default externalServiceRegistration folder.
    The command generates the files <ApexClass>.yaml, and <ApexClass>.externalServiceRegistration-meta.xml.

    The description that appears in your org's API catalog comes from the top-level description mapping in the YAML file, not the <description> element of the XML file.

  3. Run the SFDX: Deploy This Source to Org command on the generated XML file to deploy the metadata to your org.
    The command to deploy isn't ‌available on the YAML file. If the command times out, try again at a later time.

You can regenerate an OpenAPI document if you modify the Apex class associated with it.

  1. Make the changes to the Apex class associated with the OpenAPI document.
  2. Run the SFDX: Create OpenAPI Document from this Class (Beta) command.
  3. Select Overwrite or Manually merge with existing ESR from the window. Overwrite directly overwrites the existing OpenAPI document; this action is irreversible. The Manually Merge with Existing ESR option opens a diff window comparing the original and new OpenAPI documents. The new files are generated with the naming format: <ApexClass>_<timestamp>.externalServiceRegistration-meta.xml and <ApexClass>_<timestamp>.yaml.These files are located in the esr_files_for_merge folder in the root directory of your Salesforce project.
  4. Check the Problems tab for any errors or warnings in the new OpenAPI document (identified by the timestamp) and manually merge the changes from the newly generated OpenAPI document into the original document.
  5. Run the SFDX: Validate OpenAPI Document (Beta) command on the merged or overwritten OpenAPI document.
  6. Deploy the validated OpenAPI document to your Salesforce org.

You may encounter API Catalog limits when deploying. See Limits.

The OpenAPI document you deploy to your org describes the AuraEnabled API. After deployment, your API and its operations are registered in your org's API catalog.

  1. In your org, from Setup, in the Quick Find box, enter API Catalog and select it. See View Apex APIs in API Catalog.
  2. To view AuraEnabled APIs, select the AuraEnabled list as the source.
  3. Click the AuraEnabled API you created to view its operations.
  4. Activate operations to make them available for creating agent actions.
  1. In your org, from Setup, in the Quick Find box, enter Agentforce Studio.

  2. In the Agentforce Asset Library, click New Agent Action.

    The API and its operations are available as an Apex Reference Action type that you use to create a custom agent action.

    Apex tab in API catalog