Sub topic 5
Required Inputs and Asking the User
This chapter assumes you know what an Agentforce agent, topic, and action are. It also assumes you can read Apex or Flow variables and have used Agentforce Builder. Here you will learn how the "required" setting on an input changes the agent's behavior, and how to write descriptions that make the agent ask the user for a missing value instead of guessing.
What "required" means to the agent
The agent's language model reads each input's label, description, and required setting. If an input is required and the conversation does not contain a value, the agent should ask the user before it calls the action. If an input is optional, the agent may call the action without it.
"Required" is a signal to the model. It is not a guarantee. A required input with a weak description can still be filled with a guessed value. The description is what tells the agent where the value comes from.
Deciding which inputs are required
Mark an input required when the action cannot do its job without it. Leave it optional when the action can run with a sensible default or when the value only narrows the result.
| Input | Setting | Reason |
|---|---|---|
| Order Number | Required | The lookup has nothing to search on without it. |
| Include Cancelled Orders | Optional | The action can default to false. |
| Customer Email | Optional | Only used to double-check ownership when provided. |
Too many required inputs make the agent interrogate the user. Ask only for what the action truly needs. If the system can find a value itself, such as the current user's Id, do not make the agent collect it.
Writing descriptions that trigger a question
A good description for a required input does three things:
- It says what the value is, in the user's words.
- It gives an example of the format.
- It says what to do if the value is missing.
Compare these two.
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.The weak version gives the model nothing to work with. It may invent an Id or pull a number from an unrelated part of the conversation. The stronger version names the source (the customer), shows the format, and gives an explicit instruction for the missing case.
Required inputs in Apex
In an invocable method, set required=true on the @InvocableVariable and put the ask-the-user instruction in the description.
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;
}
}In a Flow, the equivalent is an input variable with "Available for input" selected and a description entered in the variable's Description field. Configure whether the input is required on the action in Agentforce Builder.
Collect or infer?
Some values the agent can take from the conversation, and some it must ask for. Your description should say which.
- Collect from the user: values only the user knows, such as an order number or a preferred date. Say "Ask the customer if not provided."
- Infer from context: values already in the conversation, such as an account the user mentioned earlier. Say "Use the account discussed earlier in the conversation."
- Do not ask at all: values the system can supply. Fill these in your Apex or Flow logic instead of exposing them as inputs.
Common errors
- A required input with a vague description. The agent guesses. Add the source, an example, and "Do not guess."
- Marking everything required. The agent asks too many questions. Make inputs optional when a default works.
- Exposing an input the system could fill. The agent asks the user for something they do not know. Compute it inside the action.
- Asking for several values in a confusing way. Keep each description about one value, so the agent can ask for it plainly.
Exercise
An action has a required input labeled "Id" with the description "The id". In testing, the agent calls the action with an Id it made up. What two changes to the input would you make?
Show answer
Rename the label to say what the value is, such as "Case Number", and rewrite the description to name its source, give a format example, and tell the agent to ask the user if it is missing and not to guess. For example: "The case number the customer provided, for example 00001234. Ask the customer if it was not given. Do not guess."
Exercise
A "Get Order Status" action needs the current user's Id to check access. Should that be a required input the agent asks for? Why or why not?
Show answer
No. The user does not know their Id, and the system can supply it. Read it inside the Apex or Flow logic, for example with UserInfo.getUserId(), and leave it out of the inputs.