Sub topic 14
Troubleshooting common problems
This chapter assumes you have followed the earlier chapters. You can run sf commands, you have authorized an org, and you have created, previewed, and tested an agent. Here you learn how to find the cause when the development loop breaks.
A working model for diagnosis
Each step in the loop depends on the one before it. A failure late in the loop often has its cause earlier. Work backward from the symptom and check each layer in order.
Setup and authorization failures
Most early errors come from the CLI or the org connection. Check these first:
sf --version
sf plugins
sf org list
sf org display --target-org my-dev-org- If
sf agentcommands are not found, the agent plugin is missing or outdated. Update the CLI and its plugins, then runsf pluginsagain. - If the org does not appear in
sf org list, or shows an expired status, runsf org login web --alias my-dev-orgagain. - If a command says it cannot find a target org, pass
--target-orgexplicitly or set a default org. - If the login works but creation fails with a permission error, the user lacks the permissions that Agentforce needs. Confirm that Agentforce is enabled in the org and that your user has the required permission sets.
Spec and creation failures
sf agent create reads the spec file you reviewed. Common causes of failure:
- The path in
--specis wrong, or the YAML is malformed. Check indentation first. - The
--api-nameis already in use or contains characters that are not valid in an API name. Use letters, numbers, and underscores only. - You edited generated topics or actions to reference something that does not exist in the org.
Fix the spec, then run the command again. Do not edit the created agent in Setup and the spec file at the same time. The two copies drift apart and you will not know which one is correct.
Preview and action problems
If sf agent preview starts but the agent gives poor answers, read the topic descriptions and instructions. The agent chooses a topic from those descriptions, so vague or overlapping text sends utterances to the wrong topic.
If a custom action is never called, check these points:
- The Apex class is deployed to the same org you are previewing against.
- The
@InvocableMethodhas a clearlabelanddescription. The agent uses them to decide when to call the action. - The action is attached to the correct topic.
- The
@InvocableVariablelabels describe the inputs in plain words.
If the action runs but returns "Not found", the problem is usually the data. Check that the case number in your utterance exists in that org.
Metadata and test problems
When a deploy fails, read the first error in the output. Later errors often follow from it. Missing dependencies are the usual cause, such as an Apex class that was not retrieved into your project.
Test failures fall into two groups:
| Symptom | Likely cause |
|---|---|
| Test cannot find the agent | `subjectName` does not match the agent's API name |
| Topic assertion fails | `expectedTopic` does not match the topic name in the org |
| Action assertion fails | `expectedActions` uses a label instead of the action name |
| Test times out | `--wait` is too short for the run |
| Result varies between runs | The utterance is ambiguous, or the outcome text is too strict |
A short checklist
- Run
sf org listto confirm the connection. - Validate the spec YAML and the names in it.
- Confirm the metadata is deployed to the org you are testing.
- Reproduce the problem in
sf agent preview. - Fix one thing, then rerun the test.
Exercise
Your test run reports that the expected action was not called, but the preview shows the agent answering the same question correctly. Name two things you would check.
Show answer
First, compare the action name in expectedActions with the actual action name in the org, since a label or a misspelled name fails the assertion. Second, confirm the test targets the same org and agent API name (subjectName) that you previewed, and that the Apex class is deployed there.