@salesforce/afv-skills 1.6.9 → 1.7.1

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 (94) hide show
  1. package/README.md +28 -23
  2. package/package.json +1 -1
  3. package/skills/developing-agentforce/README.md +112 -0
  4. package/skills/{agentforce-development → developing-agentforce}/SKILL.md +109 -16
  5. package/skills/{agentforce-development → developing-agentforce}/assets/agents/README.md +2 -2
  6. package/skills/developing-agentforce/assets/agents/order-service.agent +272 -0
  7. package/skills/developing-agentforce/assets/agents/verification-gate.agent +280 -0
  8. package/skills/{agentforce-development → developing-agentforce}/assets/bundle-meta.xml +1 -1
  9. package/skills/{agentforce-development → developing-agentforce}/references/actions-reference.md +20 -0
  10. package/skills/{agentforce-development → developing-agentforce}/references/agent-design-and-spec-creation.md +1 -1
  11. package/skills/{agentforce-development → developing-agentforce}/references/agent-metadata-and-lifecycle.md +3 -3
  12. package/skills/{agentforce-development → developing-agentforce}/references/agent-script-core-language.md +40 -3
  13. package/skills/{agentforce-development → developing-agentforce}/references/agent-user-setup.md +60 -57
  14. package/skills/{agentforce-development → developing-agentforce}/references/agent-validation-and-debugging.md +22 -20
  15. package/skills/developing-agentforce/references/architecture-patterns.md +158 -0
  16. package/skills/developing-agentforce/references/complex-data-types.md +57 -0
  17. package/skills/developing-agentforce/references/deploy-reference.md +134 -0
  18. package/skills/developing-agentforce/references/discover-reference.md +102 -0
  19. package/skills/developing-agentforce/references/examples.md +350 -0
  20. package/skills/developing-agentforce/references/feature-validity.md +43 -0
  21. package/skills/developing-agentforce/references/instruction-resolution.md +545 -0
  22. package/skills/{agentforce-development → developing-agentforce}/references/known-issues.md +18 -18
  23. package/skills/{agentforce-development → developing-agentforce}/references/production-gotchas.md +24 -3
  24. package/skills/developing-agentforce/references/safety-review-reference.md +145 -0
  25. package/skills/{agentforce-development → developing-agentforce}/references/salesforce-cli-for-agents.md +9 -7
  26. package/skills/developing-agentforce/references/scaffold-reference.md +153 -0
  27. package/skills/developing-agentforce/references/scoring-rubric.md +24 -0
  28. package/skills/{agentforce-development → developing-agentforce}/references/version-history.md +2 -2
  29. package/skills/generating-flow/SKILL.md +3 -1
  30. package/skills/observing-agentforce/SKILL.md +368 -0
  31. package/skills/observing-agentforce/apex/AgentforceOptimizeService.cls +1262 -0
  32. package/skills/observing-agentforce/apex/AgentforceOptimizeService.cls-meta.xml +5 -0
  33. package/skills/observing-agentforce/references/improve-reference.md +359 -0
  34. package/skills/observing-agentforce/references/issue-classification.md +220 -0
  35. package/skills/observing-agentforce/references/reproduce-reference.md +131 -0
  36. package/skills/observing-agentforce/references/stdm-queries.md +381 -0
  37. package/skills/observing-agentforce/references/stdm-schema.md +189 -0
  38. package/skills/testing-agentforce/SKILL.md +335 -0
  39. package/skills/testing-agentforce/assets/basic-test-spec.yaml +59 -0
  40. package/skills/testing-agentforce/assets/guardrail-test-spec.yaml +101 -0
  41. package/skills/testing-agentforce/assets/standard-test-spec.yaml +123 -0
  42. package/skills/testing-agentforce/references/action-execution.md +241 -0
  43. package/skills/testing-agentforce/references/batch-testing.md +274 -0
  44. package/skills/testing-agentforce/references/preview-testing.md +353 -0
  45. package/skills/testing-agentforce/references/test-report-format.md +160 -0
  46. package/skills/testing-agentforce/references/troubleshooting.md +73 -0
  47. /package/skills/{agentforce-development → developing-agentforce}/assets/README-legacy.md +0 -0
  48. /package/skills/{agentforce-development → developing-agentforce}/assets/agent-spec-template.md +0 -0
  49. /package/skills/{agentforce-development → developing-agentforce}/assets/agents/hello-world.agent +0 -0
  50. /package/skills/{agentforce-development → developing-agentforce}/assets/agents/multi-topic.agent +0 -0
  51. /package/skills/{agentforce-development → developing-agentforce}/assets/agents/production-faq.agent +0 -0
  52. /package/skills/{agentforce-development → developing-agentforce}/assets/agents/production-faq.bundle-meta.xml +0 -0
  53. /package/skills/{agentforce-development → developing-agentforce}/assets/agents/simple-qa.agent +0 -0
  54. /package/skills/{agentforce-development → developing-agentforce}/assets/apex/models-api-queueable.cls +0 -0
  55. /package/skills/{agentforce-development → developing-agentforce}/assets/components/apex-action.agent +0 -0
  56. /package/skills/{agentforce-development → developing-agentforce}/assets/components/error-handling.agent +0 -0
  57. /package/skills/{agentforce-development → developing-agentforce}/assets/components/escalation-setup.agent +0 -0
  58. /package/skills/{agentforce-development → developing-agentforce}/assets/components/flow-action.agent +0 -0
  59. /package/skills/{agentforce-development → developing-agentforce}/assets/components/n-ary-conditions.agent +0 -0
  60. /package/skills/{agentforce-development → developing-agentforce}/assets/components/topic-with-actions.agent +0 -0
  61. /package/skills/{agentforce-development → developing-agentforce}/assets/deterministic-routing.agent +0 -0
  62. /package/skills/{agentforce-development → developing-agentforce}/assets/escalation-pattern.agent +0 -0
  63. /package/skills/{agentforce-development → developing-agentforce}/assets/flow-action-lookup.agent +0 -0
  64. /package/skills/{agentforce-development → developing-agentforce}/assets/hub-and-spoke.agent +0 -0
  65. /package/skills/{agentforce-development → developing-agentforce}/assets/invocable-apex-template.cls +0 -0
  66. /package/skills/{agentforce-development → developing-agentforce}/assets/local-info-agent-annotated.agent +0 -0
  67. /package/skills/{agentforce-development → developing-agentforce}/assets/metadata/basic-prompt-template.promptTemplate-meta.xml +0 -0
  68. /package/skills/{agentforce-development → developing-agentforce}/assets/metadata/genai-function-apex.xml +0 -0
  69. /package/skills/{agentforce-development → developing-agentforce}/assets/metadata/genai-function-flow.xml +0 -0
  70. /package/skills/{agentforce-development → developing-agentforce}/assets/metadata/genai-plugin.xml +0 -0
  71. /package/skills/{agentforce-development → developing-agentforce}/assets/metadata/http-callout-flow.flow-meta.xml +0 -0
  72. /package/skills/{agentforce-development → developing-agentforce}/assets/metadata/record-grounded-prompt.promptTemplate-meta.xml +0 -0
  73. /package/skills/{agentforce-development → developing-agentforce}/assets/minimal-starter.agent +0 -0
  74. /package/skills/{agentforce-development → developing-agentforce}/assets/patterns/README.md +0 -0
  75. /package/skills/{agentforce-development → developing-agentforce}/assets/patterns/action-callbacks.agent +0 -0
  76. /package/skills/{agentforce-development → developing-agentforce}/assets/patterns/advanced-input-bindings.agent +0 -0
  77. /package/skills/{agentforce-development → developing-agentforce}/assets/patterns/bidirectional-routing.agent +0 -0
  78. /package/skills/{agentforce-development → developing-agentforce}/assets/patterns/critical-input-collection.agent +0 -0
  79. /package/skills/{agentforce-development → developing-agentforce}/assets/patterns/delegation-routing.agent +0 -0
  80. /package/skills/{agentforce-development → developing-agentforce}/assets/patterns/lifecycle-events.agent +0 -0
  81. /package/skills/{agentforce-development → developing-agentforce}/assets/patterns/llm-controlled-actions.agent +0 -0
  82. /package/skills/{agentforce-development → developing-agentforce}/assets/patterns/multi-step-workflow.agent +0 -0
  83. /package/skills/{agentforce-development → developing-agentforce}/assets/patterns/open-gate-routing.agent +0 -0
  84. /package/skills/{agentforce-development → developing-agentforce}/assets/patterns/procedural-instructions.agent +0 -0
  85. /package/skills/{agentforce-development → developing-agentforce}/assets/patterns/prompt-template-action.agent +0 -0
  86. /package/skills/{agentforce-development → developing-agentforce}/assets/patterns/system-instruction-overrides.agent +0 -0
  87. /package/skills/{agentforce-development → developing-agentforce}/assets/prompt-rag-search.agent +0 -0
  88. /package/skills/{agentforce-development → developing-agentforce}/assets/template-multi-topic.agent +0 -0
  89. /package/skills/{agentforce-development → developing-agentforce}/assets/template-single-topic.agent +0 -0
  90. /package/skills/{agentforce-development → developing-agentforce}/assets/verification-gate.agent +0 -0
  91. /package/skills/{agentforce-development → developing-agentforce}/references/action-prompt-templates.md +0 -0
  92. /package/skills/{agentforce-development → developing-agentforce}/references/agent-access-guide.md +0 -0
  93. /package/skills/{agentforce-development → developing-agentforce}/references/agent-topic-map-diagrams.md +0 -0
  94. /package/skills/{agentforce-development → developing-agentforce}/references/minimal-examples.md +0 -0
