Sub topic 11
Action inputs, variables, and conversation context
This chapter assumes you know what topics, instructions, and actions are, and that you have read how the agent chooses an action. Here you will see where the values an action needs come from, and how the agent keeps track of them during a conversation.
Why inputs matter
An action is only useful if it receives the right values. The "Get Order Status" action needs an order number. The agent has to find that value, pass it in, and then use the result in its reply. This is where inputs, variables, and conversation context come in.
Action inputs and outputs
Each action declares inputs and outputs. For an Apex invocable action, the inputs are the fields on the request class marked with @InvocableVariable. The outputs are the fields on the response class.
The agent does not see your code. It reads the label and description of each variable. In the order status example, the input is labeled "Order Number" with the description "The order number the customer provided". That text tells the agent what to look for in the conversation.
public class Request {
@InvocableVariable(label='Order Number' description='The order number the customer provided' required=true)
public String orderNumber;
}Two settings affect how the agent treats an input:
- Required. If an input is required and the agent has no value for it, the agent asks the customer before it runs the action.
- Collect from user. The agent may ask for the value in conversation, or it may fill the input from a variable it already holds.
Where input values come from
The agent can fill an input from several places:
- The customer's latest message, for example "Where is order 10045?"
- Earlier messages in the same conversation.
- A variable that holds a value saved earlier.
- The output of a previous action in the same turn.
The topic instruction "Ask for the order number if the customer has not given one" covers the case where none of these sources has a value.
Variables
A variable stores a value for the length of the conversation. There are two common kinds:
| Kind | Who sets it | Typical use |
|---|---|---|
| Context variable | The channel or session, before the conversation starts | The signed-in user's ID or the related record ID |
| Custom variable | An action output or the agent itself | An order number the customer gave, or a status the agent looked up |
Variables help in two ways. The agent does not need to ask again for something it already knows. Actions can also hand values to each other. If one action returns a case ID, a second action can take that ID as input without the customer repeating it.
Conversation context
The agent also carries the conversation history. This lets it handle follow-ups.
- Customer: "Where is order 10045?"
- Agent: "It shipped yesterday."
- Customer: "And can you check 10046?"
For the last message, the agent knows the topic is still order support and that "check" means look up a status. It does not need a new topic match.
History has limits. A long conversation may not keep every detail in view. If a value must be reliable later, store it in a variable instead of relying on the agent to recall it from the text.
Common errors
- Vague input descriptions. A description like "The ID" gives the agent nothing to match. Say which ID and where it comes from.
- Wrong data type. If the input expects a record ID and the customer gives an order number, the action fails or returns nothing. Name the expected format in the description.
- Missing required input handling. If the topic instructions never tell the agent to ask, it may guess. Add an instruction to ask, and never to guess.
- Relying on memory. Important values that are not stored in a variable can be lost in a long conversation.
Exercise
A customer gives an order number in their first message. Ten messages later, the agent asks for it again. Name one change that could prevent this.
Show answer
Store the order number in a custom variable when the customer first gives it, and let the action inputs read from that variable. The agent then does not depend on recalling the number from a long conversation history.
Exercise
An action input is described only as "The ID". Why is this a problem, and how would you fix it?
Show answer
The agent uses the description to decide what value to pass, and "The ID" does not say which ID. Rewrite it to be specific, for example "The order number the customer provided, such as 10045".