Sub topic 11
Activating and deactivating an agent
This chapter assumes you have created an agent with sf agent create, previewed it, and run a passing test suite. You should also know what a bot version is in Salesforce metadata. An agent can exist in your org and still be unavailable to users. Activation is the step that makes it available.
What activation changes
A newly created agent is inactive. You can preview it and run tests against it, but it does not respond to real users in channels such as Experience Cloud or messaging. Activating the agent publishes its current version to those channels. Deactivating takes it offline again.
Activation matters for editing too. An active version is treated as live, so you generally cannot change it in place. To change behavior, you deactivate the agent, deploy your edits, retest, and activate again. Check the current Agentforce DX documentation for how your org handles new versions, because this behavior has changed between releases.
Activating from the CLI
Activate by API name. Use the same org alias you used for creation and testing.
sf agent activate --api-name Case_Helper --target-org my-dev-orgIf you omit --api-name in an interactive terminal, the command prompts you to choose an agent. In scripts, always pass it explicitly so the command never waits for input. Run sf agent activate --help to see whether your plugin version also accepts a --version flag for choosing a specific version.
To take the agent offline:
sf agent deactivate --api-name Case_Helper --target-org my-dev-orgA safe change sequence
Use the same order every time you change an agent that is already live:
- Deactivate the agent in the target org.
- Deploy the changed metadata, such as topics, instructions, or an Apex action.
- Run
sf agent test runand confirm the results. - Activate the agent again.
sf agent deactivate --api-name Case_Helper --target-org my-dev-org
sf project deploy start --source-dir force-app --target-org my-dev-org
sf agent test run --api-name Case_Helper_Tests --wait 10 --result-format human --target-org my-dev-org
sf agent activate --api-name Case_Helper --target-org my-dev-orgDeactivation interrupts users, so run this sequence in a sandbox first. In production, schedule it for a quiet period.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Activation fails with a validation message | The agent has no topics, or a topic references an action that is missing in the org | Deploy the missing metadata, then retry |
| Deploy fails on an active agent | The active version is locked against edits | Deactivate, deploy, and activate again |
| Agent works in preview but not in the channel | The agent is inactive, or the channel is not connected to it | Check status, then check the channel configuration in Setup |
| Command asks you to pick an agent | `--api-name` was omitted | Pass `--api-name` explicitly |
| Permission error | Your user lacks the agent admin permissions | Review the permission sets from the authorization chapter |
Preview does not require activation, which is why a working preview does not prove the agent is live.
Exercise
Your agent works in sf agent preview, but customers in the messaging channel get no responses. What is the first thing to check, and what command fixes it?
Show answer
Check whether the agent is active. Preview works on inactive agents, but channels only serve active ones. If it is inactive, run sf agent activate --api-name Case_Helper --target-org my-dev-org. If it is already active, check the channel configuration in Setup.
Exercise
Put these steps in the correct order for changing a live agent: activate, run tests, deploy changes, deactivate.
Show answer
Deactivate, deploy changes, run tests, activate. Testing before activation means a failed test can stop the release before users see the change.