Enhance workflows with agentforce's real-time insights

Enhance Workflows with Agentforce’s Real-Time Insights

By

Editor’s note: This post was updated on November 14, 2024, with the latest information and resources.

Empowering your teams with real-time insights is key to staying competitive. Agentforce gives you the tools to create customized agents with development options that best suit your company’s needs. 

When setting up custom agent actions, a common use case is getting it to provide real-time, actionable insights. Your knowledge of your org’s processes is the key to leveraging Agentforce’s functionalities. Imagine your users are browsing an opportunity and they want to know how likely they are to close it so they can prioritize their time. Or, they might be looking at some leads and trying to figure out if they’ll convert or not.

With Agentforce custom actions, you can enable your users to receive that information directly within their workflows so they can make informed decisions and take proactive measures.

Define your use case

Are you looking to predict the win rate of an opportunity? The conversion rate for a lead? In order for your agent to surface real-time insights, you’ll need to first train and create a predictive model. Your use case will inform the data you need to prepare for it.

Here at Salesforce, we have two ways of creating a model: Our no-code Model Builder and our bring-your-own-model option. 

We’ll focus on our no-code option here. This is a quick, low-friction way of creating models for deployment. It supports binary classification and regression models, and it’s a fast and easy way for anyone to onboard onto model building.

You can read about the Bring Your Own Model (BYOM) option in the Resources section at the end of this post.

Prepare your data

The key to a good model is good data. First, ensure that you have a sufficient and organized amount of data; this is what your model will be trained on. With this data, your model can recognize patterns and trends that enable it to make informed predictions in real life. Luckily, with Data Cloud, we have a centralized way to ingest and prepare data for model building. 

Start by ingesting your desired data as a data stream. In Data Cloud, select the Data Streams tab and click New. You can ingest Salesforce objects or external data.

Data Streams section of Data Cloud showing list of data streams.

Next, map your data to a data model object (DMO). By doing so, you make your data recognizable to the Salesforce ecosystem. If you leave your data unmapped, you won’t be able to leverage it.

Data Cloud DMO mapping page showing a data lake object being mapped to a DMO.

After mapping your data, you’re ready to move on to preparing your model.

Prepare your model

Select the Einstein Studio tab. From there, click Add Predictive Model to launch into Model Builder.

Einstein Studio section of Data Cloud showing button to Add Predictive Model.

Choose the no-code model option and click Next.

Model Builder page showing choice to create a model from scratch or connect an external model.

Select the DMO that you just created. This will be the data your model is trained on.

Model Builder page showing data space and DMO choice for model training.

You also have options to filter or choose all of that data for your model.

Model Builder page showing ability to filter down records for model training.

Next, set the goal for your model. Think of this as what you want your model to predict.

Model Builder page showing ability to set which field the model should predict and set the goal of prediction.

You can also choose if you want to include all variables or just a subset of them in your model. This can be helpful if you don’t want to take some variables into consideration.

Model Builder page showing ability to choose variables needed for model training.

Model Builder will suggest the right algorithm for your model, but you also have the option to choose your own.

Model Builder page showing ability to choose the algorithm for model training.

Click Next, then Save. Now, you can start training your model!

Activate your model 

Once your model is trained, don’t immediately activate it. A good model depends on good data, and this step will tell you if there are any data issues you should be aware of. 

On the model details page, click View Training Metrics to launch Model Builder again. Here, you’ll see a robust set of training metrics that provide more information on your data and your model performance.

Model Builder training metrics page showing metrics such as AUC, prediction frequencies, threshold, F1 score, etc.

Not sure what some of the metrics mean? Don’t worry, hover over the ℹ symbol for more information. You can also be assured that if there are major issues in model accuracy, Model Builder will flag it to you.

If everything looks good, go to the top right and click to Activate the model.

Prepare model outputs for consumption

Again, we want our agent to provide real-time, actionable insights. As part of this, we don’t just want our agent to give us a prediction–we also want our agent to explain it and recommend some steps for improvement! 

We provide top factors and top improvements in our no-code models: Top factors help you understand what values contributed most to your prediction, while top improvements provide quantifiable, actionable steps towards your goal (which here is maximizing the likelihood of winning an opportunity!) 

Top factors come out of the box, but you’ll have to configure actionable variables for top improvements: In other words, you need to tell your model what variables are actually changeable or not by your user. Imagine telling someone to change the address of an opportunity to boost its win rate–that would not be helpful!

To do so, navigate to the model you want to use in Einstein Studio, click on the Integrations tab, and choose which variables are actionable. In our simple use case here, those would be amount and discount.

Actionable variables setting page showing list of variables and checkboxes to select which ones are actionable.

Next, we’ll also keep in mind that our top factors and improvements are formatted in different ways for each integration. For Flow, which you will be using, top factors and improvements are delivered as JSON–but you want your agents to respond to you in natural language. 

To do this, let’s create a nifty prompt template that will take in JSON and output paragraphs. We’ll provide the example below, but due to how extensible Prompt Builder is, you can choose to write and tune your prompt in any way that works for you. 

For this example: you can start by creating a flex prompt with three free text inputs: the Prediction Value, Top Factors, and Top Improvements.

New Prompt Template page showing a Flex prompt with free text inputs being created.

Then, in your prompt, make sure to provide a few examples of a JSON format for top factors and how it should be interpreted, and likewise for top improvements. This is a technique called few-shot prompting and helps clarify to the model how responses should be delivered.

