Skip to main content
The online Trailblazer Community is now read-only. Soon, the Trailblazer Community will come together in Slack for what’s next. Read the FAQ | Get Help

Code a New Subagent

Learning Objectives

After completing this unit, you’ll be able to:

  • Use natural language prompts to add a new subagent to an agent.
  • Validate that the new subagent works as expected.
  • Publish and activate an agent.

Code a New Local Events Subagent Using Agentforce Vibes Prompts

Now that you’ve explored the existing capabilities of Local Info Agent, it’s time to add a new feature using natural language prompts. Next, you create a Local Events subagent that provides guests with details about events and activities happening outside Coral Cloud Resort in Port Aurelia.

  1. In Agentforce Vibes IDE, make sure the Local_Info_Agent.agent Agent Script file is open in the Editor window.
  2. In the Agentforce Vibes chat interface, enter this prompt. Remember you may have to select Run multiple times as Agentforce Vibes works.
Update this agent to provide guests with details about local events and activities happening outside the resort. If there’s existing logic in the repo that would help, use it. Call the new subagent "local_events" (label: "Local Events") and new action "check_events" (label: "Check Events"). Update any existing high-level descriptions and instructions for the agent with the new functionality. Don’t publish the updated agent until I tell you to. Run quick preview tests to make sure the new and existing functionality continues to work.
Note

Because AI-powered tools are nondeterministic, Agentforce Vibes may approach this task in different ways. It might propose a plan for the new local_events subagent; in which case you must explicitly approve the plan to proceed. Alternatively, Agentforce Vibes may apply the updates directly to the Agent Script code. In either case, it automatically validates the changes by running programmatic agent preview commands to ensure the new subagent and existing functionality perform correctly.

As mentioned in the previous unit, your results can vary from the screenshots and example output in this badge. It sometimes makes mistakes and then corrects itself. Complex tasks can take about 10 minutes. Stay nearby while it works, because it might ask your permission to run commands. When it does, select Run to continue.

When Agentforce Vibes has finished coding, you see a summary of what it did, including the results of the preview tests it ran. It might take a while for Agentforce Vibes to finish, so sit back and watch how it works. As mentioned previously, if you see an error because it went down the wrong path, watch it self-correct.

  1. Review the new local_events subagent in the Local_Info_Agent.agent file. You should see a new section in the file that looks something like this (remember that your exact session may look a little different):
subagent local_events:
    label: "Local Events"
    description: "Handles guest inquiries about local events and activities happening outside the resort in the surrounding area of Port Aurelia."
    reasoning:
        instructions: ->
            | Your job is to help guests discover local events and activities happening near Coral Cloud Resort in Port Aurelia.
              Ask the guest what kind of event or activity they are interested in (for example, movies, shows, cultural events, or educational activities).
              Once you have their interest, call the {!@actions.check_events} action with their interest as the event type.
              Present the results clearly and helpfully to the guest.
        actions:
            check_events: @actions.check_events
                with Event_Type = ...
    actions:
        check_events:
            description: "Retrieve information about local events and activities happening in Port Aurelia near Coral Cloud Resort."
            label: "Check Events"
            target: "prompt://Get_Event_Info"
            include_in_progress_indicator: True
            progress_indicator_message: "Checking local events..."
            inputs:
                Event_Type: string
                    label: "Event Type"
                    description: "The type of event or activity the guest is interested in (e.g. movies, shows, cultural events, educational activities)."
                    is_required: True
            outputs:
                response: string
                    label: "Response"
                    description: "Information about local events matching the guest's interest."
                    is_displayable: True
                    filter_from_agent: False
Note

The new subagent should include a check_events action that uses the Get_Event_Info prompt template. This prompt template already existed in the sample repo, so Agentforce Vibes used this template instead of creating a new one.

  1. When you’re satisfied, save the Agent Script file by pressing Ctrl+S (Windows) or ⌘+S (macOS).
  2. Open the Agentforce DX panel by clicking in the Activity Bar.
  3. Open the History tab in the Agentforce DX panel. You should see a new live test that verifies the local events functionality.
  4. To interactively test the new functionality, open the Preview tab in the Agentforce DX panel, click Resume Live Test, and enter this prompt in the chat interface:
What movies are playing locally?

The agent either asks you for more details about your question, or just lists a few options. If you don’t see a list of movies, try stopping and restarting the live test. If that doesn’t work, try recompiling and restarting the agent by selecting .

Agentforce DX panel showing responses to the prompt “What movies are playing locally?”. The Agent Preview tab, the Recompile button, and the Stop Live Test button are highlighted.

Publish and Activate Your Agent

Now that your new feature is ready, it’s time to publish the agent to your Trailhead playground org and activate it. In Agentforce Vibes IDE, select the Agentforce Vibes icon from the Activity Bar. In the Agentforce Vibes chat interface (not Agentforce DX!), enter this prompt (and remember to select Run if you’re prompted):

Publish the Local Info Agent to my org and activate it.

Agentforce Vibes publishes the updated agent definition to your playground org and activates it so it’s ready for use. You’ll receive a confirmation in the chat interface when the process completes.

View the Agent in Agentforce Builder

Switch to your playground org’s Agentforce Builder UI where you can preview and code your agent just like you did in Agentforce Vibes IDE.

  1. From the App Launcher in Salesforce, find and select Agentforce Studio.
  2. In the list, select Local Info Agent.

Agentforce Builder opens and displays a visual summary of the Local Info Agent. On the left you can get more information about its settings, subagents, and more. This is the same agent you modified using pro code tools in your DX project, now visible in the declarative interface.

Agentforce Builder open to the Local Info Agent, with the new Local Events subagent highlighted.

Congratulations! You just learned how to use Agentforce Vibes to explore and update an agent. You also had a brief glimpse into Agentforce DX—the suite of pro-code tools for building agents—and Agent Script, the language that powers them. Additionally, you tried out Agentforce Builder, the in-org UI for agent development. You did a lot! You’re well on your way to becoming a productive member of the Coral Cloud Resort development team.

Resources

Share your Trailhead feedback over on Salesforce Help.

We'd love to hear about your experience with Trailhead - you can now access the new feedback form anytime from the Salesforce Help site.

Learn More Continue to Share Feedback