Sub topic 2
What you are testing: topics, actions, and instructions
This chapter describes the three parts of an Agentforce agent that a test case checks. It also shows how the agent's reasoning loop links them. Later chapters assume you can name these parts and point to the one that caused a given behavior.
Prerequisites
This chapter assumes the following:
- You have built or opened an Agentforce agent in Agent Builder.
- You know that an agent receives a user message, which this tutorial calls an utterance.
- You can read a short YAML file.
You do not need to have written a test yet. The Testing Center is introduced in the next chapter.
The three building blocks
An Agentforce agent is configured, not coded line by line. Three kinds of configuration decide what it does with an utterance.
- A topic is a category of work the agent can handle, such as order status or returns. A topic has a name, a description, a scope, and its own instructions.
- An action is a task the agent can run, such as looking up an order. An action wraps a Flow, an Apex method, a prompt template, or another Salesforce capability. It takes inputs and returns outputs.
- Instructions are natural-language rules that tell the agent how to behave. Some apply to one topic. Others apply to the whole agent.
Each topic lists the actions available inside it. An action that is not assigned to a topic is not available when that topic is active. This containment is what makes tests useful, because you can state which topic should handle an utterance and which actions should run inside it.
| Part | What it answers | Where you configure it | What a test can check |
|---|---|---|---|
| Topic | Which kind of request is this? | Topic name, classification description, scope | Expected topic |
| Action | What does the agent do to get data or change something? | Actions assigned to a topic | Expected actions |
| Instructions | How should the agent behave and respond? | Topic instructions and agent-level instructions | Expected outcome |
How the agent reaches a response
The agent processes an utterance in a sequence. Knowing the sequence tells you where a failure can start.
- The agent reads the utterance and the conversation so far.
- The reasoning engine compares the utterance with the descriptions and scopes of the topics. It selects one topic.
- Inside that topic, the engine reads the topic instructions and the list of available actions.
- It decides whether to run an action. It may run more than one, and one action's output can feed another.
- It composes a reply that follows the instructions and uses the action results.
Three points in this flow produce observable results. The selected topic can be recorded. The actions that ran can be recorded. The final reply can be read. Those three results map directly to the three assertions in a test case.
Topics in detail
The topic decides which instructions and actions the agent can use for the turn. A wrong topic therefore causes most of the later failures. If an order question lands in a general FAQ topic, the order lookup action is not available, and the agent can only guess or deflect.
The engine chooses a topic mainly from the topic's classification description and scope. Write these as if you were briefing a new colleague on which requests belong to this topic and which do not.
Common topic problems:
- Overlapping descriptions. Two topics both claim "questions about orders". The engine may pick either one, and the choice can change between runs.
- Vague names and descriptions. A topic called "General" with the description "Help the customer" attracts everything.
- Missing out-of-scope handling. With no topic for requests you do not support, the engine looks for the closest match and may force an unrelated request into it.
When you write a test for topic selection, you are testing these descriptions, not the code behind the actions.
Actions in detail
An action is the only way the agent reads or changes data in your org. If the agent states an order status, that status should come from an action result. If it states one without running the action, it is guessing.
Each action has these parts:
- A name and a description. The engine uses the description to decide when the action fits.
- Inputs. The engine fills them from the utterance, the conversation, or earlier action output. Instructions can also tell it to ask the user for a missing value.
- Outputs. The engine reads these when it composes the reply.
Actions fail in two different ways, and you should keep them apart:
- Selection failures. The engine does not run an action it should have run, or runs the wrong one. This is a configuration problem in the action description, topic instructions, or topic assignment.
- Execution failures. The engine chose the right action, but the Flow or Apex behind it returned an error or wrong data. This is a defect in the action's implementation.
An expected-actions assertion checks selection. It tells you the right action ran. It does not tell you that the Flow behind it is correct. Test the Flow or Apex separately with the tools for that technology.
Instructions in detail
Instructions shape how the agent works inside a topic and how it phrases the reply. They can set order of steps, required checks, tone, and limits.
Topic: Order_Status
Instructions:
1. Ask for the order number if the customer has not given one.
2. Use the Get_Order_Status action with the order number.
3. Tell the customer the status in one or two sentences.
4. Never share another customer's order details.Instructions apply at two levels:
- Topic instructions apply only while that topic is active.
- Agent-level instructions apply in every topic.
Instructions are guidance for a language model, not program logic. The engine usually follows them but does not execute them the way code runs. A rule such as "always confirm before cancelling" can be followed in most runs and skipped in a few. This is why you check instruction-driven behavior with an expected outcome, and why you should expect to rerun and refine such tests.
Conflicting instructions are a common source of odd behavior. If an agent-level rule says "keep replies under two sentences" and a topic rule says "list every item in the order", the result depends on how the engine weighs them. Tests that fail only for long orders often point to this kind of conflict.
Mapping a failure to the part that caused it
Because each building block leaves a different trace, you can sort a wrong behavior by symptom.
| Symptom | Likely part | First thing to check |
|---|---|---|
| Request handled by an unrelated topic | Topic | Classification descriptions and scope of the competing topics |
| Right topic, action never runs | Action or instructions | Action description, assignment to the topic, and whether instructions mention it |
| Wrong action runs | Action | Overlapping action descriptions |
| Right action runs, reply is wrong or empty | Action implementation or instructions | Action output, then the instructions that format the reply |
| Reply is accurate but off in tone or content rules | Instructions | Conflicts between agent-level and topic instructions |
Use this table as a starting point. The chapter on diagnosing failures returns to it with real results.
Why this structure matters for test writing
Each part of a test case in this tutorial corresponds to one building block:
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.expectedTopicchecks topic selection.expectedActionschecks action selection.expectedOutcomechecks the reply, which reflects the instructions and the action results.
The names in expectedTopic and expectedActions must match the developer names of the topic and action in your agent. A test written against a display label or an old name fails even when the agent behaves correctly.
Summary of the model
- Topics route a request and set the boundary for what the agent may do.
- Actions are the only route to org data and changes.
- Instructions guide the agent's steps and its wording, but they are guidance, not code.
- Each building block produces one result that a test case can assert.
Exercise
A customer asks "Where is my order 1001?" The reply says "Your order is on its way," but the agent never ran GetOrderStatus. Which building block is the most likely cause, and which part of a test case would expose it?
Show answer
The cause is most likely action selection. The topic may be correct, but the action description, its assignment to the topic, or the topic instructions did not lead the engine to run it. The agent produced a plausible status without data. The expectedActions assertion exposes this, because GetOrderStatus would be missing from the actions that ran.
Exercise
Two topics, OrderStatus and OrderReturns, both have the description "Questions about the customer's orders." Utterances about order status sometimes land in Order_Returns. Which part do you change, and why does an expectedTopic assertion help?
Show answer
Change the classification descriptions and scopes so each topic states what it covers and what it excludes. The expectedTopic assertion shows which utterances land in the wrong topic. It makes the overlap visible and lets you confirm the fix by rerunning the same utterances.