Sub topic 5
Instructions and Scope Inside a Topic
This chapter assumes you know basic Salesforce concepts (objects, records, Setup). It also assumes you have a high-level familiarity with Flow or Apex and a general idea of what a large language model (LLM) does. You should already know that a topic is one of an agent's areas of responsibility. This chapter covers the two fields that control behavior once a request has landed in a topic: the scope and the instructions.
Where scope and instructions sit
A topic has four parts that matter here:
- Classification description. Tells the agent which requests belong to this topic. It is read before the topic is chosen.
- Scope. States what the topic does and does not do. It is read after the topic is chosen.
- Instructions. Tell the agent how to behave inside the topic, step by step or rule by rule.
- Actions. The things the agent can run, such as a Flow or an Apex method.
The classification description decides whether the agent enters the topic. Scope and instructions decide what happens next. Mixing these up is the most common authoring mistake, and the sections below return to it.
Scope: the boundary of the topic
Scope is a short statement of what the topic covers and, just as important, what it excludes. Here is the example topic from the plan:
Topic: Order Support
Classification description: Handles customer questions about the status of an existing order, such as where it is or when it will arrive.
Scope: Look up order status and explain it. Does not process returns, refunds, or changes to an order.
Instructions:
- Ask for the order number if the customer has not given one.
- Use the order status action to look up the order before answering.
- If the order cannot be found, say so and do not guess.
Actions: Get Order StatusThe scope has two sentences. The first names the job. The second names three nearby jobs that are not this topic's job. Those exclusions matter because customers who ask about order status often follow up with "and can I return it?" Without an explicit exclusion, the agent has no signal that the follow-up is out of bounds, and it may try to improvise an answer from the actions or text it does have.
A good scope has these properties:
- It uses verbs that map to the actions attached to the topic ("look up", "explain").
- It lists the neighboring tasks that belong elsewhere.
- It is short enough to read in one pass. A paragraph of caveats dilutes the signal.
Scope does not enforce anything by itself. It is text the LLM reads, so it steers behavior but does not block it. If a task must never happen, do not attach an action that performs it, and enforce the rule in the action's own logic (a Flow or Apex method), not only in prose.
Instructions: how to behave inside the topic
Instructions are a list of directions the reasoning engine reads each time it decides what to do next in the topic. They work best when each one is a single, checkable rule. Compare the two versions below.
| Weak instruction | Stronger instruction |
|---|---|
| Be helpful with orders. | Ask for the order number if the customer has not given one. |
| Check things first. | Use the order status action to look up the order before answering. |
| Handle errors well. | If the order cannot be found, say so and do not guess. |
| Don't be wrong. | Quote the status exactly as the action returns it. |
The weak versions give the model nothing to act on. The stronger versions name a condition, an action or behavior, and an outcome.
What instructions are good for
- Sequencing. "Look up the order before answering" tells the agent to run the action first instead of replying from memory.
- Gathering inputs. "Ask for the order number" tells the agent to collect a missing value before it calls an action.
- Handling failure. "If the order cannot be found, say so" gives the agent a defined path when the action returns
Not Found. - Tone and format. "Reply in two sentences" or "Do not use the customer's first name" shape the final response.
What instructions are not good for
- Routing. Instructions are only read after the topic is chosen. Writing "if the customer asks about returns, hand off" here depends on the agent first landing in this topic. Put routing signals in classification descriptions.
- Guaranteed enforcement. An instruction is a strong hint to an LLM, not a rule engine. For anything involving money, permissions, or compliance, put the check in the action or in platform security (for example, sharing rules and
with sharingin Apex). - Documenting actions. What an action does and what it needs belong in the action's own label and descriptions, as in the Apex example later in this chapter.
How instructions and actions work together
Instructions refer to actions by what they do, so the wording needs to line up with the action's name and description. In the example, the instruction says "Use the order status action". The action is named Get Order Status, and its Apex description says it "looks up the current status of an order by its order number". A reader, human or model, can connect all three without guessing.
Here is the Apex action that backs the topic. The method and variable descriptions are the text the agent reads to decide whether to call it and what to pass in.
public with sharing class OrderStatusAction {
public class Request {
@InvocableVariable(label='Order Number' description='The order number the customer provided' required=true)
public String orderNumber;
}
public class Response {
@InvocableVariable(label='Status' description='Current status of the order, or Not Found')
public String status;
}
@InvocableMethod(label='Get Order Status' description='Looks up the current status of an order by its order number')
public static List<Response> getStatus(List<Request> requests) {
Set<String> orderNumbers = new Set<String>();
for (Request r : requests) {
orderNumbers.add(r.orderNumber);
}
Map<String, String> statusByNumber = new Map<String, String>();
for (Order o : [SELECT OrderNumber, Status FROM Order WHERE OrderNumber IN :orderNumbers]) {
statusByNumber.put(o.OrderNumber, o.Status);
}
List<Response> results = new List<Response>();
for (Request r : requests) {
Response res = new Response();
res.status = statusByNumber.containsKey(r.orderNumber) ? statusByNumber.get(r.orderNumber) : 'Not Found';
results.add(res);
}
return results;
}
}Notice how the pieces connect:
- The
required=trueflag onorderNumberbacks the instruction "Ask for the order number". The agent knows it cannot call the action without that value. - The
Not Foundstring in the response backs the instruction "If the order cannot be found, say so". The action returns a predictable value, so the instruction can refer to it. - The
with sharingkeyword means the lookup respects the running user's record access. This is enforcement in code, which no instruction can replace.
Common errors
- Putting routing logic in instructions. Symptom: requests never reach the topic, or reach the wrong one. Fix: rewrite the classification description so it distinguishes this topic from its neighbors.
- A scope with no exclusions. Symptom: the agent drifts into adjacent tasks, such as promising a refund. Fix: add a "Does not..." sentence naming the nearby jobs.
- Vague instructions. Symptom: behavior varies between runs. Fix: rewrite each as a condition plus a concrete behavior.
- Contradicting instructions. Symptom: the agent alternates between two behaviors, such as "Always ask for the order number" and "Answer immediately if the customer seems upset". Fix: remove one or state which wins and when.
- Instructions that name an action that is not attached. Symptom: the agent says it will look something up but cannot, or invents an answer. Fix: confirm that every action mentioned in the instructions is in the topic's action list.
- Too many instructions. Symptom: later rules are ignored. Long lists compete for the model's attention. Fix: keep instructions to the rules that change behavior, and move detail into action descriptions.
- Relying on prose for hard limits. Symptom: an edge case slips through. Fix: enforce the limit in the Flow or Apex logic and in permissions.
A practical editing loop
- Write the scope first, including at least one exclusion.
- Write one instruction per behavior you want to see, in plain imperative sentences.
- Run a handful of test requests that should work, and a few that sit just outside the scope, such as asking for a refund in Order Support.
- For each surprising result, decide whether the cause was routing (fix the classification description), boundary (fix the scope), behavior (fix an instruction), or action wording (fix the action's descriptions).
- Change one thing at a time and retest, so you can tell which edit helped.
Exercise
A customer in the Order Support topic asks, "Can you refund this order?" The agent promises a refund even though no refund action exists. Which topic fields would you edit first, and what would you add?
Show answer
Edit the scope first, making sure it states that the topic does not process returns, refunds, or changes to an order (the example already does, so check that it is present and worded plainly). Then add an instruction such as "If the customer asks for something outside this topic's scope, say you cannot help with it here and do not promise an outcome." If refund requests should go to a different topic, also check that topic's classification description so the request is routed there. Do not rely on prose alone for refunds: keep any refund logic in an action with its own checks.
Exercise
Rewrite the weak instruction "Handle missing orders well" so that it is a single, checkable rule that matches the Apex action above.
Show answer
"If the Get Order Status action returns Not Found, tell the customer the order could not be found and ask them to check the order number. Do not guess a status." This names the condition (the action returns Not Found), the behavior (say so and ask for a recheck), and a prohibition (no guessing).