With Salesforce CLI, you can retrieve AgentScript metadata into a DX project, work with it locally in VS Code, and deploy changes back to your org.
Prerequisites
- VS Code
- Salesforce CLI
- Salesforce DX Extensions
- Agentforce org connected to Salesforce CLI (you can also connect Trailhead playground org, see this connection guide)
Step 1. Create a DX Project
sf project generate --name agentforce-demo
cd agentforce-demo
Step 2. Authenticate to Your Org
sf org login web --alias my-agentforce-org --instance-url https://your-org-name.develop.my.salesforce.com
Verify the connection:
sf org list
Set the default org:
sf config set target-org my-agentforce-org
Step 3: Find the Agent Name
To retrieve AgentScript metadata, you need the agent name. There are several ways to find it.
Option 1: Agentforce Builder
Open your agent in the new Agentforce Builder, and in the Agent Definition view find your agent Developer Name
Option 2: View Agents with Salesforce CLI
If an agent has at least one published version, it appears as Bot metadata:
sf org list metadata --metadata-type Bot
Example output:
Full Name
------------------
CC_Service_Agent
Sales_Agent
Support_Agent
Important: This command only lists agents that have a published version. Draft-only agents may not appear.
Option 3: List AgentScript Bundles
You can also list AgentScript bundles directly:
sf org list metadata --metadata-type AiAuthoringBundle
Example output:
Full Name
------------------
CC_Service_Agent
CC_Service_Agent_1
CC_Service_Agent_2
This command will list all versions of all agents your org (draft and published).
Step 4: Retrieve AgentScript Metadata
Retrieve a specific agent:
sf project retrieve start --metadata AiAuthoringBundle:Your_Agent_Name
For example: if your agent Developer Name is "My_Agent", the command will look like this:
sf project retrieve start --metadata AiAuthoringBundle:My_Agent
Retrieved metadata is stored in:
force-app/
└── main/
└── default/
└── aiAuthoringBundles/
The bundle contains the AgentScript configuration used by Agentforce Builder.
Step 5: Deploy Changes Back to the Org
After making changes locally deploy them back to the org:
sf project deploy start --metadata AiAuthoringBundle:Your_Agent_Name
Important: Draft vs Published Agents
⚠️ One detail that is not immediately obvious when working with Agentforce: only draft agents can be deployed, committed (published) agents are immutable. To deploy changes, first open Agentforce Studio and create a draft version of your agent, then you can deploy changes from VS Code. If you try to deploy to committed agent, you'll get an error message.
| Action | Draft Agent | Published Agent |
|---|---|---|
| Retrieve | ✅ | ✅ |
| Inspect | ✅ | ✅ |
| Edit Locally | ✅ | ✅ |
| Deploy Changes | ✅ | ❌ |
In practice, this means you can retrieve metadata from both draft and published agents, but deployment targets a draft version managed in Agentforce Builder.
Using Salesforce CLI makes it much easier to inspect AgentScript metadata, use version control, and work with Agentforce in a development workflow instead of only through the browser.
Useful links
Connect a Trailhead Org to Salesforce CLI guide.
Read more in the official documentation.

Top comments (0)