Prompts and Prompt Builders in Salesforce Agentforce : Bijay Kumar

Prompts and Prompt Builders in Salesforce Agentforce
by: Bijay Kumar
blow post content copied from  SalesForce FAQs
click here to view original post



### Summary of the Content The content discusses how to effectively use prompts in Salesforce AgentForce to interact with large language models (LLMs) for generating useful responses. Prompts are essentially instructions given to the AI to retrieve information or perform tasks. The tutorial emphasizes that designing effective prompts is crucial for achieving better results from generative AI. Key points include: 1. **Understanding Prompts**: Prompts are the way users communicate with the AI. Specific prompts yield better, more relevant responses. 2. **Importance of Prompt Design**: The tutorial provides examples, illustrating how adding specific details to prompts can significantly enhance the quality of the AI's output. 3. **Salesforce AgentForce Features**: - **Prompt Builder**: A tool that helps create and manage prompt templates, allowing users to ground prompts with specific business data. - **Types of Prompt Templates**: - **Sales Email**: Generates email content based on Salesforce data. - **Field Generation**: Populates values in an object's field. - **Record Summary**: Summarizes records using Einstein Copilot. - **Flex Template**: Supports multiple object details in a single prompt. 4. **Creating Prompt Templates**: The content provides a step-by-step guide on how to create a field generation prompt template, including the use of Apex classes to enhance functionality. 5. **Conclusion**: The tutorial concludes by reinforcing the importance of effective prompt design and the capabilities of Salesforce AgentForce in leveraging generative AI. ### Additional Context In the realm of customer relationship management (CRM), effective communication and data retrieval are vital. Salesforce AgentForce's prompt builder allows sales and marketing teams to automate and streamline their processes, saving time and enhancing productivity. By grounding prompts in specific business data, users can ensure that the AI-generated content is relevant and tailored to their needs. ### Hashtags for SEO #Salesforce #AgentForce #GenerativeAI #PromptEngineering #CRM #AIPrompts #SalesAutomation #DataDrivenMarketing #EinsteinCopilot #SalesforceTutorials


Whenever you ask an agent a query or question, the prompts are how you communicate with the large language model(LLM). AgentForce responds to queries and requests in a language inspired by human speech and provides relevant responses.

Designing an effective prompt is key to unlocking the benefits of generative AI. In this tutorial, we will learn about prompts and prompt builders in Salesforce Agentforce. I will also explain how to use prompt templates created through the prompt builder.

Prompts in Salesforce Agentforce

In simple words, the prompts are the instructions that we give in the input to the Agent to retrieve information, perform a task, or take any other action. AgentForce responds to queries and requests in a language inspired by human speech and provides relevant responses.

Generative AI can give correct output or meaningful answers if it is given effective prompts. Prompts are the way you communicate with the large language model (LLM), and designing an effective prompt is key to unlocking the benefits of generative AI. This means that if your prompts are specific, then you will get much better results from the LM model.

Let’s understand this using an example of how effective prompts give better results via an LM model. In the OpenAI ChatGPT, I’m asking it to ‘Generate an image of a crowded city,’ and then we will see the difference in the output that it generates based on the prompts that we have given.

Prompts in Salesforce Agentforce

Now, let me give one more prompt with important information grounded in my needs. So here again I’m asking crowded citi but this time I want with specific details.

Specific Prompt in Agentforce

So, with this prompt, we can say that AI can give much more meaningful responses. The difference here is that the first prompt did not have grounded data, but the second prompt does, which is an Indian city.

So, when we added extra information or specific information, the response totally changed. That’s why it is vital to have an effective prompt.

Writing an efficient prompt has become very crucial when working with LLM or Gen AI technology. Now, let’s understand how it will help in Salesforce CRM.

In CRM, the sales rep or the marketing team needs to generate content to send to prospective leads or users. Gen AI is very good at generating content by analyzing large amounts of data and summarizing it in an exact, clear manner.

Prompt Builder in Salesforce Agentforce

In Salesforce CRM, getting specific details can be challenging for businesses because it requires you to add your business data to a prompt. So, it is not possible to do that for every customer or every product. Also, is your business data safe?

Because the prompt information will be sent to the LM model, the most crucial aspect here is how you ensure safety. This challenge is where the prompt builder and the Einstein trust layer come in.

What is Prompt Builder in Salesforce Agentforce?

The prompt builder helps us generate the prompt template, which can be used in different places. It is very similar to the copilot builder, where we added different actions and tested how our copilot was working.