@@ -0,0 +1,368 @@
1
+ ---
2
+ name: observing-agentforce
3
+ description: "Analyze production Agentforce agent behavior using session traces and Data Cloud. TRIGGER when: user queries STDM session data or Data Cloud trace records; investigates production agent failures, regressions, or performance issues; asks about session traces, conversation logs, or agent metrics; wants to reproduce a reported production issue in preview; runs findSessions or trace analysis queries. DO NOT TRIGGER when: user creates, modifies, or debugs .agent files during development (use developing-agentforce); writes or runs test specs (use testing-agentforce); uses sf agent preview for local development iteration; deploys or publishes agents."
4
+ allowed-tools: Bash Read Write Edit Glob Grep
5
+ license: Apache-2.0
6
+ metadata:
7
+ version: "0.5.1"
8
+ last_updated: "2026-04-08"
9
+ argument-hint: "<org-alias> [--agent-file <path>] [--session-id <id>] [--days <n>]"
10
+ compatibility: claude-code
11
+ ---
12
+
13
+
14
+ # Agentforce Observability
15
+
16
+ Improve Agentforce agents using session trace data and live preview testing.
17
+
18
+ **Three-phase workflow:**
19
+ - **Observe** -- Query STDM sessions from Data Cloud (if available), OR run test suites + preview with local traces as fallback
20
+ - **Reproduce** -- Use `sf agent preview` to simulate problematic conversations live
21
+ - **Improve** -- Edit the `.agent` file directly, validate, publish, verify
22
+
23
+ ---
24
+
25
+ ## Platform Notes
26
+
27
+ - Shell examples below use bash syntax. On Windows, use PowerShell equivalents or Git Bash.
28
+ - Replace `python3` with `python` on Windows.
29
+ - Replace `/tmp/` with `$env:TEMP\` (PowerShell) or `%TEMP%\` (cmd).
30
+ - Replace `jq` with `python -c "import json,sys; ..."` if jq is not installed.
31
+
32
+ ---
33
+
34
+ ## Routing
35
+
36
+ Gather these inputs before starting:
37
+
38
+ - **Org alias** (required)
39
+ - **Agent API name** (required for preview and deploy; ask if not provided)
40
+ - **Agent file path** (optional) -- path to the `.agent` file, typically `force-app/main/default/aiAuthoringBundles/<AgentName>/<AgentName>.agent`. Auto-detect if not provided.
41
+ - **Session IDs** (optional) -- analyze specific sessions; if absent, query last 7 days
42
+ - **Days to look back** (optional, default 7)
43
+
44
+ Determine intent from user input:
45
+
46
+ - **No specific action** -> run all three phases: Observe -> surface issues -> ask if user wants to Reproduce and/or Improve
47
+ - **"analyze" / "sessions" / "what's wrong"** -> Phase 1 only, then suggest next steps
48
+ - **"reproduce" / "test" / "preview"** -> Phase 2 (run Phase 1 first if no issues in hand)
49
+ - **"fix" / "improve" / "update"** -> Phase 3 (run Phase 1 first if no issues in hand)
50
+
51
+ ### Resolve agent name
52
+
53
+ Before any STDM query, resolve the user-provided agent name against the org to get the exact `MasterLabel` and `DeveloperName`:
54
+
55
+ ```bash
56
+ sf data query --json \
57
+ --query "SELECT Id, MasterLabel, DeveloperName FROM GenAiPlannerDefinition WHERE MasterLabel LIKE '%<user-provided-name>%' OR DeveloperName LIKE '%<user-provided-name>%'" \
58
+ -o <org>
59
+ ```
60
+
61
+ - `MasterLabel` = display name used by STDM `findSessions` and Agent Builder UI (e.g. "Order Service")
62
+ - `DeveloperName` = API name with version suffix used in metadata (e.g. "OrderService_v9")
63
+ - The `--api-name` flag for `sf agent preview/activate/publish` uses `DeveloperName` **without** the `_vN` suffix (e.g. "OrderService")
64
+
65
+ Store these values:
66
+ - `AGENT_MASTER_LABEL` -- for `findSessions()` agent filter
67
+ - `AGENT_API_NAME` -- `DeveloperName` without `_vN` suffix, for `sf agent` CLI commands
68
+ - `PLANNER_ID` -- the Salesforce record ID for this agent
69
+
70
+ ### Locate the .agent file
71
+
72
+ **Step 1 -- Search locally:**
73
+
74
+ ```bash
75
+ find <project-root>/force-app/main/default/aiAuthoringBundles -name "*.agent" 2>/dev/null
76
+ ```
77
+
78
+ If the user provided an agent file path, use that directly. Otherwise, search for files matching `AGENT_API_NAME`.
79
+
80
+ **Step 2 -- If not found locally, retrieve from the org:**
81
+
82
+ ```bash
83
+ sf project retrieve start --json --metadata "AiAuthoringBundle:<AGENT_API_NAME>" -o <org>
84
+ ```
85
+
86
+ > **Known bug:** `sf project retrieve start` creates a double-nested path: `force-app/main/default/main/default/aiAuthoringBundles/...`. Fix it immediately after retrieve:
87
+
88
+ ```bash
89
+ if [ -d "force-app/main/default/main/default/aiAuthoringBundles" ]; then
90
+ mkdir -p force-app/main/default/aiAuthoringBundles
91
+ cp -r force-app/main/default/main/default/aiAuthoringBundles/* \
92
+ force-app/main/default/aiAuthoringBundles/
93
+ rm -rf force-app/main/default/main
94
+ fi
95
+ ```
96
+
97
+ **Step 3 -- Validate the retrieved file:**
98
+
99
+ Read the `.agent` file and verify it has proper Agent Script structure:
100
+ - `system:` block with `instructions:`
101
+ - `config:` block with `developer_name:`
102
+ - `start_agent` or `topic` blocks with `reasoning: instructions:`
103
+ - Each topic should have distinct `instructions:` content (not identical across topics)
104
+
105
+ Store the resolved path as `AGENT_FILE` for Phase 3.
106
+
107
+ ---
108
+
109
+ ## Phase 0: Discover Data Space
110
+
111
+ Before running any STDM query, determine the correct Data Cloud Data Space API name.
112
+
113
+ ```bash
114
+ sf api request rest "/services/data/v63.0/ssot/data-spaces" -o <org>
115
+ ```
116
+
117
+ Note: `sf api request rest` is a beta command -- do not add `--json` (that flag is unsupported and causes an error).
118
+
119
+ The response shape is:
120
+ ```json
121
+ {
122
+ "dataSpaces": [
123
+ {
124
+ "id": "0vhKh000000g3DjIAI",
125
+ "label": "default",
126
+ "name": "default",
127
+ "status": "Active",
128
+ "description": "Your org's default data space."
129
+ }
130
+ ],
131
+ "totalSize": 1
132
+ }
133
+ ```
134
+
135
+ The `name` field is the API name to pass to `AgentforceOptimizeService`.
136
+
137
+ **Decision logic:**
138
+ - If the command fails (e.g. 404 or permission error), fall back to `'default'` and note it as an assumption.
139
+ - Filter to only `status: "Active"` entries.
140
+ - If exactly one active Data Space exists, use it automatically and confirm to the user: "Using Data Space: `<name>`".
141
+ - If multiple active Data Spaces exist, show the list (label + name) and ask the user which to use.
142
+
143
+ Store the selected `name` value as `DATA_SPACE` for all subsequent steps.
144
+
145
+ ### Prerequisite check: STDM DMOs
146
+
147
+ After deploying the helper class (step 1.0), run a quick probe to verify the STDM Data Model Objects exist in Data Cloud:
148
+
149
+ ```bash
150
+ sf apex run -o <org> -f /dev/stdin << 'APEX'
151
+ ConnectApi.CdpQueryInput qi = new ConnectApi.CdpQueryInput();
152
+ qi.sql = 'SELECT ssot__Id__c FROM "ssot__AiAgentSession__dlm" LIMIT 1';
153
+ try {
154
+ ConnectApi.CdpQueryOutputV2 out = ConnectApi.CdpQuery.queryAnsiSqlV2(qi, '<DATA_SPACE>');
155
+ System.debug('STDM_CHECK:OK rows=' + (out.data != null ? out.data.size() : 0));
156
+ } catch (Exception e) {
157
+ System.debug('STDM_CHECK:FAIL ' + e.getMessage());
158
+ }
159
+ APEX
160
+ ```
161
+
162
+ **If `STDM_CHECK:FAIL`:** STDM is not activated. Inform the user and switch to **Phase 1-ALT**:
163
+
164
+ > STDM (Session Trace Data Model) is not available in this org. To enable: Setup -> Data Cloud -> Data Streams and verify "Agentforce Activity" is active. **Proceeding with fallback: test suites + local traces.**
165
+
166
+ **If `STDM_CHECK:OK`**, proceed to Phase 1 (STDM path).
167
+
168
+ ---
169
+
170
+ ## Phase 1-ALT: Observe Without STDM (Fallback Path)
171
+
172
+ When STDM is not available, use test suites and `sf agent preview --authoring-bundle` with local trace analysis.
173
+
174
+ | Data source | When to use | Pros | Cons |
175
+ |---|---|---|---|
176
+ | STDM (Phase 1) | Historical production analysis | Real user data, volume | Requires Data Cloud, 15-min lag |
177
+ | Test suites + local traces (Phase 1-ALT) | Dev iteration, orgs without STDM | Instant, full LLM prompt, variable state | Preview only, no real user data |
178
+
179
+ ### 1-ALT.1 Run existing test suite (if available)
180
+
181
+ ```bash
182
+ sf agent test list --json -o <org>
183
+ sf agent test run --json --api-name <TestSuiteName> --wait 10 --result-format json -o <org> | tee /tmp/test_run.json
184
+ JOB_ID=$(python3 -c "import json; print(json.load(open('/tmp/test_run.json'))['result']['runId'])")
185
+ sf agent test results --json --job-id "$JOB_ID" --result-format json -o <org>
186
+ ```
187
+
188
+ ### 1-ALT.2 Derive test utterances from .agent file (if no test suite)
189
+
190
+ If no test suite exists, derive utterances: one per non-entry topic (from `description:` keywords), one per key action, one guardrail test, one multi-turn test.
191
+
192
+ ### 1-ALT.3 Preview with `--authoring-bundle` (local traces)
193
+
194
+ Run each test utterance through preview to generate local trace files:
195
+
196
+ ```bash
197
+ sf agent preview start --json --authoring-bundle <BundleName> -o <org> | tee /tmp/preview_start.json
198
+ SESSION_ID=$(python3 -c "import json; print(json.load(open('/tmp/preview_start.json'))['result']['sessionId'])")
199
+
200
+ sf agent preview send --json --session-id "$SESSION_ID" --authoring-bundle <BundleName> \
201
+ --utterance "$UTT" -o <org> | tee /tmp/preview_response.json
202
+
203
+ sf agent preview end --json --session-id "$SESSION_ID" --authoring-bundle <BundleName> -o <org>
204
+ ```
205
+
206
+ **Trace file location:** `.sfdx/agents/{BundleName}/sessions/{sessionId}/traces/{planId}.json`
207
+
208
+ ### 1-ALT.4 Local trace diagnosis
209
+
210
+ | Issue type | Trace command |
211
+ |---|---|
212
+ | Topic misroute | `jq -r '.plan[] \| select(.type=="NodeEntryStateStep") \| .data.agent_name' "$TRACE"` |
213
+ | Action not called | `jq -r '.plan[] \| select(.type=="EnabledToolsStep") \| .data.enabled_tools[]' "$TRACE"` |
214
+ | LOW adherence | `jq -r '.plan[] \| select(.type=="ReasoningStep") \| {category, reason}' "$TRACE"` |
215
+ | Variable capture fail | `jq -r '.plan[] \| select(.type=="VariableUpdateStep") \| .data.variable_updates[]' "$TRACE"` |
216
+ | Vague instructions | `jq -r '.plan[] \| select(.type=="LLMStep") \| .data.messages_sent[0].content' "$TRACE"` |
217
+
218
+ **DefaultTopic trace quirk:** With `--authoring-bundle`, the root `.topic` field often shows `"DefaultTopic"` even when routing works. Always use `NodeEntryStateStep.data.agent_name` for the real topic chain.
219
+
220
+ **Entry answering directly (SMALL_TALK pattern):** If `start_agent` trace shows `SMALL_TALK` grounding and transition tools visible but none invoked, add "You are a router only. Do NOT answer questions directly." to `start_agent` instructions.
221
+
222
+ ### 1-ALT.5 Classify and present
223
+
224
+ Classify issues using the categories in `references/issue-classification.md`. After presenting findings, automatically proceed to agent config evidence analysis.
225
+
226
+ ---
227
+
228
+ ## Phase 1: Observe -- Query STDM
229
+
230
+ > Full STDM query details, Apex service deployment, and response parsing: see `references/stdm-queries.md`
231
+
232
+ ### 1.0 Deploy helper class (once per org)
233
+
234
+ Deploy `AgentforceOptimizeService` Apex class to the org. Check if already deployed first:
235
+
236
+ ```bash
237
+ sf data query --json --query "SELECT Id, Name FROM ApexClass WHERE Name = 'AgentforceOptimizeService'" -o <org>
238
+ ```
239
+
240
+ If not deployed, copy from skill directory and deploy. See `references/stdm-queries.md` for full steps.
241
+
242
+ ### 1.1 Find sessions
243
+
244
+ Query recent sessions using `findSessions()`. Parse `DEBUG|STDM_RESULT:` from the Apex debug log. If `findSessions` returns empty, switch to Phase 1-ALT.
245
+
246
+ ### 1.2 Get conversation details
247
+
248
+ Use `getMultipleConversationDetails()` for up to 5 sessions (most recent first). Returns turn-by-turn data with messages, steps, topics, and action results.
249
+
250
+ ### 1.2b Get LLM prompt/response (optional)
251
+
252
+ When LOW adherence detected, use `getLlmStepDetails()` to get the actual LLM prompt and response.
253
+
254
+ ### 1.2c Get aggregated metrics (recommended first step)
255
+
256
+ Use `getAggregatedMetrics()` for high-level health dashboard: session rates, top intents, quality distribution, RAG averages.
257
+
258
+ ### 1.2d Get moment insights (per-session detail)
259
+
260
+ Use `getMomentInsights()` for intent summaries, quality scores (1-5), and retriever metrics per session.
261
+
262
+ ### 1.2e Run observability queries (RAG deep-dive)
263
+
264
+ Use `runObservabilityQuery()` for targeted RAG analysis: KnowledgeGap, Hallucination, RetrievalQuality, AnswerRelevancy, Leaderboard.
265
+
266
+ ### 1.3 Reconstruct conversations
267
+
268
+ Render turn-by-turn timeline from `ConversationData` JSON for each session.
269
+
270
+ ### 1.4 Identify issues
271
+
272
+ > Full issue pattern table and classification categories: see `references/issue-classification.md`
273
+
274
+ Check each session for: action errors, topic misroutes, missing actions, wrong inputs, variable capture failures, no transitions, slow actions, LOW adherence, abandoned sessions, dead topics, publish drift, dead hub anti-pattern, entry answering directly, and safety issues.
275
+
276
+ Priority: P1 = action errors, misroutes, LOW adherence; P2 = missing actions, variable bugs, knowledge gaps; P3 = performance, abandoned sessions.
277
+
278
+ ### 1.5 Present findings and agent config evidence
279
+
280
+ Present sessions analyzed, issues grouped by root cause category, and uplift estimate. Then automatically proceed to analyze the `.agent` file to confirm root causes.
281
+
282
+ > Full structural analysis checks, cross-reference procedures, and publish drift detection: see `references/issue-classification.md`
283
+
284
+ Retrieve the `.agent` file from the org, run automated checks (topic count vs action blocks, dead hub detection, orphan actions, cross-topic variable dependencies), and cross-reference STDM symptoms against the file structure.
285
+
286
+ ---
287
+
288
+ ## Phase 2: Reproduce -- Live Preview
289
+
290
+ > Full preview procedures, trace diagnosis commands, and classification criteria: see `references/reproduce-reference.md`
291
+
292
+ Build one test scenario per confirmed issue from Phase 1. Run each through `sf agent preview` with `--authoring-bundle` (generates local traces). Run each scenario **3 times** and classify:
293
+
294
+ | Verdict | Criteria |
295
+ |---|---|
296
+ | `[CONFIRMED]` | Same failure in 3/3 runs |
297
+ | `[INTERMITTENT]` | Failure in 1-2 of 3 runs |
298
+ | `[NOT REPRODUCED]` | Passes in 3/3 runs |
299
+
300
+ Only `[CONFIRMED]` and `[INTERMITTENT]` issues proceed to Phase 3.
301
+
302
+ **Key commands:**
303
+
304
+ ```bash
305
+ sf agent preview start --json --authoring-bundle <Name> -o <org>
306
+ sf agent preview send --json --session-id "$SID" --utterance "<text>" --authoring-bundle <Name> -o <org>
307
+ sf agent preview end --json --session-id "$SID" --authoring-bundle <Name> -o <org>
308
+ ```
309
+
310
+ **Trace location:** `.sfdx/agents/{Name}/sessions/{sessionId}/traces/{planId}.json`
311
+
312
+ ---
313
+
314
+ ## Phase 3: Improve -- Edit .agent File Directly
315
+
316
+ > Full procedures for pre-flight checks, fix mapping, instruction principles, regression prevention, deployment chain, verification, safety re-verification, and test case creation: see `references/improve-reference.md`
317
+
318
+ ### 3.0 Pre-flight
319
+
320
+ Verify all action targets exist and are registered in the org before editing. If targets are missing, present options: deploy stubs, remove actions, register via UI, or proceed with routing-only fixes.
321
+
322
+ ### 3.1-3.3 Map issue, edit, and follow instruction principles
323
+
324
+ Map each confirmed issue to a fix location in the `.agent` file (description, instructions, actions, bindings, transitions). Use the Edit tool for targeted changes. Follow instruction principles: name actions explicitly, state pre-conditions, scope tightly, keep persona in `system:` only.
325
+
326
+ ### 3.4 Regression prevention
327
+
328
+ Establish baseline before editing. Make minimal edits. Test immediately after each edit. One fix per publish cycle. Check cross-topic dependencies. Test adjacent topics.
329
+
330
+ ### 3.5 Apply fixes
331
+
332
+ Read the `.agent` file, edit with the Edit tool (tabs for indentation), show the diff.
333
+
334
+ ### 3.6 Validate, deploy, publish, activate
335
+
336
+ ```bash
337
+ # Validate (dry run)
338
+ sf agent validate authoring-bundle --json --api-name <AGENT_API_NAME> -o <org>
339
+
340
+ # Publish (compile + deploy + activate)
341
+ sf agent publish authoring-bundle --json --api-name <AGENT_API_NAME> -o <org>
342
+ ```
343
+
344
+ If publish fails, use deploy + activate fallback (note: incomplete -- does not propagate `reasoning: actions:` to live metadata).
345
+
346
+ ### 3.7 Verify
347
+
348
+ Run Phase 2 scenarios post-fix. Check trace for correct routing, grounding, tools, and variables. After 24-48 hours, re-run Phase 1 to compare against baseline.
349
+
350
+ ### 3.7b Safety re-verification (required)
351
+
352
+ Re-run safety review (`Section 15 of /developing-agentforce`) on the modified `.agent` file. Revert any changes that introduce BLOCK findings.
353
+
354
+ ### 3.8 Update Testing Center test cases
355
+
356
+ Create regression test cases from confirmed issues in Testing Center YAML format. Deploy with `sf agent test create` and verify all previously-broken scenarios pass.
357
+
358
+ ---
359
+
360
+ ## Reference Files
361
+
362
+ | Reference | Contents |
363
+ |---|---|
364
+ | `references/stdm-queries.md` | STDM query procedures, Apex service deployment, response parsing |
365
+ | `references/issue-classification.md` | Issue pattern table, root cause categories, structural analysis checks |
366
+ | `references/reproduce-reference.md` | Phase 2 preview procedures, trace diagnosis, classification criteria |
367
+ | `references/improve-reference.md` | Phase 3 editing, deployment chain, verification, safety, test cases |
368
+ | `references/stdm-schema.md` | DMO field schemas, data hierarchy, quality notes, agent name resolution |