Agent actions with Prompt Builder and Flow Builder

Mastering Prompt Builder and Flow Builder: Unleashing Agent Actions for Success

By

Hey, rockstar admins! Prepare to skyrocket your prompt templates to new levels with your automation prowess using Flow Builder! Mastering the dynamic duo of Prompt Builder and Flow Builder will empower you to create powerful prompt template actions for your agents, setting you up for remarkable success as you lead artificial intelligence (AI) transformations in your company.

Watch the video from Dreamforce 2024: Automate This! Build Flows for Prompt Builder.


Prompt Builder: Your AI superpower

Prompt Builder is a fantastic tool for admins to build trusted AI with ease using reusable prompt templates that summarize and create content, increasing overall user productivity. If you’re just learning about Prompt Builder, I recommend you check out The Ultimate Guide to Prompt Builder blog. To further enrich your prompts, ground them in data to provide that use-case specific, relevant data that’s not in your LLM’s trained knowledge for that more personalized, relevant response using accurate and current data.

Flex your flow building skills

As an admin, one of your superpowers is building automation, and the tool to use is Flow Builder. You already use Flow to do some pretty cool things in your org. Flex your skills by building flows that go beyond the basic record fields and record related lists to perform the more complex data gathering to ground your prompt templates.

Prompt Builder showing the use of a prompt flow to ground the prompt.

Building prompt flows

To build flows for use with prompt templates, you’ll build template-triggered prompt flows. Now that’s a mouthful, so I call them prompt flows for short. A template-triggered prompt flow is a flow type that appears in the list of available flow types if you have Prompt Builder enabled in your org.

Flow Type selection screen during the flow creation with Template-Triggered Prompt Flow selected.

Prompt flows aren’t too different from the flows you already create. What makes them unique is the Add Prompt Instructions action. This action provides data in the form of prompt instructions that’s incorporated into a prompt template in Prompt Builder when the flow is selected as a resource to ground the prompt. Don’t worry, it will all make sense in a bit.

Add Prompt Instructions action in a prompt flow.

Basic prompt flow building block combo: Get Records-Loop-Add Prompt Instructions

A prompt flow, at its most simplistic build, consists of a Get Records element, a Loop element, and a Prompt Instructions action within the Loop. You essentially need to get data using the Get Records, then for each record found, you add specific information from the record into the prompt template using the Add Prompt Instructions action. That might be all you need to get the data and add it to the prompt template. This is not to say you can’t build pretty fancy in the data gathering in your prompt flows. Of course, you can. I see you overachiever Flownatics out there!

Example of a simplistic prompt flow with a Get Records element, Loop element, and an Add Prompt Instructions action within a Loop.

Example scenario: Mochi Cupcakes

Let’s use my Mochi Cupcakes example shown in the video to step through how we use our flow building skills in Prompt Builder.

Mochi Cupcakes is an old-school cupcake store. They don’t do online orders, only orders over the phone. Since the reps work with customers over the phone, they need a very quick way to recap the customer’s recent cupcake orders and, based on past orders, recommend a cupcake order including an over-the-top cupcake and cupcake classes to take, given past enrollments. They can’t afford to put their customer on hold while they figure out this information, so they turned to AI for help. Our solution to this business challenge includes building a prompt flow to ground a Field Generation prompt template.

The Mochi Cupcakes objectives and solution.

We’re not going to focus on the entire prompt we built for our Field Generation prompt template. As we built out the prompt template, we determined that we needed information on the regular and over-the-top cupcake flavors, frosting types, and decoration themes, and to get the information about the customer’s past class enrollments, cupcake classes, and class offerings. This data is beyond what we can access via merge fields in Prompt Builder. Prompt flow to the rescue!

Highlighted section of the prompt template where a flow is needed to retrieve the data to ground in the prompt.

As you can see in the video at the 18-minute mark, I step through Mochi’s Suggestive Order and Course prompt flow.

In the Start element of my prompt flow, I specify to use (1) Automatic Inputs so I’m using inputs sent from my prompt template type instead of manually creating my own input variables. In my case, I’m using the (2) Field Generation Template Capability and my object is (3) Contact. Note: The Contact object is key to something we will reference later on in this prompt flow.

Start element of the prompt flow where I specify Automatic Inputs, Field Generation Template Capability, and the Contact object.

The bulk of this flow consists of the basic Get Records, Loop, Add Prompt Instructions combo for getting the cupcake flavors, over-the-top cupcake flavors, frosting types, over-the-top frosting types, decoration themes, over-the-top decoration themes, and cupcake courses.

Since all of these are pretty much the same except for the filter criteria of the Get Records element and what is captured in the Prompt Instructions action, I’ll show you how I retrieved the cupcake courses.

Steps used in the prompt flow to ground the prompt template with data about the cupcake courses.

In my Get Records element for cupcake courses, I’m getting all my records from the Course object—no filtering or sorting—and I’m storing all the fields automatically.

