@salesforce/afv-skills 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/package.json +4 -4
  2. package/skills/agentforce-development/SKILL.md +427 -0
  3. package/skills/agentforce-development/assets/README-legacy.md +89 -0
  4. package/skills/agentforce-development/assets/agent-spec-template.md +90 -0
  5. package/skills/agentforce-development/assets/agents/README.md +45 -0
  6. package/skills/agentforce-development/assets/agents/hello-world.agent +60 -0
  7. package/skills/agentforce-development/assets/agents/multi-topic.agent +105 -0
  8. package/skills/agentforce-development/assets/agents/production-faq.agent +101 -0
  9. package/skills/agentforce-development/assets/agents/production-faq.bundle-meta.xml +4 -0
  10. package/skills/agentforce-development/assets/agents/simple-qa.agent +72 -0
  11. package/skills/agentforce-development/assets/apex/models-api-queueable.cls +225 -0
  12. package/skills/agentforce-development/assets/bundle-meta.xml +23 -0
  13. package/skills/agentforce-development/assets/components/apex-action.agent +52 -0
  14. package/skills/agentforce-development/assets/components/error-handling.agent +58 -0
  15. package/skills/agentforce-development/assets/components/escalation-setup.agent +169 -0
  16. package/skills/agentforce-development/assets/components/flow-action.agent +66 -0
  17. package/skills/agentforce-development/assets/components/n-ary-conditions.agent +110 -0
  18. package/skills/agentforce-development/assets/components/topic-with-actions.agent +40 -0
  19. package/skills/agentforce-development/assets/deterministic-routing.agent +166 -0
  20. package/skills/agentforce-development/assets/escalation-pattern.agent +209 -0
  21. package/skills/agentforce-development/assets/flow-action-lookup.agent +115 -0
  22. package/skills/agentforce-development/assets/hub-and-spoke.agent +104 -0
  23. package/skills/agentforce-development/assets/invocable-apex-template.cls +187 -0
  24. package/skills/agentforce-development/assets/local-info-agent-annotated.agent +355 -0
  25. package/skills/agentforce-development/assets/metadata/basic-prompt-template.promptTemplate-meta.xml +109 -0
  26. package/skills/agentforce-development/assets/metadata/genai-function-apex.xml +92 -0
  27. package/skills/agentforce-development/assets/metadata/genai-function-flow.xml +57 -0
  28. package/skills/agentforce-development/assets/metadata/genai-plugin.xml +72 -0
  29. package/skills/agentforce-development/assets/metadata/http-callout-flow.flow-meta.xml +348 -0
  30. package/skills/agentforce-development/assets/metadata/record-grounded-prompt.promptTemplate-meta.xml +136 -0
  31. package/skills/agentforce-development/assets/minimal-starter.agent +42 -0
  32. package/skills/agentforce-development/assets/patterns/README.md +254 -0
  33. package/skills/agentforce-development/assets/patterns/action-callbacks.agent +178 -0
  34. package/skills/agentforce-development/assets/patterns/advanced-input-bindings.agent +141 -0
  35. package/skills/agentforce-development/assets/patterns/bidirectional-routing.agent +156 -0
  36. package/skills/agentforce-development/assets/patterns/critical-input-collection.agent +244 -0
  37. package/skills/agentforce-development/assets/patterns/delegation-routing.agent +89 -0
  38. package/skills/agentforce-development/assets/patterns/lifecycle-events.agent +127 -0
  39. package/skills/agentforce-development/assets/patterns/llm-controlled-actions.agent +184 -0
  40. package/skills/agentforce-development/assets/patterns/multi-step-workflow.agent +282 -0
  41. package/skills/agentforce-development/assets/patterns/open-gate-routing.agent +286 -0
  42. package/skills/agentforce-development/assets/patterns/procedural-instructions.agent +273 -0
  43. package/skills/agentforce-development/assets/patterns/prompt-template-action.agent +188 -0
  44. package/skills/agentforce-development/assets/patterns/system-instruction-overrides.agent +293 -0
  45. package/skills/agentforce-development/assets/prompt-rag-search.agent +131 -0
  46. package/skills/agentforce-development/assets/template-multi-topic.agent +160 -0
  47. package/skills/agentforce-development/assets/template-single-topic.agent +81 -0
  48. package/skills/agentforce-development/assets/verification-gate.agent +208 -0
  49. package/skills/agentforce-development/references/action-prompt-templates.md +164 -0
  50. package/skills/agentforce-development/references/actions-reference.md +592 -0
  51. package/skills/agentforce-development/references/agent-access-guide.md +72 -0
  52. package/skills/agentforce-development/references/agent-design-and-spec-creation.md +1010 -0
  53. package/skills/agentforce-development/references/agent-metadata-and-lifecycle.md +575 -0
  54. package/skills/agentforce-development/references/agent-script-core-language.md +1218 -0
  55. package/skills/agentforce-development/references/agent-topic-map-diagrams.md +323 -0
  56. package/skills/agentforce-development/references/agent-user-setup.md +526 -0
  57. package/skills/agentforce-development/references/agent-validation-and-debugging.md +803 -0
  58. package/skills/agentforce-development/references/known-issues.md +353 -0
  59. package/skills/agentforce-development/references/minimal-examples.md +67 -0
  60. package/skills/agentforce-development/references/production-gotchas.md +279 -0
  61. package/skills/agentforce-development/references/salesforce-cli-for-agents.md +393 -0
  62. package/skills/agentforce-development/references/version-history.md +23 -0
  63. package/skills/generate-permission-set/SKILL.md +174 -0
  64. package/skills/salesforce-custom-application/SKILL.md +1 -2
  65. package/skills/salesforce-custom-field/SKILL.md +0 -4
  66. package/skills/salesforce-custom-tab/SKILL.md +84 -8
  67. package/skills/salesforce-experience-lwr-site/SKILL.md +196 -0
  68. package/skills/salesforce-experience-lwr-site/docs/bootstrap-template-byo-lwr.md +224 -0
  69. package/skills/salesforce-experience-lwr-site/docs/configure-content-brandingSet.md +131 -0
  70. package/skills/salesforce-experience-lwr-site/docs/configure-content-route.md +232 -0
  71. package/skills/salesforce-experience-lwr-site/docs/configure-content-themeLayout.md +141 -0
  72. package/skills/salesforce-experience-lwr-site/docs/configure-content-view.md +233 -0
  73. package/skills/salesforce-experience-lwr-site/docs/configure-guest-sharing-rules.md +42 -0
  74. package/skills/salesforce-experience-lwr-site/docs/handle-component-and-region-ids.md +27 -0
  75. package/skills/salesforce-experience-lwr-site/docs/handle-ui-components.md +215 -0
  76. package/skills/salesforce-flow/SKILL.md +2 -2
  77. package/skills/salesforce-fragment/SKILL.md +85 -10
  78. package/skills/salesforce-lightning-app-build/SKILL.md +102 -10
  79. package/skills/apex-class/SKILL.md +0 -253
  80. package/skills/apex-class/examples/AccountDeduplicationBatch.cls +0 -148
  81. package/skills/apex-class/examples/AccountSelector.cls +0 -193
  82. package/skills/apex-class/examples/AccountService.cls +0 -201
  83. package/skills/apex-class/templates/abstract.cls +0 -128
  84. package/skills/apex-class/templates/batch.cls +0 -125
  85. package/skills/apex-class/templates/domain.cls +0 -102
  86. package/skills/apex-class/templates/dto.cls +0 -108
  87. package/skills/apex-class/templates/exception.cls +0 -51
  88. package/skills/apex-class/templates/interface.cls +0 -25
  89. package/skills/apex-class/templates/queueable.cls +0 -92
  90. package/skills/apex-class/templates/schedulable.cls +0 -75
  91. package/skills/apex-class/templates/selector.cls +0 -92
  92. package/skills/apex-class/templates/service.cls +0 -69
  93. package/skills/apex-class/templates/utility.cls +0 -97
  94. package/skills/apex-test-class/SKILL.md +0 -101
  95. package/skills/apex-test-class/references/assertion-patterns.md +0 -209
  96. package/skills/apex-test-class/references/async-testing.md +0 -276
  97. package/skills/apex-test-class/references/mocking-patterns.md +0 -219
  98. package/skills/apex-test-class/references/test-data-factory.md +0 -176
  99. package/skills/deployment-readiness-check/SKILL.md +0 -257
  100. package/skills/deployment-readiness-check/assets/deployment_checklist.md +0 -286
  101. package/skills/deployment-readiness-check/references/rollback_procedures.md +0 -308
  102. package/skills/deployment-readiness-check/scripts/check_metadata.sh +0 -207
  103. package/skills/salesforce-experience-site/SKILL.md +0 -178
