Skip to content

Exercise 2 - Extend Agents with Subagents and Actions

In this exercise, you’ll create a new subagent, wire it into the Agent Router for routing, and add an Apex-based action so your agent can search for storefronts by name. You’ll validate routing and action behavior using Preview and Interaction Details.

Step 1: Create the Storefront Search subagent

  1. In Agentforce Builder, click the + sign besides Subagents in the explorer.
  2. Select + New Subagent.
    Image
  3. Set the following values:
FieldValue
Subagent NameStorefront Search
DescriptionHelp users locate storefronts or restaurants by name and confirm the correct storefront based on user input.
  1. Click Create and Open.
  2. Paste the following into the Instructions Section:
Assist the user in locating a storefront or restaurant by its name. Ensure the process is user-friendly and prioritizes accuracy.
  1. Click Save to save the changes.

Step 2: Test subagent routing

  1. Click Preview to test the agent.
  2. Enter the following prompt:
Can you search for a restaurant for me?
  1. Press Enter on your keyboard.
  2. Click on the entry next to Transition to Subagent in the Interaction Details section on the right, and explore the reasoning details.
    Image

Step 3: Create an Apex-based action (storefront search)

Next, you’ll create a subagent with an Apex-based action so the agent can search storefront records by name.

  1. In the Explorer, Select the Storefront Search Subagent
  2. Click on the plus icon besides Actions, and select New action.
    Image
  3. Set the following values:
FieldValue
Action NameStore Search
DescriptionRetrieves store information based on a user query.
Reference Action TypeApex
Reference Action CategoryDefault (Invocable Method)
Reference ActionGet Storefronts by Name
Outputs - StorefrontsSelect checkbox Show in conversation
  1. Click Create and Open.

  2. Click Save.

  3. Scroll down to Outputs and check the box for Show in conversation.

  4. Open the Storefront Search subagent again from the the explorer view.

  5. Under Actions Available For Reasoning, expand the store Store Search action.

    TIP
    Per default the action inputs are defined in a way that the LLM selects which value it should pass to the action. Image

  6. Click Save.

  7. In the Storefront Search Subagent, Switch the current view from Canvas to Script.

  8. Click inside of the Script Editor and open the search (CMD + F on Mac or CTRL + F on PC).

  9. Search for the Store_Search action.
    Image

  10. Find the storefronts output and make the following changes:

    1. Update the output type to list[object]
    2. update the complex_data_type_name to "@apexClassType/c__AgentStorefrontActions$StorefrontSummary"

    Image

  11. Click Save.

Step 4: Test the storefront action

  1. Click Preview.
  2. Locate Set Context and click the little refresh icon to the right of it. Image
  3. Enter the following prompt:
Provide me information about the fusion bites restaurant
  1. Press Enter on your keyboard.
  2. Click on Action: Store Search in the Interaction Details area and review the action inputs and outputs.
    Image

You created a Storefront Search subagent and extended it with an Apex-based Store Search action to retrieve storefront details. You then tested routing and action execution in Preview using Interaction Details.

Step 5: Create the Get Customer Profile action

  1. In Agentforce Builder, switch to the Canvas View.
  2. Click the + sign besides Subagents in the explorer.
  3. Select + New Subagent.
  4. Set the following values:
FieldValue
NameOrder Issues & Refunds
Describe the job you want the subagent to doThis subagent resolves problems with orders, such as missing items, incorrect items, cold food, late deliveries, or orders that never arrived. It also handles support cases related to those issues—including creating a case, checking whether a case already exists, and providing case status/follow-up. It determines refund eligibility, issues refunds or credits, and explains outcomes clearly and empathetically to customers.
  1. Click Create and Open.
  2. Paste the following into the Instructions Section:
Address the user's concerns regarding their order. If the user reports an issue with their order, determine the nature of the issue (e.g., missing items, incorrect items, cold food, late delivery, or non-delivery).
  1. Click Save to save the changes.

Step 6: Create an action (Get Customer Profile)

  1. Open the Order Issues & Refunds folder in the explorer and select the subagent.
  2. Click on the + sign besides Actions, and select + New Action.
  3. Set the following values:
FieldValue
NameGet Customer Profile
DescriptionRetrieves a customer profile based on their email address.
Reference Action TypeApex
Reference ActionGet Customer Profile
Reference Action CategoryLeave as Default (Invocable Method)
  1. Click Create and Open.

  2. Leave the default input and output settings.

  3. Click Save.

  1. Inside the Order Issues subagent, click on the + sign besides Actions, and select Create new action.
  2. Set the following values:
FieldValue
NameGet Related Cases
DescriptionRetrieves a customer’s related cases (basic details) based on the requested case status.
Reference Action TypeApex
Refereance Action CategoryLeave as Default (Invocable Method)
Reference ActionGet Related Cases
  1. Click Create and Open.

  2. Click Save.

  3. Scroll down to Outputs and enter the following information:

    FieldValue
    Outputs - CasesSelect checkbox Show in conversation
  4. Click Save.

  5. In the Get Related Cases Action, Switch the current view from Canvas to Script.

  6. Find the Get_Related_Cases action.

  7. Find the cases output and make the following changes:

    • Update the output type to list[object] (Line 261)
    • update the complex_data_type_name to "@apexClassType/c__AgentCaseActions$CaseSummary" (Line 264)
  8. Click Save.

Step 6: Test the agent

  1. Click Preview.
  2. Locate Set Context and click the little refresh icon to the right of it.
  3. Enter the following prompt:
Can you show me all of my cases?
  1. Press Enter on your keyboard.
  2. When the agent asks for an email address, enter:
alex.morgan@example.com
  1. Press Enter on your keyboard.
  2. In Interaction Details, confirm the agent runs Get Customer Profile and then Get Related Cases, and that it shows the case results in the conversation.

You have created the core actions your agent will use for customer support workflows, added them to Order Issues & Refunds with baseline instructions, and tested that the agent can retrieve and display open cases.

This completes Exercise 2.

Released under the MIT License.