Salesforce Agent Script Guide: Balancing AI Conversation with Business Logic
Dec 10, 2025
Show More Show Less
View Video Transcript
0:07
Hello everyone. In this video we are
0:10
going to see Salesforce agent force
0:13
agent script with the help of uh new
0:17
Salesforce agent force agent script. We
0:20
will be able to build predictable
0:23
workflows for your business process.
0:27
With the previous uh agent force uh
0:30
builder, we were able to define topics
0:33
and instructions.
0:36
In the topics, we were able to add uh
0:39
standard and custom actions.
0:42
It was nondeterministic.
0:45
It means that
0:47
we won't have the same output whenever
0:50
we give the same input.
0:54
But with the help of new agent force
0:57
agent script, we will be able to define
1:00
predictable paths so that the agent
1:02
force agent can follow
1:06
and help in assisting the customers.
1:13
The agent force agent script gives uh
1:17
flexibility and consistency
1:21
with the help of uh the programmatic
1:24
approach to define the agent.
1:28
We will be able to
1:31
give deterministic nature to the agent
1:34
force agent responses.
1:40
In order to build agent force agents
1:43
using agent script instead of directly
1:46
diving deep into the development
1:49
we should understand the basics of it.
1:54
The first
1:57
basic uh
1:59
information I'm going to share is the at
2:03
symbol.
2:05
In agent force agent, we will be
2:08
defining topics, actions, context
2:10
variables and also
2:13
we will be able to configure the output
2:15
variables from the agent force actions.
2:21
If I wanted to refer an action then I
2:23
have to make use of atactions dot the
2:26
action name. If I want to reference a
2:30
topic then I have to make use of at
2:32
topic dot topic API name. Similarly for
2:36
the context variables I have to use at
2:39
variables dot the API name of the
2:41
variable. In order to refer the output
2:44
from the agent force agent action I have
2:47
to make use of atoutputs dot the output
2:50
variable name.
2:54
With the help of this uh at symbol, I
2:56
will be able to chain
2:59
actions and as well as topics,
3:05
logic and prompts.
3:07
If you wanted to define some
3:09
instructions based on the logic, then
3:11
you can make use of this arrow hyphen
3:14
followed by greater than symbol. If you
3:17
wanted to define multiple instructions
3:20
that is the prompt in multiple lines
3:24
then you can make use of this pipe
3:26
symbol.
3:29
Let's say you wanted to run an action
3:31
then you can make use of run keyword.
3:35
Let's say you wanted to provide some
3:37
inputs to the action then you can make
3:39
use of with keyword. You can make use of
3:43
uh this symbol
3:45
to define commands.
3:49
The commands will be very helpful so
3:51
that any other developer, admin,
3:54
architect or even a business user looks
3:56
at it, they will be able to understand
3:59
it. Uh so in order to uh make it more
4:02
userfriendly, you can add comments.
4:06
The agent agent script supports
4:09
mathematical and comparison operators
4:11
also.
4:13
Mathematical operators like plus and
4:15
minus are currently supported. You can
4:18
also use these comparison operators for
4:21
equal to, not equal to, greater than and
4:23
less than. For null check, you have to
4:27
make use of is none and is not none.
4:33
There are several blocks when uh when
4:36
you define an agent using the new agent
4:39
script. I have divided that into or
4:42
categorize that into three blocks. Core
4:45
configuration blocks, data and logic
4:46
blocks and finally the topic block.
4:50
The topic block are the standard and uh
4:54
custom topics
4:56
in which you will be adding instructions
4:58
and as well as uh actions.
5:02
So that is the topic block. In the core
5:05
configuration blocks, we have config
5:07
where we will define the
5:09
agent name, agent label, the Einstein
5:13
user associated to this agent and a
5:15
description. In the language block, we
5:18
have to define the default language and
5:20
also you can define any additional
5:22
languages that the agent will support.
5:26
Connection block. In the connection
5:27
block, we will be defining the agent
5:31
how it will be connected to different
5:33
channels. So we can uh uh uh connect it
5:38
with enhanced chat, SMS, WhatsApp,
5:41
voice. Uh so like that you can define
5:44
the those connections in this connection
5:46
block.
5:48
Data and logic blocks. Here we have
5:50
variables block where we will define the
5:52
context variables. The very important
5:55
block is start agent block. This is the
5:57
first block that will be executed. So we
6:00
have to define the instructions properly
6:03
here so that it will find the right
6:05
topic and then it will
6:08
uh do the executions. Next is system
6:11
block. So here we will be uh defining
6:14
the welcome and error messages. So this
6:18
is how
6:23
it will be.
6:26
So we saw about system block, config
6:28
block, variables block, language block,
6:30
connection
6:32
block and uh this is a uh start agent
6:35
block. So this is the first uh topic the
6:38
agent force agent will uh execute uh
6:42
whenever a prompt is sent. And uh these
6:45
are all the standard topics. And uh I
6:47
created a um a custom topic called
6:50
flight cancellation. So whenever they
6:52
wanted to cancel a flight, they will say
6:54
cancel my trip. I wanted to cancel my
6:57
flight. It will find the right uh topic
7:00
and then it will execute this uh flight
7:02
uh uh cancellation topic here. Um uh let
7:06
me summarize it. So in this custom topic
7:09
what I have uh added as an instruction
7:11
is whenever they wanted to cancel a
7:14
flight or a trip uh it should uh ask for
7:17
booking reference number. Um if the
7:20
booking reference number is shared it
7:22
will be stored in
7:26
um
7:28
it will be stored in booking reference
7:30
number uh variable. So this is my
7:32
booking reference uh variable.
7:37
Next is uh
7:41
let me close this
7:43
and uh okay and uh once the booking
7:46
reference number is given I'm asking the
7:49
agent force agent to get the
7:54
booking details using get booking
7:57
details. It's an agent action with the
8:00
help of flow.
8:02
Next, if the booking retrieval is
8:04
succeeded, let's say the flow was able
8:06
to successfully retrieve the data
8:07
without any runtime error and with the
8:09
right booking information, then I am
8:12
instructing it to automatically proceed
8:15
to cancel the booking by running actions
8:17
dot
8:19
cancel booking. So, I I'm able to chain
8:22
it now. So, first it will retrieve the
8:24
booking. Once it is retrieved
8:25
successfully, I'm directly calling the
8:28
action cancel booking so that it will
8:31
cancel the booking. So here I'm making
8:33
use of an apex agent action to cancel
8:36
the booking. If there are any fail
8:39
failure then I'm asking the agent to um
8:45
redirect to escalation topic.
8:50
Yeah. So no no I'm not asking them to uh
8:53
change it to escalation topic. I'm
8:54
asking them to verify their booking
8:57
booking uh um uh reference number again.
9:00
If the booking reference number is again
9:02
shared and and then if they run into the
9:04
same runtime error or any other issue
9:06
then I'm giving an option to human agent
9:11
so that they can assist them. So this is
9:14
my instructions and actions.
9:22
The first request will always go to
9:25
start agent block. So we have to make
9:27
sure it is defined with the proper set
9:30
of instructions. In this case, what I
9:33
have done is I have made it very simple.
9:37
Um
9:39
this is the start agent. I have given
9:40
the name as topic selector. The
9:43
instruction is select the tool that best
9:45
matches the user's message and
9:47
conversation history. If it is unclear,
9:49
make your best guess. So this is in
9:51
instruction I have given so that it will
9:52
try to find the right topic so that they
9:56
will be able to uh get help from those
9:59
topics.
10:00
In order to uh preview it you can make
10:03
use of the preview tab here.
10:07
Uh I will say cancel my trip.
10:12
So it should call this flight
10:14
cancellation.
10:16
It says that it couldn't retrieve the
10:18
booking details and uh it needs a
10:20
reference number in order to get it. I
10:23
let me make use of this. So it is
10:25
already cancelled. Let me change it to
10:27
booked.
10:29
And this is the booking reference
10:31
number. So I'm going to give this
10:33
booking reference number.
10:39
Since I have changed the actions, first
10:41
it will get the booking details. Next,
10:44
it should call the Apex and uh cancel
10:47
it. So, it says that it was able to find
10:49
the booking. Uh the destination is
10:51
Toronto and the uh sorry, the source is
10:54
Toronto and the destination is
10:56
Vancouver.
10:58
And then it successfully canceled by
11:00
invoking the cancel booking action. So,
11:03
let's verify that. Yeah, it canled it.
11:08
Okay.
11:11
So we talked about the connection block.
11:14
So this is the connection block. I'm
11:16
able to connect enhanced chat here. This
11:19
is the flow which will be invoked um
11:24
uh so so that it will uh get routed to a
11:29
an agent whenever there is an escalation
11:31
in order to see let's change it to
11:34
canvas instead of script. So if I go to
11:37
canvas here I have I was able to select
11:40
the escalation flow. Uh if there are any
11:43
issues while chatting with the agent
11:45
force agent if they run into any uh
11:48
issues it will invoke this route to
11:49
messaging session Q omni channel flow
11:53
and then it will execute the flow and
11:55
then it will transfer it to a human
11:56
agent.
12:01
Okay. uh we have to click commit version
12:04
and then we have to activate the agent
12:07
force agent. If you run into any issues
12:10
make use of this agent force help ask
12:13
all the errors all the doubts whatever
12:17
issues or concerns you have. It will
12:19
definitely help you so that you will be
12:21
able to publish your agent force agent
12:23
without any issues. Once it is
12:26
successfully
12:28
activated, you can verify it from
12:32
agent force agents in the Salesforce
12:34
setup.
12:36
So this is the booking agent. In order
12:39
to connect it with your enhanced chat,
12:43
go to the messaging settings in
12:44
Salesforce setup. Select the messaging
12:48
channel.
12:50
In the routing type you can select agent
12:54
for service agent and select the agent.
13:01
You can also make use of omni channel
13:02
flow and in the omni channel flow you
13:04
should be able to use the route workflow
13:06
element and route it to the agent for
13:09
service agent.
13:12
Okay. In order to test it from the
13:17
enhanced chat, I'm going to the embedded
13:20
service deployment.
13:22
I'm going to test it.
13:25
Let me change it back to booked so that
13:28
I will be able to test it out.
13:36
Okay, I'm going to initiate a chat.
13:42
The agent force agent joined it sent the
13:46
welcome message from the system block.
13:48
Please cancel my trip.
14:00
Okay, it couldn't find any booking
14:02
details because I didn't give my booking
14:04
reference number. So, I'm giving my
14:06
booking reference number.
14:11
Now it should fetch my booking details
14:14
and as well as it should cancel my
14:16
booking.
14:18
Let's verify that.
14:21
Okay. So I'm able to see that the status
14:24
is canceled and then it was last
14:26
updated. Now
14:35
please check the video description. In
14:37
the video description I have shared my
14:39
blog post. from the blog post you should
14:42
be able to get this sample agent
14:44
definition for your reference.
14:48
In this uh sample agent definition
14:54
I have invoked
14:57
flow agent action and as well as apex
14:59
agent action. So you can make use of how
15:03
I have instruct I have I how I have made
15:06
use of agent script to give the
15:09
instruction and also
15:11
uh do the um
15:14
conditional uh checks so that it will
15:17
run only with only when the booking
15:21
reference detail is available. So for
15:22
example here
15:29
so this particular action
15:31
will get fired with booking reference
15:35
number
15:36
and it will be it is available only when
15:39
the variable dot booking reference is
15:41
not null. So if it is not none so if it
15:45
is not empty or null then only it will
15:47
be available else it won't be available
15:49
for the agent force agent to get
15:52
executed
15:55
or to execute this particular action.
16:00
I hope it was helpful.
16:06
Thank you for watching.
#Internet Software