In the prompt builder, we will create the prompt and ground it with the user data, the object data, or any information that we want to pass to the LLM.

  • A prompt builder helps us build trusted generative AI. It creates a prompt template bound to one or more objects to generate summaries or content.
  • For example, the template is generated to send an email to the user with the account data already fed into it. This will definitely save a lot of time for the salesperson, who would otherwise have had to go through the details to draft the email.
  • Enrich Prompts with your Data: This feature creates more relevant prompts grounded in your business data from CRM, cloud, and external storage.
  • Preview and Version Template: Since it’s a prompt builder, we can build the prompt, test it, and preview the response, and if it is not as per our need, we can regenerate it.
  • Use Template Everywhere: Build prompts once and reuse them everywhere so we can reuse these templates during the sales email. While sending the sales email, we can use them on a record page, call them from flow and Apex, and invoke them from Einstein Copilot.

What Types of Prompts and Where Can They Be Used in Agentforce

Below, I have explained prompt template types and their uses.

1. Sales Email: 

A sales email template generates email content bound to Salesforce data, such as an email to a contact or a lead. Once these prompt templates are activated, they start showing on the out-of-box draft and email quick action that you would have seen on a record detail page, where we can log a call, create a task, and draft an email.

So, there, you will start seeing an option to generate the email through the prompt template that we have configured. The trial org that we are using to learn Einstein studio does not have a sales email prompt template.

We can invoke or execute the sales template from the draft and email feature. So the draft and email feature is available on the record detail page. As you click on that, you will get an option or a dropdown where you can select the prompt template that you have configured, and it should generate the draft email, which the agent can look at and change the content.

The sales email template can also be invoked via Apex classes, which are also exposed as rest API services. You pass the parameter, and they return the response to the calling application.

2. Field Generation: 

A field generation template is used to populate values in an object’s field. For example, we can have a field on the account that summarizes all the orders placed until now or all the cases created against it. By looking at that agent, we can get a quick overview without going through account-related details.

Like the sales email template, the field generation template can be used on a record page, which means it is bound to a specific field, let’s say the account summary field. So, on the record page, you can place your summary field, and you can bound it to this particular template.

Then, whatever response comes from this template will be stored in that particular field. It can also be called via Copilot, action flow, rest API, and Apex.

3. Record Summary:

The record summary template is only used by Einstein Copilot, and it helps generate record summaries. We have seen some examples when we asked the copilot to summarize the lead or any other record.

The summary template is only specific to copilot action.

4. Flex Template:

The flex template is the most powerful of these four types. It supports up to five object details, which can be grounded in the prompt template, whereas the sales or field generation templates are only bound to specific record objects.

Create Prompt Template in Salesforce Agentforce

As we discussed, the sales email prompt template type is unavailable in the trial org, but the creation part is similar to how you will create any other prompt template.

Once the prompt template is activated, we have the option to use it while using the draft email feature from Salesforce. So, if the template is active, the user will get this option to use a draft with Einstein. It will show all the sales email prompt templates that the user can select, and it should generate the email content.

But since the sales email template is unavailable in our org, let’s try the next type of prompt template, field generation.

Prompt Templates in Salesforce

Create Field Generation Prompt Template

We want to have an account summary field in the account object. If we look at the information stored on this account, we see different contacts, opportunities, and cases. So we want to have an account summary field here, and the content of that field should summarize the different contacts this account has.

This will help the agent have a quick overview of the account just by entering this particular field. For that reason, I have created a custom field called account summary which is of type long text area.

Here is a very important point for the field generation prompt template: since it is bound to a field, the field type should be a text area field.

Field Generation Template in Agentforce

Now, let’s create the prompt template. Go to Setup -> In Quick Find, search for the Prompt Builder -> This screen is very similar to our Einstein Copilot action screen.

To create a new prompt, click the New Prompt Template button.

Create New Prompt Builder in Salesforce

Now, fill in the details for the new prompt template, as I explained below.

  • Prompt Template Type: We have four types of prompt templates. We need to select the type of template you want to create here. I have selected the Field Generation template.
  • Template Name: After that, provide the name of your template as per your requirement. The API Name will be automatically populated.
  • Description: Give the short intro about your prompt template.
  • Object: Select the object for which you are creating this field generation template. You also need to select the Object Field.

After that, click the Next button to proceed.

New Prompt Template in Agentforce

Now, we need to build our prompt template. Here, we can specify which Model to use, and we should be able to see the preview. For this prompt template, Salesforce offers various LL Models, and we can use any one of these available LLMs.