@@ -0,0 +1,575 @@
1
+ # Agent Metadata and Lifecycle Reference
2
+
3
+ ## Table of Contents
4
+
5
+ 1. Agent Metadata Structure
6
+ 2. Agent Metadata Lifecycle Overview
7
+ 3. Creating an Agent
8
+ 4. Working With Authoring Bundles
9
+ 5. Publishing Authoring Bundles
10
+ 6. Activating Published Agents
11
+ 7. Lifecycle Operations
12
+
13
+ ---
14
+
15
+ ## 1. Agent Metadata Structure
16
+
17
+ Agent Script agents are defined across two independent metadata domains. Understanding this distinction is critical for every lifecycle operation.
18
+
19
+ ### Two-Domain Entity Graph
20
+
21
+ ```
22
+ AUTHORING DOMAIN (developer-owned, exists before any publish)
23
+ AiAuthoringBundle
24
+ ├── .agent (Agent Script source — editable text file)
25
+ └── .bundle-meta.xml (metadata; optional <target> links to published version)
26
+
27
+ RUNTIME DOMAIN (created by publish)
28
+ Bot (top-level container, one per agent)
29
+ └── BotVersion (one per published version)
30
+ └── GenAiPlannerBundle (versioned bundle, contains compiled agent definition)
31
+ └── local topics and actions (scoped to this version only)
32
+ ```
33
+
34
+ The authoring domain is where you work. The runtime domain is what the org creates when you publish. These two domains are separate until you publish, which is when they connect.
35
+ ### The Authoring Domain: AiAuthoringBundle
36
+
37
+ An `AiAuthoringBundle` is a Salesforce metadata source component represented as a directory in your local project containing two files:
38
+
39
+ **1. `.agent` file** — Agent Script source code. This is the editable text file where you define topics, actions, variables, and flow control. It is human-readable and supports multiple versions.
40
+
41
+ **2. `.bundle-meta.xml` file** — Metadata about the bundle. Contains a `bundleType` element set to `AGENT` and optionally a `<target>` element that controls whether the bundle is DRAFT (editable) or locked to a published version:
42
+
43
+ ```xml
44
+ <?xml version="1.0" encoding="UTF-8"?>
45
+ <AiAuthoringBundle xmlns="http://soap.sforce.com/2006/04/metadata">
46
+ <bundleType>AGENT</bundleType>
47
+ <target>Local_Info_Agent.v2</target>
48
+ </AiAuthoringBundle>
49
+ ```
50
+
51
+ When `<target>` is present, the bundle is locked to that published version and cannot be modified. Draft-state bundles omit `<target>` entirely.
52
+ Authoring bundles are stored in `<packageDirectory>/main/default/aiAuthoringBundles/` where `<packageDirectory>` comes from `sfdx-project.json`.
53
+ ### Two Forms of AiAuthoringBundle Locally
54
+
55
+ **Naked AiAuthoringBundle** (e.g., `Local_Info_Agent`) — No version suffix in the directory name. In the org, this always points to the highest DRAFT version. This is the only writable surface for pro-code developers.
56
+ **Version-suffixed AiAuthoringBundle** (e.g., `Local_Info_Agent_1`, `Local_Info_Agent_2`) — Published snapshots retrieved from the org after publication. Locked by a `<target>` element in their `bundle-meta.xml`. Read-only — modified deploys fail; unmodified deploys succeed as misleading no-ops. Use these for version history inspection, diffing, and auditing. NEVER edit a version-suffixed authoring bundle expecting your changes to persist.
57
+ ### The Runtime Domain: Bot → BotVersion → GenAiPlannerBundle
58
+
59
+ Publishing creates the runtime entities that make an agent usable in the org.
60
+
61
+ **Bot** — Top-level container (one per agent). Links to all published versions.
62
+
63
+ **BotVersion** — One per published version (e.g., `v1`, `v2`, `v3`). Only one version can be active at a time.
64
+
65
+ **GenAiPlannerBundle** — Compiled agent definition for a specific version. Contains topics, actions, and all runtime metadata, scoped to that version only.
66
+
67
+ Runtime entities are org-generated and never edited directly.
68
+ ### Agent Pseudo Metadata Type
69
+
70
+ When using the Salesforce CLI, `Agent:X` is a pseudo-metadata type that covers the runtime domain components: `Bot`, `BotVersion`, `GenAiPlannerBundle`, and related GenAiPlugin/GenAiFunction metadata. This saves you from specifying each type individually during retrieve/deploy.
71
+
72
+ **CRITICAL GOTCHA:** `Agent:X` retrieve does NOT include `AiAuthoringBundle`. If you need the authoring bundle (to see the `<target>` element or to work with the source), use `AiAuthoringBundle:X` explicitly.
73
+ ---
74
+
75
+ ## 2. Agent Metadata Lifecycle Overview
76
+
77
+ ### Recommended Pipeline
78
+
79
+ The end-to-end pipeline for creating and activating an agent:
80
+
81
+ 1. `sf agent generate authoring-bundle --json --no-spec --name "<Label>" --api-name <Developer_Name>`
82
+ 2. Edit the `.agent` file locally
83
+ 3. `sf project deploy start --json --metadata AiAuthoringBundle:<Developer_Name>`
84
+ 4. `sf agent validate authoring-bundle --json --api-name <Developer_Name>`
85
+ 5. `sf agent publish authoring-bundle --json --api-name <Developer_Name>`
86
+ 6. `sf agent activate --json --api-name <Bot_API_Name>`
87
+
88
+ Each phase is detailed in the sections that follow.
89
+ ### Lifecycle Phases
90
+
91
+ **Phase 1: Generate** — Create a boilerplate `AiAuthoringBundle` in your local project with `sf agent generate authoring-bundle`. The authoring bundle exists locally only; the org is unaffected. See Section 3.
92
+
93
+ **Phase 2: Deploy** — Push the `AiAuthoringBundle` to the org using `sf project deploy start`. This populates the authoring domain only — the authoring bundle becomes visible in Agent Builder (part of Agentforce Studio) for low-code authoring and preview. The `Bot` and `GenAiPlannerBundle` metadata entities are NOT created yet.
94
+
95
+ **Phase 3: Publish** — Compile the `AiAuthoringBundle` and create the full runtime entity graph with `sf agent publish authoring-bundle`. This populates the runtime domain: `Bot`, `BotVersion`, and `GenAiPlannerBundle` are created. See Section 5.
96
+
97
+ **Phase 4: Activate** — Make a published version live with `sf agent activate`. Only one version can be active at a time. Published agents must be activated before they can be previewed with `--api-name` or used in production. See Section 6.
98
+ **Phase 5: Test** — Create test specs (`sf agent test create`), run tests against the activated agent (`sf agent test run`), and check results (`sf agent test resume`). Tests run against activated published agents only — DRAFT authoring bundles cannot be tested. The `sf agent test create` command compiles an Agent Test Spec (YAML) into `AiEvaluationDefinition` metadata in the org. See Section 7 (Test Lifecycle).
99
+ ### Deploy vs. Publish: The Critical Distinction
100
+
101
+ These are two different operations that populate different domains.
102
+
103
+ **Deploy** (`sf project deploy start`): Metadata operation only. Puts the `AiAuthoringBundle` source file into the org's authoring domain. Does NOT create Bot, BotVersion, or GenAiPlannerBundle. The authoring bundle IS visible in Agentforce Studio for low-code users to edit and preview as a DRAFT. Deploy is a staging step — useful for pro-code/low-code collaboration where pro-code developers author locally and deploy to get the authoring bundle into Builder for low-code refinement.
104
+ **Publish** (`sf agent publish authoring-bundle`): Full entity creation. Deploys the `AiAuthoringBundle`, compiles Agent Script to Agent DSL, and creates the entire runtime entity graph (Bot + BotVersion + GenAiPlannerBundle + GenAiPlugins). Publish is self-contained — a brand-new `AiAuthoringBundle` can be published directly with no prior deploy or org state.
105
+
106
+ Mental model: the `AiAuthoringBundle` is the recipe; the runtime domain entities are the cooked dish; publish is the act of cooking. Deploy stages the recipe in the org's kitchen — publish actually cooks it.
107
+ ---
108
+
109
+ ## 3. Creating an Agent
110
+
111
+ Use the `sf agent generate authoring-bundle` command to create a new agent. This command requires three flags.
112
+
113
+ ### Command Syntax
114
+
115
+ ```bash
116
+ sf agent generate authoring-bundle --json --no-spec --name "<Label>" --api-name <Developer_Name>
117
+ ```
118
+
119
+ **Required flags:**
120
+
121
+ - `--json` — Always set first. Produces machine-readable output.
122
+
123
+ - `--no-spec` — This flag must be present, or the command hangs waiting for input.
124
+
125
+ - `--name "<Label>"` — The human-readable display name. This becomes `agent_label` in the Agent Script `config` block. Example: `"Local Info Agent"`. Wrap in quotes if the label contains spaces.
126
+
127
+ - `--api-name <Developer_Name>` — The unique API identifier (no spaces, letters/numbers/underscores only). This becomes `developer_name` in the `config` block. Example: `Local_Info_Agent`.
128
+ ### What the Command Creates
129
+
130
+ The command creates two files in a directory named after your `--api-name`:
131
+
132
+ ```
133
+ aiAuthoringBundles/
134
+ └── Local_Info_Agent/
135
+ ├── Local_Info_Agent.agent (editable source)
136
+ └── Local_Info_Agent.bundle-meta.xml (metadata)
137
+ ```
138
+
139
+ The `.agent` file contains boilerplate with `system`, `config`, `start_agent`, and placeholder topics. You edit this file to define your agent.
140
+
141
+ The `.bundle-meta.xml` file is initially minimal (bundleType only, no `<target>`), indicating DRAFT state.
142
+ ### Common Failure Modes with WRONG/RIGHT Pairs
143
+
144
+ **1. Omitting `--no-spec`**
145
+
146
+ ```bash
147
+ # WRONG — CLI waits for spec file (hangs)
148
+ sf agent generate authoring-bundle --json --name "Local Info Agent" --api-name Local_Info_Agent
149
+
150
+ # CORRECT — explicit --no-spec
151
+ sf agent generate authoring-bundle --json --no-spec --name "Local Info Agent" --api-name Local_Info_Agent
152
+ ```
153
+
154
+ Without `--no-spec`, the CLI expects interactive input. Always include `--no-spec`.
155
+ **2. Confusing `--name` and `--api-name`**
156
+
157
+ ```bash
158
+ # WRONG — swapped; produces invalid developer_name
159
+ sf agent generate authoring-bundle --json --no-spec \
160
+ --name Local_Info_Agent \
161
+ --api-name "Local Info Agent"
162
+
163
+ # CORRECT — name is human-readable (spaces OK), api-name is identifier
164
+ sf agent generate authoring-bundle --json --no-spec \
165
+ --name "Local Info Agent" \
166
+ --api-name Local_Info_Agent
167
+ ```
168
+
169
+ `--name` is the label (human-readable, can include spaces, goes in `agent_label`). `--api-name` is the developer name (identifier, no spaces, goes in `developer_name`).
170
+ ---
171
+
172
+ ## 4. Working With Authoring Bundles
173
+
174
+ This section covers the non-obvious behaviors and constraints of authoring bundles.
175
+
176
+ ### First Deploy Creates DRAFT V1
177
+
178
+ When you deploy an `AiAuthoringBundle` to an org for the first time (if it has never been published), the org creates DRAFT V1. This is your starting state. Subsequent deploys update this DRAFT. When you publish, V1 becomes locked and a new DRAFT is created for future edits.
179
+ ### The "Naked" AiAuthoringBundle Always Points to the Highest DRAFT
180
+
181
+ Your local agent directory (without a version suffix) represents the editable working copy in the org. In the org, this "naked" `AiAuthoringBundle` is always linked to the highest DRAFT version. When you deploy, you update this DRAFT. When you publish, a new DRAFT version is created for the next round of edits.
182
+ ### Version-Suffixed AiAuthoringBundles Are Frozen Snapshots
183
+
184
+ After you publish, version-suffixed authoring bundles appear in your local project (e.g., `Local_Info_Agent_1`, `Local_Info_Agent_2`). These are org-generated snapshots locked by a `<target>` element in their `bundle-meta.xml`:
185
+
186
+ ```xml
187
+ <AiAuthoringBundle xmlns="http://soap.sforce.com/2006/04/metadata">
188
+ <bundleType>AGENT</bundleType>
189
+ <target>Local_Info_Agent.v1</target>
190
+ </AiAuthoringBundle>
191
+ ```
192
+
193
+ The presence of `<target>` locks this authoring bundle to that specific published version. It is read-only. Modified deploys fail with an error like "content cannot be changed on a locked version." Unmodified deploys succeed as meaningless no-ops.
194
+
195
+ Use version-suffixed authoring bundles for auditing and diffing version history, NOT for editing. All edits must go through the naked `AiAuthoringBundle`.
196
+ ### No Pro-Code Way to Create New DRAFT Versions
197
+
198
+ Once a DRAFT version exists in the org, there is no CLI command to create additional DRAFT versions. The only way to create multiple DRAFTs is via Agentforce Studio's "create new DRAFT version" button on a published version. These additional DRAFTs can then be retrieved with their version number.
199
+
200
+ In pro-code workflows, you have one DRAFT per agent at any given time. The DRAFT evolves: you deploy, the DRAFT updates. You publish, the DRAFT becomes locked. You deploy again, a new DRAFT is created.
201
+ ### Deploy-Before-Publish Is Legitimate (For Pro-Code/Low-Code Collaboration)
202
+
203
+ Deploy-before-publish is the foundation for pro-code/low-code collaboration:
204
+
205
+ 1. Pro-code developer authors Agent Script locally
206
+ 2. Pro-code developer deploys the authoring bundle (no publish step)
207
+ 3. Low-code user opens the authoring bundle in Agentforce Studio and refines it
208
+ 4. Low-code user saves changes
209
+ 5. Pro-code developer retrieves the updated authoring bundle and continues
210
+
211
+ Deploy/retrieve are one-way overwrites with no sync warnings. This is by design for cross-tool collaboration.
212
+ ### NEVER Deploy `AiAuthoringBundle` in Routine Backing-Code Operations
213
+
214
+ When deploying backing code (Apex, Flows, Prompt Templates), NEVER include agent metadata (`.agent` files or `AiAuthoringBundle` metadata) unless you explicitly intend to update the agent.
215
+
216
+ Accidental deployment of an outdated authoring bundle will overwrite in-progress work in the org.
217
+ ### `default_agent_user` Configuration: Immutable and Restricted
218
+
219
+ The `default_agent_user` field in your Agent Script `config` block must reference a Salesforce user with the "Einstein Agent" license type. Standard Salesforce-licensed users, even System Administrators, will fail at publish time with a misleading error message: "Internal Error, try again later."
220
+
221
+ This error message does NOT indicate a license issue — it masks the true problem.
222
+
223
+ To find a valid user, query the org for active users with the Einstein Agent license:
224
+
225
+ ```bash
226
+ sf data query --json -q "SELECT Username FROM User WHERE Profile.UserLicense.Name = 'Einstein Agent' AND IsActive = true LIMIT 5"
227
+ ```
228
+
229
+ `default_agent_user` can be changed after publish, but only while no published version is activated. Deactivate the agent before changing `default_agent_user`, then republish and reactivate.
230
+ ### Two Validation Layers: Compile vs. API Validation
231
+
232
+ The CLI `sf agent validate authoring-bundle` checks syntax and Agent Script compilation only. It does NOT validate `default_agent_user` or backing logic references.
233
+
234
+ API validation runs during `sf agent publish` and in Agentforce Studio. This is where `default_agent_user` license requirements are checked and backing logic references are fully validated.
235
+
236
+ The result: A developer can validate successfully and still fail at publish due to invalid `default_agent_user` or missing backing logic.
237
+ ### Deploy Validates Backing Logic via Invocable Action Registry Lookup
238
+
239
+ When you deploy an `AiAuthoringBundle`, the deployment process validates that every backing logic reference (Apex class, Flow, Prompt Template) resolves to a registered Invocable Action in the org. The referenced class or flow or prompt must exist.
240
+
241
+ For Apex classes, the class must have an `@InvocableMethod`-annotated method.
242
+
243
+ **Critical gap:** Deploy validation does NOT check parameter names, types, return types, or whether the method has the correct number of parameters. Stub classes with `@InvocableMethod` are sufficient to unblock deployment.
244
+
245
+ This means you can deploy an authoring bundle with completely wrong I/O definitions and not discover the problem until conversation or preview. Parameter mismatches are caught only at runtime.
246
+
247
+ A minimal stub class with `@InvocableMethod` unblocks pro-code/low-code collaboration, but defers type validation to runtime.
248
+ ### Server-Side `AiAuthoringBundle` Filename Versioning
249
+
250
+ When deploying a local authoring bundle (`Local_Info_Agent.agent`), the server uses a version-suffixed filename (`Local_Info_Agent_4.agent`), triggering a CLI warning:
251
+
252
+ ```
253
+ "AiAuthoringBundle, Local_Info_Agent_4.agent, returned from org, but not found in the local project"
254
+ ```
255
+
256
+ This is not an error — it's normal behavior. It reflects the "naked `AiAuthoringBundle` = highest DRAFT" behavior. The warning is misleading but harmless.
257
+ ### Post-Publish Workflow Is Seamless
258
+
259
+ After publishing, your local source remains unchanged. The `bundle-meta.xml` does NOT get `<target>` set automatically. You can immediately continue editing the `.agent` file and deploy again. The platform auto-creates a new DRAFT version on the server.
260
+
261
+ The intended workflow is: publish → keep editing → deploy (auto-creates new DRAFT).
262
+ ### Edge Case: Retrieve After Publish Locks the Authoring Bundle
263
+
264
+ If you explicitly retrieve the authoring bundle after publishing (e.g., `sf project retrieve start --json --metadata AiAuthoringBundle:Local_Info_Agent`), the retrieved `bundle-meta.xml` WILL have `<target>` set, locking the authoring bundle to that published version. Subsequent deploys with content changes fail.
265
+
266
+ Recovery: Remove `<target>` from `bundle-meta.xml` and deploy. This unlocks the authoring bundle and allows new edits.
267
+
268
+ This edge case only happens if you retrieve after publish. Normal post-publish workflows (just keep editing and deploying) never trigger this behavior.
269
+ ---
270
+
271
+ ## 5. Publishing Authoring Bundles
272
+
273
+ Publishing converts an agent's design (Agent Script in an `AiAuthoringBundle`) into its runtime existence (Bot, BotVersion, GenAiPlannerBundle). It is self-contained and can be done with no prior deploy.
274
+
275
+ ### Why Publishing Is Needed
276
+
277
+ Deploy alone puts the authoring bundle source into the org but does NOT create the runtime entity graph. A published agent cannot be previewed with `--api-name` until it is activated.
278
+
279
+ Publishing compiles the `AiAuthoringBundle` to Agent DSL and creates Bot, BotVersion, and GenAiPlannerBundle. After activation, the agent becomes usable for preview and runtime.
280
+ ### Publish Is Self-Contained
281
+
282
+ You do NOT need to deploy first. A brand-new authoring bundle can be published directly:
283
+
284
+ ```bash
285
+ sf agent generate authoring-bundle --json --no-spec --name "Local Info Agent" --api-name Local_Info_Agent
286
+ # Edit Local_Info_Agent.agent ...
287
+ sf agent publish authoring-bundle --json --api-name Local_Info_Agent
288
+ ```
289
+
290
+ Publish handles the initial deploy, compilation, and entity creation in one step. The simplest pipeline is: generate → edit → validate → publish → activate.
291
+ ### Command Syntax
292
+
293
+ ```bash
294
+ sf agent publish authoring-bundle --json --api-name <Developer_Name>
295
+ ```
296
+
297
+ The `--api-name` is the directory name under `aiAuthoringBundles/` (the `developer_name` from your config block).
298
+ ### What Metadata Gets Created
299
+
300
+ When you publish, the org creates:
301
+
302
+ - **Bot** — Top-level container (one per agent)
303
+ - **BotVersion** — Versioned instance (e.g., `v1`, `v2`, `v3`)
304
+ - **GenAiPlannerBundle** — Compiled agent definition for this version of the agent, with a `localActions/` directory containing topic-scoped action definitions.
305
+
306
+ Example directory structure after publishing:
307
+
308
+ ```
309
+ bots/
310
+ └── Local_Info_Agent/
311
+ ├── Local_Info_Agent.bot-meta.xml
312
+ ├── v1.botVersion-meta.xml
313
+ ├── v2.botVersion-meta.xml
314
+ └── v3.botVersion-meta.xml
315
+ genAiPlannerBundles/
316
+ ├── Local_Info_Agent_v1/
317
+ │ ├── localActions/
318
+ │ └── Local_Info_Agent_v1.genAiPlannerBundle
319
+ ├── Local_Info_Agent_v2/
320
+ │ ├── localActions/
321
+ │ └── Local_Info_Agent_v2.genAiPlannerBundle
322
+ └── Local_Info_Agent_v3/
323
+ ├── localActions/
324
+ └── Local_Info_Agent_v3.genAiPlannerBundle
325
+ ```
326
+
327
+ These are separate top-level directories. Each publish adds a BotVersion and a version-named GenAiPlannerBundle subdirectory. All are org-generated and read-only.
328
+ ### Multiple Published Versions Accumulate
329
+
330
+ Each publish creates a new version. Older versions remain in the org but become inactive. You can have v1, v2, v3, etc. coexisting.
331
+
332
+ After first publish: `v1.botVersion-meta.xml` and `Local_Info_Agent_v1.genAiPlannerBundle` exist.
333
+ After second publish: `v2.botVersion-meta.xml` and `Local_Info_Agent_v2.genAiPlannerBundle` exist. (v1 still exists but is inactive.)
334
+
335
+ This is version inflation — versions accumulate whether content changed or not (when no existing DRAFT exists on server).
336
+ ### Gotcha: Publish Response Lacks Version Number
337
+
338
+ The `sf agent publish authoring-bundle` response does NOT tell you which version number was created. You must retrieve with `AiAuthoringBundle:` (NOT `Agent:`) to see what version was published:
339
+
340
+ ```bash
341
+ sf project retrieve start --json --metadata AiAuthoringBundle:Local_Info_Agent
342
+ ```
343
+
344
+ Examine the returned `bundle-meta.xml` to see the `<target>` version (e.g., `Local_Info_Agent.v2`).
345
+ ### The `Agent` Pseudo-Type Retrieves Runtime Metadata Only
346
+
347
+ Retrieving with `Agent:Local_Info_Agent` returns the runtime entity graph: `Bot`, `BotVersion`, and `GenAiPlannerBundle` metadata. It does not include `AiAuthoringBundle` metadata.
348
+
349
+ To retrieve the authoring bundle (e.g., to inspect `<target>` after publish), use the `AiAuthoringBundle` metadata type directly:
350
+
351
+ ```bash
352
+ sf project retrieve start --json --metadata AiAuthoringBundle:Local_Info_Agent
353
+ ```
354
+ ### Troubleshooting Publish Failures
355
+
356
+ When `sf agent publish authoring-bundle` fails, run these checks in order. Stop at the first failure and fix it before continuing.
357
+
358
+ #### 1. Validate `default_agent_user`
359
+
360
+ Read `agent_type` and `default_agent_user` from the `.agent` config block, then validate based on agent type:
361
+
362
+ **If `agent_type` is `AgentforceEmployeeAgent`:** `default_agent_user` must NOT be present. If it is set, remove the entire line.
363
+
364
+ **If `agent_type` is `AgentforceServiceAgent`:** `default_agent_user` must be present. Query the org for the specified username:
365
+
366
+ ```bash
367
+ sf data query --json -q "SELECT Username, IsActive, Profile.UserLicense.Name FROM User WHERE Username = '<default_agent_user_value>'"
368
+ ```
369
+
370
+ - No results → user does not exist. Set a valid username.
371
+ - `IsActive` is false → reactivate the user or set a different username.
372
+ - `Profile.UserLicense.Name` is not `"Einstein Agent"` → wrong license. Set a user with the Einstein Agent license.
373
+
374
+ #### 2. Verify all backing logic is deployed
375
+
376
+ Every `target` in the `.agent` file must resolve to a registered backing logic component in the org. Redeploy all backing logic:
377
+
378
+ ```bash
379
+ sf project deploy start --json --metadata ApexClass Flow PromptTemplate
380
+ ```
381
+
382
+ If deploy reports unresolved references, identify and deploy the missing components before retrying publish. For Apex-backed actions, the class must have an `@InvocableMethod`-annotated method — a class without the annotation produces the same error as a missing class.
383
+
384
+ #### 3. Inspect `bundle-meta.xml` for a stale `<target>` lock
385
+
386
+ Open the authoring bundle's `bundle-meta.xml` and check for a `<target>` element:
387
+
388
+ ```xml
389
+ <!-- If this element is present, the bundle is locked -->
390
+ <target>Developer_Name.v2</target>
391
+ ```
392
+
393
+ Remove the entire `<target>` line, save, and redeploy before publishing again.
394
+
395
+ #### 4. Deactivate any active version, then republish
396
+
397
+ ```bash
398
+ sf agent deactivate --json --api-name <Bot_API_Name>
399
+ sf agent publish authoring-bundle --json --api-name <Developer_Name>
400
+ ```
401
+
402
+ #### 5. If all checks pass and publish still fails, escalate to the human
403
+
404
+ State which checks you ran and what each returned.
405
+
406
+ ---
407
+
408
+ ## 6. Activating Published Agents
409
+
410
+ After publishing, the agent exists but is inactive. Activation makes a published version live for preview, runtime access, and testing.
411
+
412
+ ### Activation Commands
413
+
414
+ ```bash
415
+ # Activate a specific published version
416
+ sf agent activate --json --api-name <Bot_API_Name>
417
+
418
+ # Deactivate (take a version offline without deleting it)
419
+ sf agent deactivate --json --api-name <Bot_API_Name>
420
+ ```
421
+
422
+ The `--api-name` is the Bot's API name (from your Agent Script `config` block's `developer_name`).
423
+ ### Activation Requirements
424
+
425
+ Only one published version can be active at a time. Activating a new version automatically deactivates the previous one. Running `sf agent preview start --api-name <Bot_API_Name>` requires the Bot to have an activated version. If no version is activated, attempting to start a preview with `--api-name` fails.
426
+ ### Agent Test Execution Requires an Activated Agent
427
+
428
+ Tests run against activated published agents only. If you try to run a test against an unpublished or inactive agent, it fails.
429
+ ---
430
+
431
+ ## 7. Lifecycle Operations
432
+
433
+ This section consolidates CLI commands for deploy, retrieve, delete, rename, test execution, and opening in Builder.
434
+
435
+ ### Deploy
436
+
437
+ Deploy puts the `AiAuthoringBundle` into the org as metadata. It does NOT create runtime entities.
438
+
439
+ **Deploy action-backing code only:**
440
+
441
+ ```bash
442
+ sf project deploy start --json --metadata ApexClass Flow
443
+ ```
444
+
445
+ Use `--metadata` to scope routine deploys to backing code. A bare `sf project deploy start` deploys all changed local metadata, including agent metadata.
446
+
447
+ **Deploy agent metadata (pro-code/low-code collaboration):**
448
+
449
+ ```bash
450
+ sf project deploy start --json --metadata AiAuthoringBundle:Local_Info_Agent
451
+ ```
452
+
453
+ Explicitly including agent metadata is useful when collaborating with low-code users in Agentforce Studio.
454
+ ### Retrieve
455
+
456
+ Retrieve pulls metadata from the org to your local project.
457
+
458
+ **Retrieve authoring bundle (highest version):**
459
+
460
+ ```bash
461
+ sf project retrieve start --json --metadata AiAuthoringBundle:Local_Info_Agent
462
+ ```
463
+
464
+ This retrieves the authoring bundle source files (`.agent` and `.bundle-meta.xml`). Use this to see the `<target>` element or to get the latest source from the org.
465
+
466
+ **Retrieve authoring bundles (all versions):**
467
+
468
+ ```bash
469
+ sf project retrieve start --json --metadata "AiAuthoringBundle:Local_Info_Agent_*"
470
+ ```
471
+
472
+ The wildcard `*` retrieves every version of an authoring bundle (e.g., `Local_Info_Agent_1`, `Local_Info_Agent_2`). Without the wildcard, only the naked `AiAuthoringBundle` is returned.
473
+
474
+ Use this pattern to inspect/compare different versions of an authoring bundle.
475
+ **Retrieve runtime metadata with the `Agent` pseudo-type:**
476
+
477
+ ```bash
478
+ sf project retrieve start --json --metadata Agent:Local_Info_Agent
479
+ ```
480
+
481
+ The `Agent` pseudo-type retrieves Bot, BotVersion, GenAiPlannerBundle, and GenAiPlugin — the full runtime entity graph. It does not include `AiAuthoringBundle`. Use the `AiAuthoringBundle` metadata type directly when you need source files.
482
+ ### Delete
483
+
484
+ Deletion behavior differs based on whether the agent has been published.
485
+
486
+ **Delete unpublished authoring bundle:**
487
+
488
+ ```bash
489
+ sf project delete source --json --metadata AiAuthoringBundle:Local_Info_Agent
490
+ ```
491
+
492
+ This works for DRAFT-only agents that have never been published.
493
+
494
+ **Published agents cannot be deleted via CLI:**
495
+
496
+ Published agents cannot be deleted via the Metadata API due to circular dependencies between metadata types. There is no CLI path to delete a published NGA agent. Cleanup requires the Salesforce Setup UI or scratch org expiration.
497
+
498
+ Use unique names for test agents to avoid collisions.
499
+ **Backing Code Deletion Enforcement:**
500
+
501
+ The org tracks dependencies between `AiAuthoringBundle` versions and their backing Apex classes. Attempting to delete a backing class while any version references it fails with a dependency error.
502
+
503
+ To delete a backing class:
504
+
505
+ 1. Update the authoring bundle to remove the reference
506
+ 2. Deploy the updated authoring bundle
507
+ 3. Delete the backing class
508
+ ### Rename
509
+
510
+ Renaming is hazardous due to the metadata hierarchy. The platform creates dependencies between `AiAuthoringBundle` names and published versions.
511
+
512
+ Do not attempt an in-place rename. Create a new agent with the desired name and migrate content. Document the old agent as deprecated and schedule deletion after a grace period.
513
+
514
+ ### Test Lifecycle
515
+
516
+ Agent testing requires a test spec (YAML), which gets compiled into `AiEvaluationDefinition` metadata in the org. Test specs are NOT Salesforce metadata — they are local YAML files that the CLI uses as input.
517
+
518
+ **Test spec location:** `specs/` directory at the SFDX project root (not inside a package directory).
519
+
520
+ **Create a test spec from the skill template:**
521
+
522
+ Copy the test spec template from the **agentforce-testing** skill to `specs/<Agent_API_Name>-testSpec.yaml` in the user's SFDX project. Update `name`, `description`, `subjectName`, and `testCases` to match the agent being tested.
523
+
524
+ Do NOT use `sf agent generate test-spec` to create a new test spec. This command requires interactive input and cannot be used programmatically. It can reverse-engineer a test spec from an existing `AiEvaluationDefinition` when supplied with the `--from-definition` flag:
525
+
526
+ ```bash
527
+ sf agent generate test-spec --from-definition force-app/main/default/aiEvaluationDefinitions/Local_Info_Agent_Test.aiEvaluationDefinition-meta.xml --output-file specs/Local_Info_Agent-testSpec.yaml
528
+ ```
529
+
530
+ **Create the test in the org:**
531
+
532
+ ```bash
533
+ sf agent test create --json --spec specs/Local_Info_Agent-testSpec.yaml --api-name Local_Info_Agent_Test --force-overwrite
534
+ ```
535
+
536
+ This compiles the test spec YAML into `AiEvaluationDefinition` metadata and automatically deploys it to the target org. The `--force-overwrite` flag ensures the CLI does not enter interactive mode if an `AiEvaluationDefinition` with the same `--api-name` already exists. Use `--preview` to generate the `AiEvaluationDefinition` locally without deploying to the org.
537
+
538
+ Iterating on a test spec is a common workflow: edit the YAML, re-run `sf agent test create` with the same `--api-name` and `--force-overwrite`, then run the test again.
539
+
540
+ A local test spec YAML does NOT mean the test exists in the org. You must run `sf agent test create` before you can run the test.
541
+
542
+ **Run tests:**
543
+
544
+ ```bash
545
+ sf agent test run --json --api-name Local_Info_Agent_Test --wait 5
546
+ ```
547
+
548
+ The `--api-name` is the `AiEvaluationDefinition` name (set by `--api-name` during `sf agent test create`). The `--wait 5` flag forces synchronous execution with a 5-minute timeout — the command blocks until the test completes or times out. Without `--wait`, the command returns a job ID immediately and the agent must poll `sf agent test results` for completion. Tests run against activated published agents only.
549
+
550
+ **Check test results (async fallback):**
551
+
552
+ ```bash
553
+ sf agent test results --json --job-id <JOB_ID>
554
+ ```
555
+
556
+ Only needed if `--wait` was not used or the wait timed out. Use the job ID from the `sf agent test run` response.
557
+ ### Open in Builder
558
+
559
+ These commands launch the user's local browser to Agentforce Studio. Do NOT use `--json` with these commands — JSON mode outputs the target URL but does not open the browser.
560
+
561
+ **View all authoring bundles:**
562
+
563
+ ```bash
564
+ sf org open authoring-bundle
565
+ ```
566
+
567
+ Opens Agentforce Studio showing all authoring bundles in the org.
568
+
569
+ **View a specific published agent:**
570
+
571
+ ```bash
572
+ sf org open agent --api-name <Bot_API_Name>
573
+ ```
574
+
575
+ Opens the published agent in Agentforce Studio. Only works for published agents. Unpublished (DRAFT-only) authoring bundles must be opened via `sf org open authoring-bundle`.