Sub topic 10
Activating the agent and checking it works
This chapter covers the step after deployment: making the agent active in the target org and confirming that it behaves as it did in the source org. It assumes you can use the Salesforce CLI, that you have deployed the agent metadata (Bot, BotVersion, GenAiPlanner, GenAiPlugin, GenAiFunction) and its dependencies, and that you know the agent user and permission set concepts from the previous chapters.
Why deployment is not the finish line
A successful deployment means the metadata files were accepted by the target org. It does not mean customers or employees can talk to the agent. Three things can still be missing:
- The agent version may be inactive, so no channel will route conversations to it.
- The agent user or the running user may lack access to the Apex classes, Flows, and objects that the actions call.
- Org-specific data, such as record IDs, Knowledge articles, or channel connections, may not exist in the target.
Treat activation and verification as one phase with a fixed order: grant access, activate, inspect state, then exercise the agent.
Step 1: Grant access before you activate
Activation can succeed even when the agent cannot do its work. The failure appears later, at conversation time, when an action runs under a user that lacks permission. For that reason, assign permission sets first.
Two identities matter:
- The agent user. For service agents, this is the user the agent runs as. It needs the permission sets that give access to the objects, fields, Apex classes, and Flows used by the agent's actions.
- The people who test and use the agent. For employee-facing agents, the logged-in user is the running user. Each person needs access to the agent and to what its actions touch.
Permission sets travel as metadata, but their assignments do not. Assignment is data in the target org, so you must repeat it there.
sf org assign permset --name Agent_Action_Access --target-org target-org
sf agent activate --api-name My_Service_Agent --target-org target-orgThe permission set name and agent API name above are placeholders. Replace them with your own. The --api-name value is the agent's developer name, which is the Bot metadata file name without the extension.
If the agent user is a different user from your CLI user, sf org assign permset alone is not enough. Use the --on-behalf-of flag with the agent user's username, or assign the permission set in Setup.
sf org assign permset \
--name Agent_Action_Access \
--on-behalf-of [email protected] \
--target-org target-orgThe username of the agent user in the target org usually differs from the source org, because sandbox usernames carry a suffix. Check it before you run the command.
Step 2: Activate the agent
An agent can have several versions, and only one version is active at a time. Activation turns on the version you choose. It also makes that version the one that channels use.
sf agent activate --api-name My_Service_Agent --target-org target-orgIf the command asks you to choose a version in a non-interactive environment, pass the version explicitly. Run sf agent activate --help to see the flags available in your installed CLI version, because agent commands have changed between plugin releases.
You can also activate in the UI. Open Agentforce Studio (Agent Builder in older orgs), pick the agent, and select Activate. Both paths set the same version status.
Deactivate before you redeploy
Metadata for an active agent version is often locked against changes. If you deploy a changed BotVersion while it is active, you may see an error saying the version cannot be modified. The safe cycle for a later release is:
- Deactivate the agent in the target org.
- Deploy the new metadata.
- Activate again.
sf agent deactivate --api-name My_Service_Agent --target-org target-org
sf project deploy start --manifest manifest/package.xml --target-org target-org
sf agent activate --api-name My_Service_Agent --target-org target-orgStep 3: Check the status
After activation, confirm the state instead of trusting the command's exit message. BotVersion records are queryable, so you can compare source and target directly.
sf data query \
--query "SELECT BotDefinition.DeveloperName, VersionNumber, Status FROM BotVersion WHERE BotDefinition.DeveloperName = 'My_Service_Agent'" \
--target-org target-orgRun the same query against source-org. You should see the same version numbers. Compare the Status column, too. The expected result in the target after activation is one row with Status set to Active, and any older versions set to Inactive.
If the target shows a different version count, the usual causes are:
- The manifest used specific
BotVersionmembers and missed one. - A previous deployment created a version that you never cleaned up.
- The source org has draft versions that were never meant to ship.
Step 4: Preview the agent
Preview lets you converse with the agent from the CLI or the builder, without wiring up a channel. It is the quickest way to find out whether topics are routing correctly and actions are running.
sf agent preview --api-name My_Service_Agent --target-org target-orgThe CLI starts an interactive session. If your plugin version supports it, you can choose between simulated actions and live actions. Use them differently:
| Mode | What runs | Use it for |
|---|---|---|
| Simulated | The model decides which actions to call, but action results are generated, not real | Checking topic routing and instructions without touching data |
| Live | Real Apex, Flows, and queries run in the target org | Checking that dependencies, permissions, and data actually work |
Simulated mode cannot expose a missing Apex class or a missing permission, because nothing executes. After deployment, the live mode is what answers your real question: does this agent work here?
Use a small set of prompts that you also used in the source org. For each topic, send at least:
- One request that should trigger the topic and one of its actions.
- One request that is outside the topic's scope, to check the agent declines or redirects as the instructions say.
- One request that depends on org data, such as looking up a record that exists in the target.
Write the expected behavior down before you run the prompts. Otherwise you tend to accept whatever the agent says.
What to look at beyond the reply text
A fluent reply can hide a failure. Open the session trace in the builder, or the preview output if your CLI shows it, and check:
- Which topic was selected.
- Which actions were called and with what inputs.
- Whether each action returned a result or an error.
An agent that answers from general knowledge because its action failed can sound correct while being wrong. The trace shows this. The reply alone does not.
Step 5: Run automated tests
Manual previews do not scale and are hard to repeat. If you have a test suite defined for the agent, deploy it with the agent and run it in the target org. The next chapter covers test design in depth. Here, only the basic loop matters:
sf agent test run --api-name My_Agent_Test_Suite --wait 10 --target-org target-orgThe test suite name is a placeholder. The test definitions are metadata (AiEvaluationDefinition), so you must include them in the manifest, or the target org will have nothing to run. Compare the pass rate in the target with the source. A drop usually points to missing data or permissions, not to a model problem.
Common errors and how to read them
| Symptom | Likely cause | What to do |
|---|---|---|
| Activation fails with a message about the agent user | The agent user is missing, inactive, or lacks the required license or permission set | Create or fix the agent user, assign the permission set, retry |
| Activation succeeds but the agent never answers on a channel | The channel (for example, a messaging deployment) is not configured or not linked to the agent in the target | Configure the channel in the target org. Channel setup is not part of the agent metadata |
| An action returns an error about insufficient access | The running user or agent user cannot reach the Apex class, Flow, or object | Add the Apex class or Flow access to the permission set and assign it |
| Deploying a new version fails because the version is locked | The current version is active | Deactivate, deploy, activate |
| Agent replies but never calls an action | Topic classification or instructions differ, or an action is not attached to the topic | Read the trace, then check topic and action assignments |
| An action fails on a hard-coded record ID | An ID from the source org does not exist in the target | Replace IDs with lookups by name or a custom setting |
A repeatable verification checklist
Use this list at the end of every deployment:
- Permission sets are assigned to the agent user and to the testers.
- The agent version is active, confirmed by querying
BotVersion. - Version numbers match between source and target.
- A live preview of every topic shows the right action running and returning a result.
- Out-of-scope prompts get the expected refusal or redirect.
- Automated tests pass at the same rate as in the source.
- The channel is connected and a real message reaches the agent.
Exercise
You deployed an agent and activated it. In a simulated preview, every action appears to work. Users then report that the agent cannot look up orders. Name the likely gap and one way to confirm it.
Show answer
Simulated mode generates action results without running Apex or Flows, so it cannot detect missing access or missing dependencies. The likely cause is that the agent user or running user lacks access to the Apex class, Flow, or object behind the order lookup. Confirm by running a live preview, then reading the trace for the action's error, and check the permission set assignment in the target org.
Exercise
A second release fails to deploy with an error saying the bot version cannot be changed. What is the safe sequence of commands to release the change?
Show answer
Run sf agent deactivate --api-name My_Service_Agent --target-org target-org, then sf project deploy start --manifest manifest/package.xml --target-org target-org, then sf agent activate --api-name My_Service_Agent --target-org target-org. Finally, query BotVersion to confirm the new version is active.