Sub topic 1
Why Agents Need a Different Kind of Testing
Prerequisites
Assume basic familiarity with Agentforce agents, topics, and actions. You also need access to a Salesforce org with Agentforce and the Testing Center enabled.
Why Agents Need a Different Kind of Testing
A unit test checks a small, predictable piece of code. It might verify that a function returns 42 for a given input. An Agentforce agent is different. It interprets natural-language requests, selects a topic, follows instructions, and may call actions that depend on changing data.
The same request can sometimes produce different wording while still being correct. A useful test therefore checks the agent's behavior and decisions, not only an exact text string.
Agent tests should verify:
- The agent recognizes the user's intent.
- The agent selects the correct topic.
- The agent calls the right actions.
- The response meets the expected business outcome.
- The agent refuses or redirects requests outside its scope.
What You Are Testing
An agent's main building blocks have different responsibilities:
| Building block | What it controls |
|---|---|
| Topic | The area of work selected for the request |
| Action | The operation performed, such as retrieving an order |
| Instructions | The rules that guide selection, execution, and responses |
A failure can occur at any layer. For example, the agent might choose Order_Status correctly but fail to call Get_Order_Status. It might call the action and still give an incomplete response because its instructions are unclear.
What the Testing Center Does
The Testing Center runs defined utterances against an agent and compares the observed behavior with your expectations. It reports results for each test case so you can inspect routing, action use, and the final outcome.
> callout note > Test behavior that matters to the user. Avoid requiring one exact sentence when several responses satisfy the same outcome.
Anatomy of a Test Case
A test case pairs an utterance with three assertions:
testCases:
- utterance: Where is my order 1001?
expectedTopic: Order_Status
expectedActions:
- Get_Order_Status
expectedOutcome: The agent tells the customer the current order status.The utterance is the input. The expected topic checks routing. Expected actions check the agent's operations. The expected outcome describes the result the user should receive.
Asserting the Expected Topic
Use the expected topic to verify intent classification. Choose the topic that should own the request, even when the wording is informal or incomplete. Include variations such as “Track order 1001” and “Has my package shipped?”
A topic assertion fails when the agent routes the request to the wrong topic or cannot identify a suitable topic. Review the topic description, scope, and neighboring topics before changing the test.
Exercise
An utterance asks for a pizza recipe, but the agent routes it to Order_Status. Which assertion failed?
Show answer
The expected topic assertion failed. The request should route to an out-of-scope topic or receive the agent's defined out-of-scope response.