Sub topic 2
Setting up the Salesforce CLI for agent work
This chapter gets your machine ready for the sf agent commands used in the rest of the tutorial. It assumes you can use a terminal, know what a Salesforce DX project is (sfdx-project.json and a force-app folder), and have Node.js available. The next chapter covers authorizing an org.
What you need
Agentforce DX is not a separate tool. The agent commands are part of the Salesforce CLI (sf), supplied by the agent plugin, @salesforce/plugin-agent. Setup means three things:
- A current
sfCLI. - The agent plugin, which recent CLI versions include.
- A DX project to hold the agent's metadata and spec files.
Install and update the CLI
Install sf from the Salesforce developer site as an OS installer, or with npm:
npm install --global @salesforce/cliThen confirm the version and update to the latest release:
sf --version
sf updateAgent commands change quickly. If a flag in this tutorial is rejected, the first thing to try is sf update.
Check the agent plugin
List the installed plugins and look for the agent plugin:
sf plugins --coreIf @salesforce/plugin-agent does not appear, install it:
sf plugins install agentThen confirm that the commands exist:
sf agent --helpYou should see topics such as generate, create, preview, and test. These map directly to the chapters ahead.
Create a DX project
Agent files live in a normal DX project, so they can go into Git like any other metadata. Create one and initialize the repository:
sf project generate --name agent-workspace
cd agent-workspace
git init
mkdir specsThe specs folder will hold the spec and test YAML files. They are inputs to CLI commands, not deployable metadata, so keeping them outside force-app is a reasonable convention. Check that sfdx-project.json has a sourceApiVersion that your org supports. Agent metadata types need a recent API version.
Org prerequisites
The CLI can only create agents in an org that has Agentforce enabled. Before you go further, confirm with your admin that:
- Einstein generative AI and Agentforce are turned on in the target org.
- Your user holds the permissions needed to create and manage agents.
- You are working in a sandbox, scratch org, or Developer Edition org, not production.
Common setup errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `command sf not found` | CLI not on PATH | Reopen the terminal or fix PATH |
| `sf agent` shows no subcommands | Old CLI or missing plugin | Run `sf update`, then `sf plugins install agent` |
| Unknown flag error | CLI older than the tutorial | Run `sf update` and compare `sf agent create --help` |
| Plugin install fails behind a proxy | Network policy blocks npm | Set proxy variables or ask IT for access |
Verify the setup
A short script gives you a repeatable check, which is also useful in CI later:
#!/usr/bin/env bash
set -euo pipefail
sf --version
sf agent --help > /dev/null && echo "Agent commands available"
test -f sfdx-project.json && echo "DX project found"Exercise
You run sf agent create --help and get an error saying the command does not exist, but sf --version works. Which two commands do you run to fix it, and in what order?
Show answer
Run sf update first, because an older CLI may not include the agent plugin. If sf agent --help still shows no agent topic, run sf plugins install agent, then check again with sf agent --help.