Sub topic 4
Generating an agent spec with sf agent generate agent-spec
This chapter assumes you have the Salesforce CLI with the agent plugin installed and an authorized org, as covered in the earlier chapters. You should also be comfortable reading YAML.
What an agent spec is
An agent spec is a YAML file that describes the agent you want. It holds the agent type, its role, some company context, and a list of topics. The next command, sf agent create, reads this file and builds the agent in your org.
The spec is a draft. The CLI asks the org's generative AI service to propose topics from the text you provide. You then review and edit the file before anything is created.
Running the command
Authorize an org first. The org must have Agentforce and generative AI enabled, because topic suggestions are generated there.
sf org login web --alias my-dev-org
sf agent generate agent-spec \
--type customer \
--role "Answer questions about the status of customer support cases" \
--company-name "Acme Support" \
--company-description "Acme provides hardware and support plans" \
--output-file specs/caseAgentSpec.yaml \
--target-org my-dev-orgThe flags control the following:
| Flag | Purpose |
|---|---|
| `--type` | Agent type: `customer` (talks to your customers) or `internal` (talks to employees) |
| `--role` | One sentence describing what the agent does |
| `--company-name` | Name the agent uses when it describes the business |
| `--company-description` | Background that helps the AI pick relevant topics |
| `--output-file` | Where to write the YAML |
| `--target-org` | Org that generates the suggestions |
If you leave out required flags, the command prompts you for them. Pass --no-prompt in scripts so it fails instead of waiting for input. Run sf agent generate agent-spec --help to see the other options, such as a cap on the number of topics. Available flags depend on your plugin version.
Reading the generated file
The output looks like this. The topic names and descriptions come from the AI and will differ on each run.
agentType: customer
role: Answer questions about the status of customer support cases
companyName: Acme Support
companyDescription: Acme provides hardware and support plans
maxNumOfTopics: 5
topics:
- name: Case Status
description: Look up a support case and explain its current status
- name: Plan Information
description: Answer questions about hardware and support plansEach topic is a area of responsibility. Its description tells the agent when to use it, so vague wording leads to wrong topic choices later.
Editing before you create
Treat the review as a required step. Check these points:
- Remove topics outside the role. A case-status agent does not need a general sales topic.
- Make each description specific about what is in scope and what is not.
- Keep the topic count small. Fewer, clearer topics are easier to test.
- Confirm the role sentence matches what you want users to see.
Common errors
- The org is not found or not authorized. Run
sf org listand check that the alias in--target-orgmatches. - The command fails with a permissions or feature error. The user may lack access to Agentforce features, or the org may not have them enabled. This is covered in the authorization chapter.
- The output directory is missing. Create
specs/first if the CLI does not do it for you. - Topics are too generic. Improve the
--roleand--company-descriptiontext, then regenerate or edit by hand.
Exercise
You regenerated a spec into the same output file and lost your hand-edited topic descriptions. Name two practices that prevent this.
Show answer
Commit the reviewed spec to Git so you can restore it, and write each new draft to a different file name (or review the diff before accepting it). Generation is not deterministic, so reusing the same output path can overwrite edits.