Prompt Builder showing a filled out prompt template with examples of how to interpret JSON formats.

Make any additional formatting or tone requests, then save and activate. Now you’re ready to build your invocable action.

Create an invocable action

Now that you have a predictive model and a prompt template, you can have your agent apply that model conversationally to provide real-time insights. 

You can do this with a flow. First, launch the Flow Builder interface and create an autolaunched flow. Let’s use the example of getting the win rate of an opportunity.

Flow Builder showing Autolaunched Flow start node.

Your first node will be a Get Records element. This node will retrieve what the agent will look at to provide a prediction. For example, if you want the agent to provide the likelihood of winning an opportunity, you want this Get Records element to get an opportunity record. Make sure to describe what the input is.

Flow Builder showing Get Records element that retrieves Opportunity object.

Your second node will be a Data Cloud action. From Action, choose Data Cloud Action, then look for the name of the predictive model you created. After selecting that model, make sure you map the model inputs to fields on the record from the first node. This is very important because you want the model to look at the right fields before making a prediction.

You also have the opportunity to enable top factors and top improvements. You can enter any value from 0 to 3 for the number of top factors and improvements you want to receive.

Flow Builder showing Action node that maps object fields to input fields for a predictive model along with ability to select top recommendations and top predictors

We want to add our prompt node next to process the outputs from our second node into natural language. Remember how the prompt takes in free text inputs and how our top factors/improvements are JSON–to make top factors/improvements understandable to the prompt, navigate to the resource section on the top left and create two new text templates. 

Add the top factors output from the previous node to one text template and save.

Text template with only top factors added in Body.

Add top improvements to the other text template and save.

Text template with only top improvements added in Body.

Now you are ready for your third node, which will be our prompt template. Add an Action node and select your prompt.

Flow Builder showing another Action node added, with Prompt Template selected as the Action category.

And add in your prompt template inputs. Again, depending on how you configured your prompt template, this step may look slightly different.

Flow Builder showing configuration of Prompt Template Action node with all inputs mapped.

You are now ready for your last node, an Assignment element, where you assign the output of the previous node to the overall flow output. Make sure to describe what the output is.

Flow Builder showing an Assignment node populated.

Lastly, click Save and give your flow a description. In four nodes, you’ve set up your invocable action.

Save the flow page showing Flow Label, Flow API Name, and Description fields, all populated.

Create an Agentforce custom action

This is the last step. Go to Setup and search for “Agent Copilot Actions”. From there, create a new action. 

Choose Flow as your Reference Action Type and select the name of the flow you just created.

Create an Agent Action page showing Reference Action, Agent Action Label, and Agent Action API Name fields.

If you populated descriptions for your flow, you’ll notice that it auto-populates your action descriptions as well, saving you extra steps. If you haven’t populated them, it’s time to populate your action descriptions here. Make sure to require input and check show in conversation for your output.

Create an Agent Action page where Agent Action Instructions, Input, and Output are populated.

Then, navigate to Agents in Setup. Select the agent you want to assign this action to, then click Open in Builder.

Salesforce org with Agent open in Setup, button for Open in Builder on top right.

Once you are in Builder, select an existing Topic or create a new Topic you want to add this action to. Make sure to update the instructions of the topic to include this action, then click on This Topic’s Actions.

Agent Builder displaying a Topic created by the user.

From there, click New and Add from Asset Library, then scroll to select your action. You’ll also see the other OOTB or custom actions you have available.

Agent Builder displaying list of actions available to be added to a topic, with the action Predicted Win Rate of Opportunity selected.

Click Finish, and you are now ready to test your action and activate your agent.

Agent Builder displaying the created action, Predicted Win Rate of Opportunity, added to the topic.

Now, your agent can provide real-time, in-context insights to you and your users.

Salesforce org with Agent panel open on Opportunity object; Agent provides win rate of opportunity alongside an explanation and recommendation.

Explore the extended possibilities

We just covered one use case today, but with all our platform tools, there are infinite possibilities for leveraging Agentforce! The more invocable actions you create, the more custom actions you can create, and the more robust your agent can be. 

What will you do with Agentforce? We can’t wait to see!

Resources

A podcast cover featuring John Demby for the Salesforce Admins Podcast.

What Makes Tableau Pulse Essential for Salesforce Admins?

Today on the Salesforce Admins Podcast, we talk to John Demby, Director of Solution Engineering at Tableau. Join us as we chat about Pulse for Salesforce, Tableau Einstein, and how easy it is to get started. You should subscribe for the full episode, but here are a few takeaways from our conversation with John Demby. […]

READ MORE
Governance strategies for your first AI project

AI and Agentforce: Governance Strategies for Your First AI Project

There is a lot of excitement around artificial intelligence (AI) right now. New uses and new models are changing the way we think about how AI can support and improve the ways we work.  At Dreamforce ’24 one of the big announcements was Agentforce, a powerful companion to help Salesforce users resolve cases, answer questions, […]

READ MORE
Prepare for the AI Specialist Exam and Agentforce

Prepare for the Salesforce AI Specialist Exam and Agentforce

As Salesforce Admins, we have clear core responsibilities that define our day-to-day roles. We manage users, data, and product, provide actionable analytics, and oversee security. But we’re currently in the third wave of the artificial intelligence (AI) revolution: contextual and generative AI, characterized by prompt-based generative AI, real-time AI applications, and autonomous agents.  This means […]

READ MORE