Sub topic 7
Referencing Actions and Stating When to Use Them
Prerequisites
This chapter assumes you can do the following:
- Open Agentforce Builder and preview a conversation.
- Describe what an Agentforce topic is and what its classification description, scope, and instructions do.
- Recognize an action as a capability the agent can run, such as a Flow, an Apex method, or a prompt template.
Earlier chapters covered how to write clear, ordered, testable instructions. This chapter covers the part of those instructions that connects wording to behavior: naming an action and saying exactly when it should run.
Why instructions need to mention actions
A topic's actions are the only way the agent can read or change data in your org. Without them, it can only talk. The agent decides on each turn whether to call an action, which one, and with what inputs. It makes that decision from the conversation, the topic's instructions, and each action's own name and description.
If your instructions never mention an action, the agent has to guess from the action's description alone. That works for simple cases. It becomes unreliable in these situations:
- Two actions look similar.
- An action should run only after another one succeeds.
- An action should run only under certain conditions.
- The agent must pass specific values as inputs.
Naming the action and stating its trigger turns each of these guesses into a rule you can test.
The shape of an action reference
A reliable reference has four parts:
- Condition. What must be true in the conversation.
- Action. The exact name of the action to run.
- Inputs. Where each required value comes from.
- Next step. What the agent does with the result, including when the action fails or returns nothing.
Here is a minimal version of the first two parts:
If the customer asks for the status of an order, use the Get Order Status action with the order number.The condition is "asks for the status of an order." The action is "Get Order Status." The input is "the order number." This is a good start, but it does not say what happens if the customer has not given an order number, or if the lookup finds nothing. A fuller version fills in those gaps:
1. If the customer asks about an order and has not given an order number, ask for it before doing anything else.
2. Once you have the order number, use the Get Order Status action with that number.
3. Give the current status and the expected delivery date in one or two sentences.
4. If Get Order Status returns no order, say that you could not find it and ask the customer to check the number. Do not guess a status.Each line pairs one condition with one expected behavior. You can check each line in a test conversation and see whether the agent followed it.
Use the exact action name
Use the action's name as it appears in Agentforce Builder. "Get Order Status" is a hypothetical name used in this tutorial. In your own topic, copy the real name from the action list.
Three habits help:
- Copy, don't retype. A small difference such as "Order Status Lookup" versus "Get Order Status" gives the agent two names for one thing, or one name that matches nothing.
- Keep one name per action. Don't call it "the lookup" in one sentence and "the order tool" in the next.
- Recheck after renaming. If you rename an action or swap it for a different one, search your instructions for the old name. Instructions that point to a name that no longer exists fail quietly. Nothing warns you. The agent just behaves differently.
Only reference actions the topic has
An instruction can only use an action that is assigned to that topic. If your instruction says "use Create Return" but that action belongs to a different topic, the agent cannot call it here. At best it ignores the line. At worst it makes up a plausible answer.
Check this in two places:
- The topic's action list contains every action named in the instructions.
- Every action in the list is needed by the topic's scope. If an action doesn't fit the scope, the topic is probably covering too much. See the chapter on keeping neighboring topics distinct.
This also gives you a clean way to express a refusal. If a request belongs to another topic, the instruction should say what to tell the customer. It should not point to an action the topic doesn't have:
If the customer asks to return an item, tell them you can't process returns in this topic and offer to transfer them to a human agent.State conditions as observable facts
A condition is only useful if you can tell, from the conversation, whether it is true. Compare these pairs:
| Vague condition | Observable condition |
|---|---|
| If the customer seems to have an order problem | If the customer says the order has not arrived after the expected delivery date |
| When appropriate, look up the account | When the customer gives an email address or account number, look up the account |
| If the request is urgent | If the customer says the order is for an event within three days |
The right-hand versions name something the customer says or something a previous action returned. You can write a test utterance that makes each one true or false. The left-hand versions leave the decision to the agent's judgment, and judgment varies between runs.
Conditions can also depend on action output. For example:
If Get Order Status shows the order as Delivered but the customer says they did not receive it, tell them you will transfer them to a human agent.Here the condition refers to a value that the action returned. This is stronger than a condition based on how the customer sounds.
Say where inputs come from
Most actions need inputs. For each required input, an instruction should state one of three things:
- The customer provides it. "Ask the customer for their order number."
- A previous step provides it. "Use the order ID returned by Find Order."
- It is fixed or derived. "Always set the channel to Chat."
If you don't say, the agent may ask the customer for something it already has. It may also fill an input with a guess. Missing inputs are a common cause of actions that run with wrong values or never run.
Ask only for what the action needs. If the action needs an order number, don't also require the customer's email unless the action takes it. Extra questions slow the conversation and add places for it to stall.
Order dependent actions
When one action depends on another, write the sequence explicitly and put the dependency in the condition.
1. Use Find Customer with the customer's email address.
2. Only after Find Customer returns a customer, use List Open Orders with that customer's ID.
3. If the customer has more than one open order, ask which one they mean before using Get Order Status.Step 2 says "only after." Step 3 gives the agent a reason to pause and ask. Without the sequence, the agent may call the second action first, with an empty input.
The flow below shows the decisions this kind of instruction set describes.
If you can draw an instruction set as a flowchart like this, every branch is a line you can test. If you can't, the instructions are probably missing a case.
Handle failure and empty results
Actions fail or return nothing more often than authors expect. A record may not exist, a callout may time out, or a Flow may return an error. If the instructions don't say what to do, the agent improvises. Improvisation sometimes means inventing an answer.
Add at least one line for each action that covers the case where it returns nothing or fails:
- State what to tell the customer.
- State whether to retry, ask for different input, or hand off.
- Forbid guessing when the answer matters: "Do not guess a status."
When an instruction is the wrong tool
Referencing an action tells the agent to run it. It does not make the agent run it every time, in the same way, with the same checks. Instructions are followed by a language model, so wording guides behavior but does not guarantee it.
Move a rule out of the instructions and into the action when it must hold every time. Examples:
- A refund must never exceed the order total.
- A discount requires manager approval above a threshold.
- A record must be validated before it is updated.
Put those checks inside a Flow or an Apex action, so the action itself rejects invalid requests. Then the instruction only needs to say when to call the action and what to tell the customer when it declines. The later chapter on deterministic logic covers this decision in detail.
Common mistakes with action references
- A vague trigger. "Use the order action when needed" gives the agent no criterion. Name the customer request that triggers it.
- A paraphrased name. The agent may treat "the lookup" as a different thing from the action.
- Two actions for one condition. If two lines both apply to "the customer asks about an order," the agent has to pick one. State which runs first or which one covers which case.
- No result handling. The instruction ends at "use the action," so the agent makes up what to do next.
- Rules that belong in logic. A long list of "never do X unless Y" lines about data values is a sign the action should enforce them.
- An action that isn't assigned. The instruction names something the topic cannot call.
Test each reference
For each action reference, write at least three test utterances in the Builder preview:
- The normal case. The customer gives everything the action needs.
- A missing input. The customer asks the question without the order number.
- A failure or lookalike. The lookup returns nothing, or the customer asks for something close but out of scope, such as a return.
Then open the details of the preview conversation and check which action ran, with which inputs, and in what order. The reply text alone can hide a skipped action. If the agent called the wrong action or used a wrong input, change one line of the instruction and run the same utterances again. Changing one line at a time shows which edit caused which change.
Exercise
A topic has the instruction "Look up the order when the customer needs help." It has actions named Find Order and Get Order Status. Rewrite it as an instruction that names the actions, states the conditions, says where the input comes from, and covers an empty result. Use an order number as the input.
Show answer
One acceptable version: 1. If the customer asks about an order and has not given an order number, ask for it. 2. Once you have the order number, use the Find Order action with that number. 3. Only after Find Order returns an order, use the Get Order Status action with the order ID it returned. 4. Give the status and expected delivery date in one or two sentences. 5. If Find Order returns no order, say you could not find it and ask the customer to check the number. Do not guess a status. This version names both actions exactly, states the condition for each, says where each input comes from, orders the two calls, and handles the empty result.
Exercise
An instruction says "Issue refunds up to $50 without approval and require approval above that." Should this rule live in the instruction wording, or somewhere else? Explain what you would write in the instruction instead.
Show answer
The limit should be enforced in a Flow or Apex action, because it must hold every time and wording alone cannot guarantee that. The action should reject or route to approval any refund above $50. The instruction then only says when to call the action, for example "If the customer's order arrived damaged, use the Issue Refund action with the order number and amount," and what to say if the action declines, for example "If Issue Refund says approval is required, tell the customer a human agent will review the request."