Sub topic 11
Telling the agent when and how to use an action
This chapter assumes you know what a topic is, how a topic's classification description and scope work, and what an action is. It also assumes you have seen action inputs and outputs and can read basic Apex or Flow. Here you will learn how to write instructions that tell the agent when to call an action, how to fill its inputs, and what to do with its result.
Why an action needs instructions
An action can exist in a topic without being used well. The agent reads the action's name and description and decides, from the conversation, whether to call it. That is a guess unless your instructions narrow it down.
Instructions on a topic guide the agent's reasoning. For actions, they answer four questions:
- When should the agent call the action?
- Where does each input value come from?
- What should the agent do with each possible result?
- What must the agent never do with this action?
If the instructions leave one of these open, the agent fills the gap itself. Sometimes it guesses well. Often it does not, and the failure looks random from the outside.
Where the agent finds guidance
The agent draws on several pieces of text when it considers an action. Knowing which text does which job keeps you from putting guidance in the wrong place.
| Source | What it tells the agent | Typical content |
|---|---|---|
| Action name and description | What the action does | "Looks up the status of an order by its order number" |
| Input and output labels and descriptions | What each value means | "The order number the customer provided" |
| Topic instructions | When and how to use the action in this topic | "Use Get Order Status with that order number" |
| Topic scope | What the topic's job includes and excludes | "You cannot change or cancel orders" |
Put what is always true about the action in its description. Put what is true only in this topic's workflow in the topic instructions. An action can be reused in several topics, and each topic can then give it different handling.
Name the action in the instruction
Refer to the action by its exact label. The agent matches your words against the actions available in the topic, and a precise label removes doubt.
Compare these two instructions:
Check the order.Use the Get Order Status action with the order number the customer gave.The first could mean the action, a knowledge lookup, or just a reply. The second names one action and one input source. When you rename an action, update every instruction that mentions it. A stale name is a common cause of an action that is never called.
Say when to call it
A call condition is a statement about the conversation that makes the call appropriate. Write it as a condition the agent can check.
Good call conditions:
- "Once the customer has given an order number, use Get Order Status."
- "Only call Get Order Status after you have an order number."
- "If the customer asks about several orders, call the action once for each."
Weak call conditions:
- "Use the action when helpful."
- "Check the order when appropriate."
The weak versions leave the decision to the agent, which is what you were trying to avoid.
It also helps to state when not to call. If an action changes data, say what must happen first. For example: "Do not call Update Shipping Address until the customer has confirmed the new address."
Say where the inputs come from
Each input needs a source. There are usually three:
- The customer's message. The agent extracts the value from what they wrote.
- A question to the customer. The agent asks when the value is missing.
- Context the system already holds, such as the signed-in user or the case the conversation started from.
Write the source into the instruction. "Ask the customer for their order number if they have not given one" tells the agent to ask rather than invent a value. Without that line, an agent may pass an empty value or a guess to the action.
Two points matter for inputs:
- Required inputs. If an input is required, say how to collect it. If the agent cannot collect it, say what to do instead, for example transfer to a person.
- Format. If the action expects a specific format, such as an order number without a leading "#", say so. Do this in the input description when the rule always applies, and in the instruction when it applies only in this topic.
Say what to do with each result
Every action returns something, and each kind of result may need a different reply. Plan for the cases in the action itself, then write one instruction for each.
For the order lookup from the earlier code examples, the Apex method returns the status, or the text Not found. That gives two cases, and the instructions cover both:
1. Ask the customer for their order number if they have not given one.
2. Use the Get Order Status action with that order number.
3. If the action returns 'Not found', tell the customer you could not find the order and ask them to check the number.
4. Otherwise, state the status in one sentence.
5. Never share details about orders that belong to other customers.Step 3 handles the failure case. Step 4 handles success and limits the reply length. Step 5 is a rule that holds regardless of the result.
The instruction can only match values the action really returns. If step 3 says "if the order is missing" but the action returns Not found, the agent has to interpret. Quote the exact value when you can. This is also a reason to design actions with predictable outputs: a fixed set of status strings is easier to write instructions for than free text.
Handle errors and empty results
An action can also fail outright, for example from a Flow fault or a permissions error. Decide what the agent should say, and do not let it guess.
- Tell the agent not to claim success when the action did not succeed.
- Tell it what to offer instead, such as trying again or handing off to a person.
- Tell it not to show raw error text to customers.
An example:
If the action fails or returns no result, apologize briefly, do not guess the status, and offer to connect the customer with a support agent.Empty results are a separate case from errors. A lookup that finds nothing is a valid outcome, so give it its own instruction, as step 3 above does.
Order the steps
Instructions are read as a sequence, so order carries meaning. Put the input collection before the call, and the result handling after it. When a step depends on an earlier one, say so with words such as "after", "once", or "only if".
The diagram below shows the decision flow that the order lookup instructions describe.
Add guardrails for risky actions
Actions that change data or expose data need extra instructions. Instructions guide the agent, but they are not a security control. Enforce access in the action itself. The invocable Apex example does this by running its query WITH USER_MODE, so field and object permissions apply to the running user. The instruction "Never share details about orders that belong to other customers" is a second layer on top of that, not a replacement.
For actions that write data, consider these instructions:
- Require explicit confirmation from the customer before the call.
- Repeat the value being changed back to the customer first.
- Call the action once per confirmed request, not repeatedly.
Common mistakes
| Mistake | Effect | Fix |
|---|---|---|
| Instruction says "check the order" with no action name | The agent may not call the action | Use the action's exact label |
| No source given for a required input | The agent guesses or passes an empty value | Add "Ask the customer for..." |
| Only the success case is covered | Odd replies on `Not found` or failure | Write one step for each result |
| Instruction mentions a renamed action | The action is never called | Update instructions when you rename |
| Many actions with overlapping descriptions | The agent picks the wrong one | Make descriptions distinct and say when to use each |
| Safety rules only in instructions | Rules can be bypassed | Enforce in the action, restate in instructions |
Check it in Builder
After you write the instructions, test them with utterances that exercise each branch. For the order lookup, try these:
- A message with a valid order number.
- A message with no order number, to see whether the agent asks.
- A message with an order number that does not exist.
- A message asking about a refund, to confirm the topic scope keeps the agent out of this action.
Look at the reasoning and action details shown in the test view. Check that the agent chose the expected action, passed the expected input values, and applied the instruction for the result it received. If it did not, fix the instruction that covers that step before changing anything else.
Exercise
A topic has an action labeled Update Shipping Address. The instruction reads "Update the address when the customer wants a change." Name three problems with it and rewrite it.
Show answer
Problems: it does not name the action by label, it gives no source for the new address input, and it has no confirmation step or result handling. Rewrite: "1. Ask the customer for the order number and the new shipping address if they have not given them. 2. Repeat the new address back and ask the customer to confirm. 3. Only after the customer confirms, use the Update Shipping Address action with the order number and the confirmed address. 4. If the action succeeds, tell the customer the address was updated in one sentence. 5. If it fails, do not say the address was changed, and offer to connect the customer with a support agent."
Exercise
An Apex action returns the string 'Not found' when no record matches. Your instruction says "If the order does not exist, apologize." The agent sometimes reports 'Not found' as if it were a status. What change fixes this, and why?
Show answer
Quote the exact returned value: "If the action returns 'Not found', tell the customer you could not find the order and ask them to check the number." The agent must connect the instruction to the literal output. A vague condition like "does not exist" forces it to interpret, and it may treat the string as an ordinary status.