Connect Flows to Agentforce with Actions
Learning Objectives
In this project, you’ll:
- Test Agent actions with sample data in Agent Builder.
- Create a custom Agent action to use Flow for automation.
Bring Agentforce into the Conversation
Generative AI has made it possible to interact with computers in the same way we interact with our friends and coworkers: with conversational language. And with our Agentforce platform, you can add the amazing power of generative AI into Salesforce so your customers and employees can interact conversationally, too.
Agentforce is a team of autonomous agents that help your Salesforce users with common business tasks, and it’s seamlessly built into the Salesforce interface. Using everyday language, users can ask their Agentforce to get the latest hot leads, summarize a case, or draft an email to a potential customer.
As you learn in Agents and Angentforce Basics, agent actions and custom actions are the building-blocks for these natural interactions. For example, one action, called Query Records, finds and retrieves Salesforce records based on the user’s request and specific conditions. Agentforce comes with many actions out of the box, and together they allow for some really sophisticated interactions. Custom actions allow you to create actions that are unique to your organization, and they can even harness your flows, prompt templates, or Apex for truly impressive interactions.
In this project you explore the standard Agent actions, and learn how to test them in the Agent Builder. Then you create a custom action that uses an existing flow that we’ve already set up to initiate a return for a recent order.
Sign Up for a Trial Org with Einstein Generative AI
To complete this project, you need a special, limited-time custom playground that contains Einstein AI and our sample data.
- If you haven't already, click the I can receive a password email checkbox in the beginning of the unit.
- Click Create Playground.
- Follow the prompts.
- Make note of your org's expiration date and complete this badge before then.
Get to Know Agent Actions
Agentforce is already quite capable out of the box thanks to the premade actions that you just learned about. Let’s take a minute to review those actions in Agent Builder, and discover what Agentforce can do without any customization on your part.
- If you don’t already have your Einstein AI-enabled trial org open, scroll down to the Challenge section and click Launch to open it.
- From the App Launcher, search for
orders
then click Orders.
- Choose the All Orders list view.
Two orders will appear, both for Edge Communications. They play a role later in our story, so it’s good to verify they exist. Now we can set up Agentforce.
- In the upper right corner, click
and click Setup. The Setup page opens in a new tab.
- In the Quick Find box, enter
einstein setup
, then click Einstein Setup.
-
Turn on Einstein by clicking the toggle. It may already be on if you’ve completed the Quick Start: Prompt Builder project.
- Refresh your browser window. This reveals new admin settings now that Einstein is enabled.
- In the Quick Find box, enter
agent
, then click Agents.
Currently, you can customize and launch one agent for your employees, and that agent is available in the flow of work in Salesforce.
- Turn on Agentforce by clicking the toggle, and refresh your browser window again.
- Click Agentforce (Default) (formerly Einstein Copilot), found at the bottom of the page. (If you don’t see it, refresh your browser window again.
- Click Open in Builder.
- In order to make changes you need to ensure the agent isn’t active. If you see a Deactivate button in the upper right, click Deactivate. If it says Activate, your agent currently isn’t active and you can continue to the next step.
- If your agent is named Einstein Copilot, click Settings, rename it to
Agentforce (Default)
and click Save. If not, continue to the next step.
- The first thing we need to do is add a standard Topic. Click New, and select Add from Asset Library.
- Check the box next to General CRM and click Finish.
- Click the Refresh button
in the Conversation Preview window, to ensure your new Topic is utilized.
Welcome to the Agent Builder. Here you can try out your agent and witness how it plans its response using real data.
It’s okay if you see an error message in the Conversation Preview, the following directions will still work. Let’s start a conversation by asking your agent to search and retrieve a record.
- In the Conversation Preview window, enter
Tell me about the orders for the account Edge Communications.
Then press return (MacOS) or Enter (Windows).
Agentforce begins processing your request. It’s figuring out what you intend, and how to respond. In a moment you’ll get an answer that’s based on the available actions. Agentforce uses large language models (LLMs) so you might find some questions return results that are a bit different that the screen captures in this project.
If you get a message that Agentforce is having trouble, then click the Refresh buttonin the Conversation Preview window to try again.
- If Agentforce asks you to pick a record, select
Edge Communications
and click Submit.
A lot happens when you ask this question. And in Agent Builder, you see the process your agent follows in order to respond.
For this request, your agent recognized that two actions were required. First, it needed to identify the correct account. Second, it needed to identify the correct records within the Accounts object. The ability to reason and call the right actions is one of the things that make your agent especially good at maintaining its side of the conversation. Another important part of holding a conversation is remembering details that were brought up earlier. Agentforce can do that too! For example, you can ask it to provide more details about something it previously mentioned.
In the Conversation Preview window enter What is the oldest order?
Then press return (MacOS) or Enter (Windows).
This time Agentforce uses the context of the conversation to understand that you are asking about orders specific to Edge Communications. After a moment, details of the two existing orders appear.
Create a Custom Action
The standard actions can do a lot, but in this scenario you have a special process for handling order returns. In fact, you already have a flow that automates the process. (Team Trailhead made the flow for you in your Einstein AI-enabled org.)
You can use that flow to extend the capabilities of your agent, by creating a custom action that references the flow.
- Click the left arrow
to exit Agent Builder.
- In the Quick Find box, enter
agent
, then click Agent Actions.
- Click New Agent Action.
- For Reference Action Type, choose Flow.
- For Reference Action, choose Initiate Return.
This is the existing flow you’ve been using to initiate order returns.
- Click Next.
- For Agent Action Instructions, paste the following text:
Use Initiate Return for requests to return or refund orders or products in an order.
- Check the box labeled Show Loading text for this action and paste the following text:
Initiating your return or refund.
- For Instructions (under Inputs), paste the following text:
Populate this input variable with an Order recordId.
- Check Require Input.
- Check Collect data from user.
- For Instructions (under Outputs), paste the following text:
This output indicates the status of the return request, whether it has been initiated, processed, or completed.
- Check Show in conversation.
- Click Finish.
Excellent, your custom action has everything it needs. For this example, we supplied the descriptions because they’re critical to how the action functions. They’re part of the prompt that Einstein AI sends to the LLM. You can learn all about what makes a great prompt in the Prompt Fundamentals badge. Then use the prompt engineering skills you learn to make the descriptions for your custom actions clear and complete.
Now go back to the Agent Builder to add the new action to your agent.
- Click Agents.
- Click Agentforce (Default) (formerly Einstein Copilot).
- Click Open in Builder.
Ensure your agent isn’t active, it should show an Activate button. If it shows a Deactivate button, click Deactivate.
- Under Topic Details, click General CRM.
- Click This Topic’s Actions.
- Click New Version at the bottom of the Action list.
- Click New, then select Add from Asset Library.
- Check the Initiate Return box and click Finish.
- Click the Topic Configuration tab and click Save at the bottom.
- Refresh your browser window and then click on General CRM.
- Click This Topic’s Actions and verify the Initiate Return action is still in the list. If it isn’t, repeat steps 7 - 11. Sometimes in our practice environments an added action does stay associated with the topic the first time you save it.
- Click Activate.
Great, your agent can now use the Initiate Return action in a conversation. Let’s try it out as if we were an actual user.
- Close the Setup tab to return to the Sales app.
- Click the Home tab.
Let’s start from Home as if we were just starting our day.
- Refresh your browser window, which should make the Einstein button appear.
- Click the Agentforce button to open the conversation window.
- To start your test, give your agent some context to work with by finding a specific order. In the conversation window, type
What is the order with the most recent order start date?
Then press return (MacOS) or Enter (Windows).
After a moment it should display order 101, with a clickable link.
- Click order number 00000101. Edge Communications ordered these items accidentally, so let’s start a return. Sometimes in our practice environments the agent won’t provide a link to the record directly. If that is the case find order 00000101 from the Edge Communications account and open it manually. This won’t prevent you from completing the remaining steps.
- In the conversation window, type
Start a return for this order
. Then press return (MacOS) or Enter (Windows).
Because your custom action has a clear and comprehensive description, your agent can identify it as the action you intend to take. So it kicks off the related flow, and gives you a status update.
- Click the Details tab. (If you don’t see the Details tab, make sure you’re in order number 00000101.)
If you scroll to the bottom of the page, you’ll find that the Return Status field has been updated to Initiated thanks to the Initiate Return flow.
With just a few clicks, you can incorporate existing automation into your agent’s catalog of actions. Now, automations and processes that are unique to your organization can be part of the conversation when interacting with Einstein AI. Next, click Verify step to earn 100 points below to check your work and earn your badge.
Resources
- Trailhead: Agents and Agentforce Basics
- Trailhead: Prompt Fundamentals
- Salesforce Help: Best Practices for Agent Action Instructions