Sub topic 14
Testing the Agent and Inspecting Action Calls
This chapter covers how to test an Agentforce agent in Agentforce Builder and how to read the record of what it did. It assumes you know the Salesforce data model, can work in Setup and Lightning Experience, and understand how topics, instructions, and actions fit together from earlier chapters. It also assumes you know the basics of permission sets and profiles.
Why testing actions needs its own method
An agent is not deterministic code. The same request can lead to slightly different wording, and sometimes a different action path. A passing test therefore needs more than a good-looking reply. You need to confirm four things:
- The right topic was chosen.
- The right actions ran, in a sensible order.
- Each action received the right inputs.
- The reply reflects what the actions actually returned.
A fluent answer can still be wrong. For example, the agent may skip a lookup and answer from the conversation alone, or it may update the wrong record. The tools below let you check each step.
The testing surface in Agentforce Builder
Builder has a preview panel where you chat with the agent as if you were a user. Two parts matter most:
- The conversation pane. You type messages and read replies, as an end user would.
- The interaction details. For each turn you can open a trace of what happened behind the reply. Names of panels can differ between releases, so look for the trace or "reasoning" view for the turn.
The trace typically shows these stages:
- The user message as received.
- The topic the agent classified the message into.
- The actions available in that topic, and which ones were called.
- The inputs sent to each action and the outputs returned.
- The final reply the agent produced from those outputs.
Read the trace from the top down. When a reply is wrong, the first stage that looks wrong is usually where the fix belongs.
Choosing the test user
Actions run on behalf of a user, so the data they can see depends on who is running them. Preview in Builder uses your own access by default. This can mislead you in two ways:
- As an administrator you may see records that your intended users cannot. A lookup that works for you can return nothing for them.
- If your user lacks a permission the agent needs, you may see an error that your real users would not.
Test with representative users, not only with an administrator. Confirm that the permission sets and profiles for your target group give field-level and object-level access to everything the actions touch. The chapter on permissions and the Einstein Trust Layer covers the rules. Here the point is practical: repeat important tests under each kind of user.
A test plan for a topic
Build a short, written test plan for each topic before you change anything. Use the Account Support topic from earlier chapters as a model. The table lists cases and what to check in the trace.
| Case | Example message | What to confirm in the trace |
|---|---|---|
| Happy path | "Give me an overview of Acme." | Identify Record by Name ran first, then the summary action used its result. |
| Ambiguous name | "Summarize the Global account." | With several matches, the agent asks you to clarify and does not guess. |
| No match | "Summarize Zzyzx Corp." | The lookup returned no record, and the agent says so without inventing data. |
| Update with confirmation | "Change Acme's phone to 555-0100." | The agent restates the field and new value and waits before calling the update action. |
| Update declined | Reply "no" to the confirmation. | No update action appears in the trace. |
| Out of scope | "Write me a poem." | The agent declines or redirects and calls no actions. |
| Restricted user | Repeat the happy path as a low-access user. | The result respects that user's access, and the agent reports what it cannot see. |
Run each case more than once. If a case passes four times and fails once, the instructions are too loose. Fix the instructions, not the single failing run.
Reading action inputs and outputs
For each action call, check the inputs first.
- Missing inputs. A required input that is empty means the agent did not collect it. Add instruction text such as "ask the user for the account name if it is missing", or improve the input's description.
- Wrong inputs. The agent may pass a name where an ID is needed. Chaining fixes this: the lookup produces the ID, and the next action takes it as input. Say so in the topic instructions.
- Invented values. If an input contains a value the user never gave, the agent guessed. Tighten the instruction and the input description.
Then check the outputs.
- Empty output. The action ran but returned nothing. Check the filter, the record name, and the user's access.
- Error output. The message often names the cause, such as a missing field permission or a failed validation rule on an update. Fix the cause in Setup.
- Correct output, wrong reply. The agent had the right data and still answered badly. The problem is in the instructions or the agent's wording rules, not in the action.
Diagnosing common failures
The most common failures and their usual fixes:
- Wrong topic. The classification description overlaps with another topic. Make each description narrow and distinct, and describe what the topic does not cover.
- Action not called. The action's name or description does not match the user's wording, or the instructions never say when to use it. Name the action and the trigger in the instructions, as in "Use the summary action when the user asks for an overview."
- Wrong order. The agent summarizes before it finds the record. State the order explicitly, as in "first find the account record, then use the result for any later step."
- Too many actions. A topic with many similar actions makes selection less reliable. Remove actions the topic does not need.
- Update without confirmation. The instructions do not require it. Add a confirmation step before any action that changes data.
Test safely
Update and create actions change real data, even in preview. Follow these rules:
- Use a sandbox or a Developer Edition org, not production, to test record-changing actions.
- Create test records with clear names such as "ZZ Test Account" so you can find and delete them.
- Keep a list of records your tests change, and restore them afterward.
Change one thing at a time
When a test fails, change one piece, then rerun the same message. If you edit the topic description, an instruction, and an input description together, you cannot tell which change helped. Save your test messages in a document so you can replay them after every edit. This also catches regressions, where a fix for one case breaks another.
A useful habit is to keep a pass/fail record per case, with the date and the user you tested as.
Exercises
Exercise
You ask the agent, "Summarize the Orion account." The reply is a plausible summary, but the trace shows no Identify Record by Name call and the summary action received an empty account input. What does this tell you, and what is the likely fix?
Show answer
The agent answered without a real record. The summary action ran with no account, so the reply cannot be trusted. Add an instruction that the agent must first find the account record and pass the result to the summary action, and make the summary action's input description say it needs a record found earlier. Then rerun the message and confirm the lookup appears before the summary in the trace.
Exercise
A lookup returns an account when you test as an administrator, but a sales user gets "I could not find that account" with the same message. Name two things to check.
Show answer
Check the sales user's object and field access through their profile and permission sets, and check sharing, because the user may not be able to see that record. The action runs on behalf of the user, so it only returns what that user can access. Retest as the sales user after fixing access.
Exercise
The agent updates a phone number right after the user asks, with no confirmation. The topic instructions never mention confirming. How do you fix it, and how do you check the fix?
Show answer
Add an instruction such as "Before updating a record, restate the field and the new value and ask the user to confirm." To check, send the update request in a sandbox and confirm the update action does not appear in the trace until the user answers yes. Also send "no" and confirm no update runs.