Sub topic 3
Names, Labels, and Descriptions the Agent Reads
This chapter assumes you know what an Agentforce agent, topic, and action are. It also assumes you can read Apex or Flow variables. Here you will learn which text the agent sees for an action, and how to write it so the agent picks the right action and fills the right values.
What the agent actually sees
The agent never reads your Apex code or your Flow logic. It reads metadata: the action's name, label, and description, plus the label, description, data type, and required flag of each input and output. The large language model uses that text to decide three things:
- Whether this action fits the customer's request.
- What value belongs in each input.
- How to describe each output to the customer.
If the text is vague, the agent guesses. A precise description is the cheapest way to improve agent behavior.
Where the text comes from
The source depends on the action target.
| Target | Action text | Input and output text |
|---|---|---|
| Apex | `label` and `description` on `@InvocableMethod` | `label` and `description` on each `@InvocableVariable` |
| Flow | Flow label and description | Label and description of each input or output variable |
You can also adjust the action's instructions in Agentforce Builder, but the underlying metadata is your starting point.
Action-level text: say when to call it
The action description has one main job: tell the agent when this action applies. Start with what the action does, then give the trigger.
- Weak:
Gets order info - Stronger:
Looks up the status of one order by its order number. Use when the customer asks where their order stands.
Use a verb-first label such as Get Order Status. Avoid labels that differ from a sibling action by only one word. If two actions both say "Looks up an order", the agent cannot tell them apart.
Input and output text: say what, with an example
A good input description covers four points: what the value is, an example, where it comes from, and what to do if it is missing. A good output description covers what the value means, its possible values, and what an empty value means.
Weak input description:
Label: Id
Description: The id
Stronger input description:
Label: Order Number
Description: The order number the customer provided, for example 00000101. Ask the customer if it was not given. Do not guess.
Weak output description:
Label: Result
Description: Output of the action
Stronger output description:
Label: Order Status
Description: Current status of the order, such as Draft or Activated. Empty if no order was found.A complete example
This Apex class applies those rules. Notice that the descriptions carry the guidance, and that the response includes a message for the not-found case.
public with sharing class GetOrderStatus {
public class Request {
@InvocableVariable(
label='Order Number'
description='The order number the customer provided, for example 00000101. Ask the customer if it was not given. Do not guess.'
required=true
)
public String orderNumber;
}
public class Response {
@InvocableVariable(
label='Order Status'
description='Current status of the order, such as Draft or Activated. Empty if no order was found.'
)
public String status;
@InvocableVariable(
label='Result Message'
description='A short plain-language message describing the outcome, including when no order matches the number.'
)
public String message;
}
@InvocableMethod(
label='Get Order Status'
description='Looks up the status of one order by its order number. Use when the customer asks where their order stands.'
)
public static List<Response> getStatus(List<Request> requests) {
Set<String> numbers = new Set<String>();
for (Request r : requests) {
numbers.add(r.orderNumber);
}
Map<String, Order> byNumber = new Map<String, Order>();
for (Order o : [SELECT OrderNumber, Status FROM Order WHERE OrderNumber IN :numbers WITH USER_MODE]) {
byNumber.put(o.OrderNumber, o);
}
List<Response> results = new List<Response>();
for (Request r : requests) {
Response res = new Response();
Order o = byNumber.get(r.orderNumber);
if (o == null) {
res.message = 'No order was found with number ' + r.orderNumber + '.';
} else {
res.status = o.Status;
res.message = 'Order ' + r.orderNumber + ' has status ' + o.Status + '.';
}
results.add(res);
}
return results;
}
}Common errors
- Generic labels. Names like
Id,Result, orOutputgive the agent nothing to match against the conversation. - Descriptions that repeat the label. "Order Number: the order number" adds no information. Add an example and a rule.
- Developer-only wording. Text such as "FK to Order__c" helps a developer but not the agent. Write in terms the customer would use.
- Overlapping actions. If two descriptions could match the same request, state the difference, such as "for one order" versus "for all orders in the last 30 days".
- Missing empty-result meaning. If the agent does not know that an empty status means "not found", it may report a blank value as a real answer.
Exercise
A Flow action has an input variable labeled "Id" with the description "The id". Rewrite the label and description so the agent knows what to collect for a case lookup. Include an example and a rule for a missing value.
Show answer
One good answer: Label "Case Number". Description "The case number the customer provided, for example 00001024. Ask the customer if it was not given. Do not guess." The label names the business concept, the example shows the format, and the last two sentences tell the agent how to handle a missing value.