Sub topic 9
How the Agent Chooses an Action
This chapter assumes you know what a topic is, how a request is matched to a topic, and that actions are things like Flow, Apex, or prompt templates. Here we look at what happens after the topic is chosen: how the agent picks one action from that topic's list.
What the model sees
Once the reasoning engine has selected a topic, it builds a prompt for the large language model (LLM). The prompt contains:
- The topic's scope and instructions.
- The list of actions in that topic, each with its name and description.
- The inputs each action needs, with their descriptions.
- The conversation so far and any variables that hold values.
The model does not see your Flow or Apex code. It sees only the text you wrote. If that text is vague, the choice will be vague too.
The decision steps
The model decides in a loop, one step at a time.
- Read the latest request in light of the topic instructions.
- Compare the request to the description of each action in the topic.
- Check whether every required input is available from the conversation or a variable.
- If an input is missing, ask the user for it. If all inputs are present, call the action.
- Read the action's result and decide whether to call another action or answer.
Instructions steer the choice
Instructions can tell the agent the order of steps or the condition for using an action. Using the Order Support topic from earlier:
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.The second line ties the answer to the action. The agent should not reply from memory when a lookup exists. The third line covers the result "Not Found", which the Apex action returns as a status string.
Descriptions the model reads
In the Apex example, the label and descriptions are the text used for the decision.
@InvocableMethod(label='Get Order Status' description='Looks up the current status of an order by its order number')@InvocableVariable(label='Order Number' description='The order number the customer provided' required=true)
public String orderNumber;The method description tells the model when the action applies. The variable description tells it what value to extract from the conversation. The required=true flag means the agent must have this value before it calls the action.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Wrong action runs | Two actions have overlapping descriptions | Rewrite each description to state what it does and what it does not do |
| Action never runs | Description uses internal jargon the customer never says | Describe it in terms of the user's request |
| Agent asks for the same input twice | Input description is unclear, or the value is not stored in a variable | Clarify the input description and map it to a variable |
| Agent answers without calling an action | Instructions do not require the lookup | Add an instruction such as "Use the action before answering" |
| Action called with a guessed value | Input is optional | Mark it required so the agent asks first |
Checking the choice
When an agent picks the wrong action, test the same request in the Agent Builder test panel and look at the trace of the reasoning steps. Compare the descriptions it had available with what you intended. Change one description at a time and run the request again.
Exercise
An agent has two actions in one topic: "Get Order Status" and "Get Order Details". Both are described as "Gets information about an order". Customers asking where their package is sometimes get the wrong result. What should you change, and why?
Show answer
Rewrite the descriptions so they differ. For example, "Get Order Status: looks up whether an order is processing, shipped, or delivered, and when it will arrive" and "Get Order Details: returns the items, quantities, and prices on an order". The model compares the request to action descriptions. When two descriptions say nearly the same thing, it has no basis for a reliable choice. You can also add an instruction such as "For questions about where an order is, use Get Order Status".