Get Records element for Courses in the prompt flow.

Next, I have my Loop element which will loop through each record from my ‘Get Courses’ Get Records element.

Courses Loop element from the prompt flow.

Here’s the important ingredient to making this all work with the prompt template: the Add Prompt Instructions action. Notice, in the Prompt Instructions area, I’m using merge fields from my Loop record to gather the course name, course description, and course duration for my prompt template.

Add Prompt Instructions action in the prompt flow.

I want to gather all the future class offerings for my prompt because I don’t want to recommend any class offerings that have already happened. In this case, I used the Get Records element to get the classes, then a Decision element to determine whether the class was in the future and, if so, for each record from the Get Records collection, I would add that class offering to the prompt template. Again, this still follows the basic Get Records-Loop-Add Prompt Instructions combo with a Decision element thrown into the mix.

An example for the Get Records-Loop-Add Prompt Instructions combo with a Decision element in the prompt flow.

Meet $Input, the new global variable

The last portion of my prompt flow is getting the customer’s enrollments using a Get Records element, then using a Decision element to determine whether the flow found any enrollments. If yes, we loop through each record from the Get Records collection and add the past enrollments to the prompt template.

Another example for the Get Records-Loop-Add Prompt Instructions combo with a Decision element in the prompt flow.

In the Get Enrollments Get Records element, I filtered the records from the Enrollment object using Contact equals to the contact ID passed from Prompt Builder to my prompt flow. Note: The value uses $Input > RelatedEntity > ContactId. $Input is a new global variable. This indicates the input passed from the prompt template. Remember the Contact object I specified in the Start element? That is the Related Entity. After selecting the Related Entity, I select the Contact ID. Check out the 20:06-minute mark in the video where I talk about this in greater detail.

 ‘Get Enrollments’ Get Records where the records are filtered, where the contact is the contact ID passed from the prompt template.

Test and activate your prompt flow

After you build your flow and before activation, test your flow using Debug. One thing I’d like to point out is that the Add Prompt Instructions action behaves like an Assignment element. It takes the contents of that Prompt Instructions box and assigns the value to the output variable prompt ($Output.Prompt).

Debug details showing the Add Prompt Instructions action writes to the Prompt output variable in the prompt flow.

The prompt flow continues to add data to the Prompt variable each time it’s invoked. As shown in the GIF below, in the very last Add Prompt Instructions element, you may have one massive cumulative prompt like this.

Review of the final Add Prompt Instructions action in the debug details to show the cumulative prompt output variable in the prompt flow.

The contents of the Prompt variable are passed from our prompt flow into our prompt template. In other words, that’s how we’re grounding the prompt with data.

After the prompt flow is tested, it’s ready for use so we activate the flow.

Then, back in the prompt template you want the flow to be called, you select the flow from the Resource Picker > Flow.

Depicts how to select the flow in the resource picker to add into the prompt template to ground it with data using Flow Builder.

Pro tips

  • Activate your prompt flow. Otherwise, it will not appear in the resource picker in Prompt Builder.
  • Refresh Prompt Builder. If you’re in Prompt Builder before you activated the prompt flow, you’ll need to navigate out of the prompt template and open it again in order for that new flow to show in the resource picker.

Design impactful prompt template actions for your agents

Agents are the way of the future, working together with humans to drive success in the AI era. Your expertise in prompt and flow building will prime you for success, making the creation of prompt template actions an absolute breeze. Once you’ve built your prompt grounded with data from your flow, creating a prompt template agent action is really straightforward!

Just navigate to your agent in Agent Builder, choose the relevant topic, go to This Topic’s Actions, and from the action dropdown, select New > Prompt Template. Choose the prompt as the reference action, then review and update the instruction fields as needed and set your inputs and outputs accordingly, ensuring at least one output is set to ‘Show in conversation’.

Once you’ve added the prompt template agent action, it becomes available in the asset library for reuse across other agents in your Salesforce org. That's what we call working smarter, not harder. And I'm all for that.

How to create a new prompt template agent action in Agent Builder.

Try this at home

I’m sure you can think of examples of how you can flex those Flow skills by building prompt flows to further enrich your prompts with data. Share your creative use cases on social, and don’t forget to tag us or use #AwesomeAdmin. We can’t wait to see what you’ve built!

Resources

Want to see more good stuff? Subscribe to our channel!

SUBSCRIBE TODAY
Gillian Bruce returns to the Salesforce Admins Podcast to discuss Agentforce and Slack.

Gillian Is Back to Talk Agentforce And Slack!

Today on the Salesforce Admins Podcast, we talk to Gillian Bruce, Director of Developer Marketing at Slack. Join us as we chat about how Agentforce allows you to bring Salesforce to Slack, and why every admin should learn how to build Slack solutions. You should subscribe for the full episode, but here are a few […]

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