Sub topic 2
Creating and Iterating on an Agent with Salesforce CLI
Assume you have a Salesforce DX project, an authorized org, and a reviewed agent spec. An agent uses topics to group user goals, instructions to guide behavior, and actions to perform work.
Create the agent
Run sf agent create with the API name, spec file, and target org:
sf agent create \
--name "Case Helper" \
--api-name Case_Helper \
--spec specs/caseAgentSpec.yaml \
--target-org my-dev-orgThe command creates the agent and related metadata in the org. The API name is the stable identifier used by later commands. Keep it consistent with test specifications and deployment scripts.
Preview conversations
Preview the agent from your terminal before writing formal tests:
sf agent preview --api-name Case_Helper --target-org my-dev-orgEnter realistic questions, such as “What is the status of case 00001026?” Check whether the agent selects the expected topic, requests missing information, and calls the correct action. Previewing is interactive exploration, so it does not replace repeatable tests.
Retrieve, deploy, and version metadata
After creation, retrieve the agent metadata into your project and commit the result with Git:
sf project retrieve start \
--source-dir force-app/main/default \
--target-org my-dev-org
git add force-app specs
git commit -m "Add Case Helper agent"To move reviewed changes to another org, deploy the source:
sf project deploy start \
--source-dir force-app/main/default \
--target-org my-dev-orgSource control gives you reviewable history and a repeatable path between development, testing, and production orgs.
Topics and actions
A topic describes a category of user intent. An action is an operation the agent can invoke. Actions may be built-in Salesforce capabilities, Flow actions, or custom invocable Apex methods. Give each action a precise label and description so topic instructions can select it reliably.
Exercise
Why should you preview an agent before deploying metadata to another org?
Show answer
Previewing exposes incorrect topic or action selection while the change is still easy to revise.