Sub topic 7
Setting up the agent user and permissions
This chapter assumes you can run Salesforce CLI commands, know how permission sets and profiles work, and have already retrieved and packaged your agent. Here you will set up the user the agent runs as and the permissions its actions need in the target org.
Why the agent user matters
An Agentforce agent does not act as the person chatting with it in every case. A service agent runs as a designated agent user. Each action the agent calls, such as an Apex class or a Flow, runs with that user's access. If the user cannot read an object or run an Apex class, the action fails, even if it worked in the source org.
User records and permission set assignments are not part of the agent metadata. Deploying the agent does not create the user or grant it access. You must do this in the target org yourself.
Step 1: Identify what the agent user needs
Use the dependency inventory from the earlier chapter. For each action, note what it touches:
| Action type | Access to grant |
|---|---|
| Apex class | Apex class access |
| Flow | Flow access, plus object and field permissions the Flow uses |
| Standard or custom object reads and writes | Object and field permissions |
| The agent itself | Access to the agent, depending on how it is used |
Grant only what the actions need. An agent user with broad access can expose more data than you intend.
Step 2: Put the access in a permission set
Collect these permissions in one permission set, rather than assigning them one by one. The set can be deployed with your manifest, which keeps the access the same across orgs. The manifest in the earlier chapter already includes the PermissionSet type.
In this example the permission set is named Agent_Action_Access. Replace this with your own name.
Step 3: Create or choose the agent user in the target org
The agent user is created in the target org, not deployed. Check these points:
- The user is active.
- The user has a license and profile that allow the permissions in your set. Some features require specific licenses, so check your org's available licenses first.
- For a service agent, the user you select in the agent's configuration is the one that runs it.
Sandboxes often have different users and usernames from production. Do not assume the same user exists in the target.
Step 4: Assign the permission set
Assign the permission set to the agent user with the CLI. Use --on-behalf-of when the user is not the CLI's authenticated user.
sf org assign permset \
--name Agent_Action_Access \
--on-behalf-of [email protected] \
--target-org target-orgConfirm the assignment by querying it:
sf data query \
--query "SELECT Assignee.Username, PermissionSet.Name FROM PermissionSetAssignment WHERE PermissionSet.Name = 'Agent_Action_Access'" \
--target-org target-orgThe result should list the agent user. If it is empty, the assignment did not happen.
Step 5: Check the common failures
- Action fails with insufficient access. The agent user lacks Apex class, Flow, object, or field access. Add it to the permission set and redeploy.
- Agent cannot be activated or run. The selected user is missing, inactive, or lacks the license the agent requires.
- It worked in the sandbox. Your sandbox user was probably an administrator. Production's agent user has only what you granted, so test with that user's access.
The next steps depend on this setup. Activation and verification only succeed when the agent user has the access its actions need.
Exercise
You deployed an agent to production and assigned the permission set with sf org assign permset --name Agent_Action_Access --target-org target-org. The command reported success, but the agent's actions fail with access errors. What is the most likely cause, and how do you confirm it?
Show answer
The command had no --on-behalf-of option, so it assigned the permission set to the CLI's authenticated user instead of the agent user. Confirm by querying PermissionSetAssignment for the permission set and checking that the agent user appears as the assignee. Then rerun the command with --on-behalf-of set to the agent user's username.