Sub topic 2
Retrieving an Agentforce Agent from a Source Org
This chapter assumes you understand Salesforce orgs, permission sets, Salesforce CLI, and basic Agentforce concepts. You should also know that Apex classes and Flows can implement agent actions.
Retrieving the Agent from the Source Org
An Agentforce agent is stored as deployable metadata. Retrieve the agent-related metadata into a Salesforce DX project before you build a deployment package. Authenticate both orgs first, then retrieve the agent from the source org.
sf org login web --alias source-org
sf org login web --alias target-org
sf project retrieve start \
--metadata Bot \
--metadata BotVersion \
--metadata GenAiPlanner \
--metadata GenAiPlugin \
--metadata GenAiFunction \
--target-org source-orgThe exact metadata types can vary by Agentforce release and agent configuration. Check the retrieved files and your current Salesforce metadata documentation before committing the project.
Writing a Manifest for the Agent and Its Dependencies
A manifest is a package.xml file that lists the metadata to deploy. Include the agent metadata and every component used by its actions, such as Apex classes, Flows, and permission sets.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>*</members>
<name>Bot</name>
</types>
<types>
<members>*</members>
<name>BotVersion</name>
</types>
<types>
<members>*</members>
<name>GenAiPlanner</name>
</types>
<types>
<members>*</members>
<name>GenAiPlugin</name>
</types>
<types>
<members>*</members>
<name>GenAiFunction</name>
</types>
<types>
<members>*</members>
<name>ApexClass</name>
</types>
<types>
<members>*</members>
<name>Flow</name>
</types>
<types>
<members>*</members>
<name>PermissionSet</name>
</types>
<version>63.0</version>
</Package>Use specific member names instead of wildcards in a production project. Wildcards are useful while discovering dependencies, but they can deploy unrelated metadata.
Setting Up the Agent User and Permissions
The target org needs an agent user with the required licenses, permissions, and access to action dependencies. Deploying a permission set does not automatically assign it to a user.
sf org assign permset \
--name Agent_Action_Access \
--target-org target-orgAssign the permission set to the correct target-org user. Confirm that the user can access the Apex classes, Flows, objects, and fields used by the agent.
Handling Environment-Specific Settings
The source and target org may use different URLs, named credentials, record IDs, users, or permission assignments. Keep these values configurable rather than copying source-org values into the target.
Record the required substitutions before deployment:
- Target-org user and permission-set assignments
- Named credentials and external service settings
- Record IDs and queue identifiers
- Feature enablement and licensing requirements
Exercise
Why should a manifest include an agent's Apex classes and Flows?
Show answer
The agent's actions may reference those components. Including them makes the deployment package contain the dependencies required for the actions to work.