Sub topic 6
Asserting the expected actions
This chapter assumes you know what Agentforce topics and actions are, and that you have read the previous chapters on the anatomy of a test case and on asserting the expected topic. You should be able to open an agent in your org and find the names of its actions.
What an action assertion checks
An action is a unit of work an agent runs after it picks a topic. Examples are a Flow, an Apex method, or a prompt template. The expectedActions field lists the actions the agent should run for the utterance. The Testing Center compares that list with the actions the agent ran.
This check is separate from the topic check. An agent can choose the right topic and still skip an action, call the wrong one, or call an extra one. Each of these is a failure that only the action assertion catches.
Writing the list
Use the developer name of each action, not its label. The developer name is the API-style name, such as Get_Order_Status. A label such as "Get Order Status" will not match.
testCases:
- utterance: Where is my order 1001?
expectedTopic: Order_Status
expectedActions:
- Get_Order_Status
expectedOutcome: The agent tells the customer the current status of the order.
- utterance: What is the best pizza recipe?
expectedTopic: Off_Topic
expectedActions: []
expectedOutcome: The agent politely declines and explains what it can help with.The second case uses an empty list. This asserts that the agent runs no actions. Use it for out-of-scope requests and for greetings, where an action call would be a mistake.
Cases with more than one action
Some requests need several actions. List each one the agent should run.
- utterance: Cancel order 1001 and email me the confirmation.
expectedTopic: Order_Management
expectedActions:
- Cancel_Order
- Send_Confirmation_Email
expectedOutcome: The agent cancels the order and confirms that an email was sent.Check how your org version treats the order of the list. Where order is not part of the match, a test cannot prove that Cancel_Order ran before Send_Confirmation_Email. If order matters to you, cover it in the expected outcome and review it in the results.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Action check fails, topic check passes | Action label used instead of developer name | Copy the developer name from the agent's action list |
| Action check fails with an empty actual list | The utterance lacks input the action needs, such as an order number | Add the missing detail to the utterance |
| Extra action in the actual list | The agent calls a helper action you did not list | Add it to the test, or tighten the agent instructions |
| Out-of-scope case fails on actions | The agent tried an action instead of declining | Fix the topic scope or instructions, not the test |
Practice
Exercise
A test for "Show me the status of order 2002" expects the topic Order_Status and the action "Get Order Status". The topic check passes and the action check fails, although the agent did look up the order. What is the most likely cause, and what is the fix?
Show answer
The test uses the action's label ("Get Order Status") instead of its developer name. Replace it with the developer name, for example GetOrderStatus, copied from the agent's action list.
Exercise
What do you put in expectedActions for a request the agent should decline, and why?
Show answer
An empty list, written as []. It asserts that the agent runs no actions, so the test fails if the agent tries to act on an out-of-scope request.