8.1 Deploying an Agent from Sandbox to Production

Key Takeaways

  • New Agentforce Builder agents use AiAuthoringBundle metadata for Agent Script, with Bot, BotVersion, and GenAiPlannerBundle created when a version is committed.
  • Agent retrieval automatically includes flow, Apex, and prompt template actions, but other dependencies such as custom objects and Data 360 assets must be added to the manifest.
  • The first deployment to a target org must include the whole agent definition, and later deployments are blocked unless source and target agent versions match.
  • Agents run as a user, so the agent username must be replaced or assigned in the target org, and committed agents need a new version to change it.
  • Data library changes can't be deployed from a sandbox, and MCP server registrations aren't packaged, so recreate or re-register them in the target org.
Last updated: September 2026

8.1 Deploying an Agent from Sandbox to Production

Quick Answer: Build and test agents in a sandbox, then move them as metadata: retrieve with a package.xml manifest and deploy with Salesforce CLI / Agentforce DX, VS Code, DevOps Center, or a partner DevOps tool. Include dependencies, set the agent user for the target org, respect version matching and committed-version rules, and plan to recreate what doesn't deploy: data libraries, MCP server registrations, channel setup, and some Data 360 assets. Then test, commit, and activate in production.

Why Deploy Instead of Rebuilding

Rebuilding an agent by hand in production is error-prone and skips testing evidence. Treating agents as metadata gives you version control, code review, repeatable CI/CD, and the same configuration you validated in Testing Center.

Agent Metadata Types

Metadata typeWhat it representsBuilder
AiAuthoringBundleDesign-time artifacts: the .agent Agent Script file plus a bundle descriptor, stored per version (for example AgentName_1, AgentName_2)New Agentforce Builder only
BotInformation common to all versions, such as agent type, settings like private-data logging, and agent-level context variablesBoth
BotVersionVersion details, such as conversation variables, welcome message, and transfer messageBoth
GenAiPlannerBundleAll data for each published (committed) version. In the new builder it bundles local subagents and actions, input and output schemas, and the agent graph and scriptBoth (replaced GenAiPlanner from API v64)
GenAiPlugin / GenAiFunctionTopics (subagents) and actions as separate metadataMainly legacy builder agents
GenAiPromptTemplatePrompt templates used by actionsBoth
AiEvaluationDefinitionTesting Center test definitionsBoth

Key points from Salesforce's metadata guidance:

  • In the new builder, Bot and GenAiPlannerBundle are created automatically when a version is committed. AiAuthoringBundle, the agent script, and the agent graph exist only for new-builder agents.
  • GenAiPlannerBundle versions auto-increment in commit order, so they don't necessarily match AiAuthoringBundle version numbers.
  • The new bundled structure puts all version-specific local assets in one folder, which prevents missing-dependency errors.
  • Metadata types evolve with API versions. Salesforce notes that the newest agent metadata requires both orgs on the same supported API version. While one org is a release ahead, keep using the previous types.

The Retrieve-and-Deploy Workflow

  1. Update Salesforce CLI and authorize both orgs.
  2. Create a Salesforce DX project with a manifest.
  3. Define the agent in package.xml. Specify versions such as MyAgent#2 (version 2), MyAgent#* (all versions), or * (all agents).
  4. Retrieve. Salesforce automatically retrieves the agent's flow, Apex, and prompt template actions. Add other metadata the agent needs, such as custom objects and Data 360 dependencies.
  5. Handle the agent user. Retrieved metadata contains source-org usernames. Use string replacement to substitute the target org's agent username for draft agents. You can't do this for committed agents, because they can't be edited.
  6. Deploy with the appropriate sf project deploy start command. The first deployment must include the whole agent definition, not just one version.
  7. Configure in the target org: assign the agent user if it wasn't set during deployment, grant it permissions, and connect channels.
  8. Test, commit if needed, and activate.

For Agent Script-first development, Agentforce DX also offers commands such as sf agent publish authoring-bundle (creates the underlying agent metadata in an org) and sf agent activate.

Rules That Cause Deployment Failures

RuleConsequence
Agents in source and target must match after the first deploymentIf you create a new version in the target, create the corresponding version in the source, or future deployments are blocked
Committed agents can't be editedTo add or change the agent user on a committed agent, create a new version first
Draft agents deployed without username replacementYou must manually update the agent's username before it can run
Don't hand-edit other retrieved agent metadataSalesforce warns that uploading edited metadata can corrupt your org
Agent user permissionsThe target agent user needs every permission the agent's actions require, such as FLS on a custom contact field
Target org readinessEinstein and Agentforce must be enabled, and Data 360 must be set up if the agent depends on it

What Doesn't Move with Agent Metadata

AssetWhat to do
Agentforce Data LibraryDeploying library changes from a sandbox isn't supported. Recreate the library in the target org. Files aren't copied into sandboxes either
Data 360 search indexes and retrieversUse data kits or recreate them. They aren't included with prompt template deployments
MCP server registrationsRegistration metadata isn't packaged. Before deploying, register the MCP servers in the target org and allowlist the tools. After deploying, replace the MCP tool actions in the agent with the new ones from the asset library
Agent user recordUsers aren't metadata. Create or select the agent user in the target org (for example with sf org create agent-user) and assign permission sets
Channel configurationSet up Enhanced Chat deployments, messaging channels, email configurations, telephony, and Omni-Channel flow activation in the target org as needed
Permission set assignmentsAssign permission sets to users in the target org

Deployment Readiness Checklist

  • Testing Center suites pass in the sandbox (default, quality, and custom scorers)
  • Manifest includes the agent plus custom objects, fields, and Data 360 dependencies
  • Prompt templates are active in source, and the plan covers activation in target (section 8.2)
  • Flows referenced by actions will be active in target
  • Target agent user exists with least-privilege permissions
  • Data libraries, retrievers, and MCP registrations exist in target
  • Channels and Omni-Channel flows are configured
  • Rollback plan: keep the previous committed version so you can reactivate it

Scenario

An agent passes testing in a Developer Pro sandbox. The team retrieves ServiceAgent#3 and deploys to production. The deploy succeeds, but the agent can't run. Likely causes, in order:

  1. The agent username still points to the sandbox user. For a draft, replace it; for a committed version, create a new version with the correct user.
  2. The production agent user lacks permissions for a custom object the flow updates.
  3. The agent's data library doesn't exist in production, because libraries aren't deployable from sandboxes.

Exam Traps

  • Flow, Apex, and prompt template actions retrieve with the agent, but custom objects and Data 360 dependencies need explicit manifest entries.
  • Version mismatch blocks future deployments.
  • MCP tool actions don't work out of the box after deployment until servers are registered and actions replaced.
  • You can't deploy a data library from a sandbox.
Loading diagram...
Sandbox-to-production agent deployment
Test Your Knowledge

An architect retrieves a committed agent version from a sandbox and deploys it to production, but the agent can't run because its agent username references a sandbox user. How should this be fixed?

A
B
C
D
Test Your Knowledge

When retrieving an agent's metadata with a package.xml manifest, which dependencies does Salesforce retrieve automatically?

A
B
C
D
Test Your Knowledge

After the first deployment, an admin creates a new agent version directly in production. What problem does Salesforce warn about?

A
B
C
D
Test Your Knowledge

An agent uses MCP tool actions registered in the sandbox. What must happen for those actions to work after deployment to production?

A
B
C
D