Sub topic 12
Testing in Flow Builder and in the agent preview
Testing a flow-based action happens in two places. Flow Builder tells you whether the flow logic works. The agent preview in Agent Builder tells you whether the agent calls the flow at the right time, with the right inputs, and explains the result well. This chapter covers both layers and how to find the cause when one of them fails.
This chapter assumes you can build and save an autolaunched flow, and that you know how to open Agent Builder from Setup. It uses the Get_Case_Status flow from earlier chapters. That flow takes a caseNumber input, runs Get Records on Case, and returns a caseStatus output.
Why you test in two layers
An action can fail in two different ways. The flow can be wrong, or the agent can use a correct flow wrongly. These failures look similar in a chat window, so you test them separately.
| Layer | Question it answers | Where you test it |
|---|---|---|
| Flow logic | Given these inputs, does the flow return the right outputs? | Flow Builder debug |
| Action selection | Does the agent pick this action for this request? | Agent preview |
| Input collection | Does the agent pass the right value in each input? | Agent preview, plan view |
| Response | Does the agent report the output correctly? | Agent preview |
Always test the flow first. If the flow is wrong, every agent test after that is misleading.
Testing the flow in Flow Builder
Run a debug session
Open the flow in Flow Builder and select Debug. Enter values for the input variables, then run it. The debug panel lists each element that ran, the values it read, and the final values of your output variables.
For Get_Case_Status, run at least these cases:
- A case number that exists, such as
00001026. ExpectcaseStatusto hold the case's Status. - A case number that does not exist, such as
99999999. Expect the short message from your not-found path, not an empty value. - An empty
caseNumber. The agent may send this if it fails to collect the input. Expect a clear message. - A case number with leading or trailing spaces. Users paste values with stray whitespace, so decide whether the flow trims it.
Check what the debug options change
The debug dialog has options that affect results. Know them before you trust a run.
- Run flow in rollback mode. Changes made by the flow are rolled back after the run. Use this for flows that create or update records, so that test runs do not leave data behind. Some actions, such as sending email, still happen in rollback mode.
- Show details of what is executed. This adds more detail for each element in the debug output. It helps when a decision takes a path you did not expect.
- Run as another user. If your org offers it, you can debug as a different user, which helps you test permissions. If it is not available, you can still test by logging in as a test user.
Rollback mode matters most for update flows. Without it, a debug run changes real records.
Read the output values
Check the output values, not only whether the run finished. A flow can complete with no error and still return a wrong or empty caseStatus. If an output is blank, the usual causes are:
- The Get Records element found nothing, and no assignment set a fallback message.
- An assignment stored the value in a different variable than the output variable.
- The output variable name differs by one character from what you expected, because variable names are case sensitive in some references.
Compare the final variable values in the debug panel with the output you intended.
Check the variable settings
The agent only sees variables marked as available for input or output. Confirm the metadata still matches your plan:
<variables>
<name>caseNumber</name>
<dataType>String</dataType>
<isCollection>false</isCollection>
<isInput>true</isInput>
<isOutput>false</isOutput>
<description>The Case Number of the case to look up, for example 00001026.</description>
</variables>
<variables>
<name>caseStatus</name>
<dataType>String</dataType>
<isCollection>false</isCollection>
<isInput>false</isInput>
<isOutput>true</isOutput>
<description>The current Status of the case, or a short message if no case was found.</description>
</variables>A common error is a debug run that works because you typed a value into a variable that is not marked as input. The agent cannot fill that variable, so the action fails in the preview even though the debug passed.
Testing the action in the agent preview
Refresh the action after flow changes
When you save a new version of a flow, make sure the action points at a version you tested. Activate the new version of the flow. Then reopen the action in Agent Builder and check that it still lists the inputs and outputs you expect. If you added, renamed, or removed a variable, you may need to remove the action and add it again so that the new variable settings appear.
Run realistic utterances
Open the preview panel in Agent Builder and type requests as a user would. Do not only use the phrasing from your own instructions. Test a spread of requests:
| Test type | Example utterance | What you check |
|---|---|---|
| Happy path | "What is the status of case 00001026?" | The action runs and the reply states the real status |
| Missing input | "What is the status of my case?" | The agent asks for the case number before it calls the action |
| Indirect wording | "Any news on ticket 00001026?" | The agent still picks the action |
| Not found | "Status of case 99999999?" | The reply uses the not-found message, without inventing a status |
| Wrong topic | "Cancel my subscription" | The agent does not call `Get Case Status` |
The missing input row tests the input setting from the earlier chapter: Collect from the user. Ask for it if it was not provided. If the agent guesses a case number instead of asking, revisit that setting.
Inspect the plan
The preview can show how the agent reasoned. Open the plan or trace view for a reply. It shows the topic the agent chose, the action it called, the input values it sent, and the output it received. This is the main tool for finding the cause of a wrong reply.
Read the trace in this order:
- Topic. Did the agent pick the topic that holds your action? If not, the topic description or scope needs work.
- Action. Was your action called? If not, the action instructions or the action's description do not match the request.
- Inputs. Were the values correct? A case number with extra words, or a value taken from the wrong part of the message, points to the input description or input instructions.
- Outputs. Does the output match your debug run? If it differs, the flow in the org may be a different version from the one you debugged.
- Reply. Does the reply match the output? If the output is right and the reply is wrong, tighten the output instructions, for example "Tell the customer the status in plain language."
Know what the preview does not guarantee
The agent's language model produces the reply, so two runs of the same utterance may be worded differently. Test each important utterance more than once. A test that passes once is weaker evidence than one that passes several times.
Also remember that the preview runs with the permissions that the preview session uses, which may not be the same as those of real customers. The security chapter covers run context. Test with the real kind of user when permissions matter.
Diagnosing common failures
| Symptom | Likely cause | Fix |
|---|---|---|
| Action never called | Instructions do not match the request, or action is on a different topic | Rewrite the action instructions and check the topic |
| Wrong action called | Two actions have overlapping descriptions | Make the descriptions distinct, or merge or split the actions |
| Agent invents a case number | Input setting does not require collecting from the user | Set the input to collect from the user and ask when missing |
| Action called, error shown | Flow fails on the given input | Debug in Flow Builder with the exact value from the trace |
| Output blank in the reply | Output variable not populated, or not marked as output | Check the debug panel and the variable settings |
| Reply states wrong status | The agent paraphrased the output badly | Add an output instruction that says to report the value as given |
| Works in debug, fails in preview | Permissions differ, or a different flow version is active | Check the active version and the run context |
When the cause is not obvious, take the exact input from the trace and run it in Flow Builder debug. This separates a flow problem from an agent problem in one step.
A repeatable test routine
Keep a short list of utterances and expected results for each action. Run the list after any change to the flow, the descriptions, or the instructions. A change to a variable description can alter how the agent behaves with no change in the flow logic, so the list also guards against that.
For a flow-based action, the minimum list covers one happy path, one missing input, one not-found case, one indirect wording, and one request that should not trigger the action.
Exercise
Your debug run of Get_Case_Status with 00001026 returns the correct status. In the agent preview, the same request gets a reply that says the status is "Open", but the case is Closed. The plan view shows the action was called with 00001026 and returned "Closed". Where is the problem, and what do you change?
Show answer
The flow and the input are fine, because the output was "Closed". The problem is in the agent's reply, the last step in the trace. Add or tighten the output instruction, for example "Report the status exactly as returned by the action", and retest the utterance several times.
Exercise
Give two reasons a flow can pass in Flow Builder debug but fail when the agent calls it.
Show answer
First, a variable you filled in during debug is not marked as available for input, so the agent cannot supply it. Second, a different flow version is active, or the preview runs with different permissions than your debug session. Either one changes the result without any change to the logic you tested.