Since we have seen that the field generation template is for an account object, you should be able to see it in the Resource option.

  • Account: If we need to ground this template with account-related information, we should be able to access it through the Resource option.
  • Current User/Organization: Similarly, we can add information about the current user and the organization here.
Prompts and Prompt Builders in Salesforce Agentforce

So here, since we want this template to summarize the account information, we should give our prompt like the one below.

This is where we have to provide specific information about an account, which means that we are grounding the customer data into the prompt template. For that, we need the account name. Click on the Resource -> Account -> Account Name field.

If you want to add more information, you can again go to Resources -> Account -> where you will find all the account fields.

That means now this template has some static content and will have dynamic content based on which account is passed here. This is how we can ground the CRM data into the prompt, and this is what we can call dynamic grounding, which means that we are passing information about a particular record during the prompt’s runtime.

When this prompt executes, we pass that information just before that. So, you can add more information about this account object from the resource section. If you have to get information about the current logged-in user, I can get it through resources.

Now, we require that the information we want to feed into the prompt template be available in a third-party system. Maybe the information is a little complicated, requires a SOQL query to run, or requires some custom logic to run.

After that, we want to feed whatever response we have into the prompt template. So for such kind of requirement, you can invoke appex or flow, and they can respond whatever the response they will give back that will become the grounding data for this prompt template.

So for that, we need to create an Apex class, or you need to have specific flows. Then that apex class or flow will be available for a prompt template.

Create Field Generation Template in Agentforce

Apex Class For Prompt Template in Salesforce Agentforce

Below, I have created one Apex class, AccountSummaryPrompt. Just like our custom actions, if we want the Apex method to be available as a prompt template response, then that method should be annotated with the Invokable method. Here, this method is available for the record generation template.

Since our prompt template is for an account, the account is the related entity to that prompt template.

After that, save the apex class and navigate to the prompt builder again.

public class AccountSummaryPrompt {
    
    @InvocableMethod(label='Account Details'
                     description='Find Account details')

    public static List<Response> getAccData(List<Request> requests) {
        
        if (requests.size() != 1)  
            throw new IllegalArgumentException('The requests list must contain one entry only'); 
        
        Account acc = requests[0].RelatedEntity;

        List<Account> AccDetails = [SELECT Id, Name, Industry FROM Account WHERE Id = :acc.Id];

        String responseData;
        
        if (AccDetails.isEmpty()) {
            responseData = 'There are no Account records.';
        } else {
            responseData = 'Account Details: ';
            for (Account a : AccDetails) { 
                responseData += String.format('{0}, {1}.', new List<Object>{a.Id, a.Name});
            }
        }

        List<Response> responses = new List<Response>();
        Response res = new Response();
        res.Prompt = responseData;
        responses.add(res);

        return responses;
    }
    
    public class Request {
        @InvocableVariable(required=true)
        public Account RelatedEntity;
    }
    
    public class Response {
        @InvocableVariable(required=true)
        public String Prompt;
    }
}

Now, we need to add the apex class that we created. For that, click the resources -> Apex -> Select the label you provided in the apex invocable method. That Apex method will give the response in a string format that will be added here.

Salesforce Agentforce Prompt Builder

So, the final prompt, which already includes all this information, will be passed as a prompt to the LM model.

In the preview panel, we will see what our final prompt has been generated by actually adding this information here. In the response, we will see that by passing that prompt, what response are we getting from the LM model? So, for this one, let’s use a model like OpenAI’s GPT 4.

We have to give a related record to get that account’s name, which will also be passed to our Apex method. So, for that, let’s add our account. Let’s use sForce. You can click on Save and Preview. This is where you will see two pieces of information.

Prompt Template Workspace in Salesforce Agentforce

In the preview section, we see this prompt template. After grounding the information, how does it look? We were told to write a short paragraph summary of the account details. The account name is sForce.

You will see that it has grounded that information. The account name is now available here. The account details and the case details are listed below.

Prompt Builder in Agentforce

Conclusion

I hope you have a good understanding of prompts and prompt builders in Salesforce Agentforce. I have also explained how to use prompt templates created through the prompt builder.

We learned that designing an effective prompt is key to unlocking the benefits of generative AI. Also, I have explained the types of prompt templates and how to create a prompt template in Salesforce AgentForce.

You may like to read:

The post Prompts and Prompt Builders in Salesforce Agentforce appeared first on SalesForce FAQs.


March 27, 2025 at 07:09PM
Click here for more details...

=============================
The original post is available in SalesForce FAQs by Bijay Kumar
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.
============================

Salesforce