@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.
- package/package.json +4 -4
- package/skills/agentforce-development/SKILL.md +427 -0
- package/skills/agentforce-development/assets/README-legacy.md +89 -0
- package/skills/agentforce-development/assets/agent-spec-template.md +90 -0
- package/skills/agentforce-development/assets/agents/README.md +45 -0
- package/skills/agentforce-development/assets/agents/hello-world.agent +60 -0
- package/skills/agentforce-development/assets/agents/multi-topic.agent +105 -0
- package/skills/agentforce-development/assets/agents/production-faq.agent +101 -0
- package/skills/agentforce-development/assets/agents/production-faq.bundle-meta.xml +4 -0
- package/skills/agentforce-development/assets/agents/simple-qa.agent +72 -0
- package/skills/agentforce-development/assets/apex/models-api-queueable.cls +225 -0
- package/skills/agentforce-development/assets/bundle-meta.xml +23 -0
- package/skills/agentforce-development/assets/components/apex-action.agent +52 -0
- package/skills/agentforce-development/assets/components/error-handling.agent +58 -0
- package/skills/agentforce-development/assets/components/escalation-setup.agent +169 -0
- package/skills/agentforce-development/assets/components/flow-action.agent +66 -0
- package/skills/agentforce-development/assets/components/n-ary-conditions.agent +110 -0
- package/skills/agentforce-development/assets/components/topic-with-actions.agent +40 -0
- package/skills/agentforce-development/assets/deterministic-routing.agent +166 -0
- package/skills/agentforce-development/assets/escalation-pattern.agent +209 -0
- package/skills/agentforce-development/assets/flow-action-lookup.agent +115 -0
- package/skills/agentforce-development/assets/hub-and-spoke.agent +104 -0
- package/skills/agentforce-development/assets/invocable-apex-template.cls +187 -0
- package/skills/agentforce-development/assets/local-info-agent-annotated.agent +355 -0
- package/skills/agentforce-development/assets/metadata/basic-prompt-template.promptTemplate-meta.xml +109 -0
- package/skills/agentforce-development/assets/metadata/genai-function-apex.xml +92 -0
- package/skills/agentforce-development/assets/metadata/genai-function-flow.xml +57 -0
- package/skills/agentforce-development/assets/metadata/genai-plugin.xml +72 -0
- package/skills/agentforce-development/assets/metadata/http-callout-flow.flow-meta.xml +348 -0
- package/skills/agentforce-development/assets/metadata/record-grounded-prompt.promptTemplate-meta.xml +136 -0
- package/skills/agentforce-development/assets/minimal-starter.agent +42 -0
- package/skills/agentforce-development/assets/patterns/README.md +254 -0
- package/skills/agentforce-development/assets/patterns/action-callbacks.agent +178 -0
- package/skills/agentforce-development/assets/patterns/advanced-input-bindings.agent +141 -0
- package/skills/agentforce-development/assets/patterns/bidirectional-routing.agent +156 -0
- package/skills/agentforce-development/assets/patterns/critical-input-collection.agent +244 -0
- package/skills/agentforce-development/assets/patterns/delegation-routing.agent +89 -0
- package/skills/agentforce-development/assets/patterns/lifecycle-events.agent +127 -0
- package/skills/agentforce-development/assets/patterns/llm-controlled-actions.agent +184 -0
- package/skills/agentforce-development/assets/patterns/multi-step-workflow.agent +282 -0
- package/skills/agentforce-development/assets/patterns/open-gate-routing.agent +286 -0
- package/skills/agentforce-development/assets/patterns/procedural-instructions.agent +273 -0
- package/skills/agentforce-development/assets/patterns/prompt-template-action.agent +188 -0
- package/skills/agentforce-development/assets/patterns/system-instruction-overrides.agent +293 -0
- package/skills/agentforce-development/assets/prompt-rag-search.agent +131 -0
- package/skills/agentforce-development/assets/template-multi-topic.agent +160 -0
- package/skills/agentforce-development/assets/template-single-topic.agent +81 -0
- package/skills/agentforce-development/assets/verification-gate.agent +208 -0
- package/skills/agentforce-development/references/action-prompt-templates.md +164 -0
- package/skills/agentforce-development/references/actions-reference.md +592 -0
- package/skills/agentforce-development/references/agent-access-guide.md +72 -0
- package/skills/agentforce-development/references/agent-design-and-spec-creation.md +1010 -0
- package/skills/agentforce-development/references/agent-metadata-and-lifecycle.md +575 -0
- package/skills/agentforce-development/references/agent-script-core-language.md +1218 -0
- package/skills/agentforce-development/references/agent-topic-map-diagrams.md +323 -0
- package/skills/agentforce-development/references/agent-user-setup.md +526 -0
- package/skills/agentforce-development/references/agent-validation-and-debugging.md +803 -0
- package/skills/agentforce-development/references/known-issues.md +353 -0
- package/skills/agentforce-development/references/minimal-examples.md +67 -0
- package/skills/agentforce-development/references/production-gotchas.md +279 -0
- package/skills/agentforce-development/references/salesforce-cli-for-agents.md +393 -0
- package/skills/agentforce-development/references/version-history.md +23 -0
- package/skills/generate-permission-set/SKILL.md +174 -0
- package/skills/salesforce-custom-application/SKILL.md +1 -2
- package/skills/salesforce-custom-field/SKILL.md +0 -4
- package/skills/salesforce-custom-tab/SKILL.md +84 -8
- package/skills/salesforce-experience-lwr-site/SKILL.md +196 -0
- package/skills/salesforce-experience-lwr-site/docs/bootstrap-template-byo-lwr.md +224 -0
- package/skills/salesforce-experience-lwr-site/docs/configure-content-brandingSet.md +131 -0
- package/skills/salesforce-experience-lwr-site/docs/configure-content-route.md +232 -0
- package/skills/salesforce-experience-lwr-site/docs/configure-content-themeLayout.md +141 -0
- package/skills/salesforce-experience-lwr-site/docs/configure-content-view.md +233 -0
- package/skills/salesforce-experience-lwr-site/docs/configure-guest-sharing-rules.md +42 -0
- package/skills/salesforce-experience-lwr-site/docs/handle-component-and-region-ids.md +27 -0
- package/skills/salesforce-experience-lwr-site/docs/handle-ui-components.md +215 -0
- package/skills/salesforce-flow/SKILL.md +2 -2
- package/skills/salesforce-fragment/SKILL.md +85 -10
- package/skills/salesforce-lightning-app-build/SKILL.md +102 -10
- package/skills/apex-class/SKILL.md +0 -253
- package/skills/apex-class/examples/AccountDeduplicationBatch.cls +0 -148
- package/skills/apex-class/examples/AccountSelector.cls +0 -193
- package/skills/apex-class/examples/AccountService.cls +0 -201
- package/skills/apex-class/templates/abstract.cls +0 -128
- package/skills/apex-class/templates/batch.cls +0 -125
- package/skills/apex-class/templates/domain.cls +0 -102
- package/skills/apex-class/templates/dto.cls +0 -108
- package/skills/apex-class/templates/exception.cls +0 -51
- package/skills/apex-class/templates/interface.cls +0 -25
- package/skills/apex-class/templates/queueable.cls +0 -92
- package/skills/apex-class/templates/schedulable.cls +0 -75
- package/skills/apex-class/templates/selector.cls +0 -92
- package/skills/apex-class/templates/service.cls +0 -69
- package/skills/apex-class/templates/utility.cls +0 -97
- package/skills/apex-test-class/SKILL.md +0 -101
- package/skills/apex-test-class/references/assertion-patterns.md +0 -209
- package/skills/apex-test-class/references/async-testing.md +0 -276
- package/skills/apex-test-class/references/mocking-patterns.md +0 -219
- package/skills/apex-test-class/references/test-data-factory.md +0 -176
- package/skills/deployment-readiness-check/SKILL.md +0 -257
- package/skills/deployment-readiness-check/assets/deployment_checklist.md +0 -286
- package/skills/deployment-readiness-check/references/rollback_procedures.md +0 -308
- package/skills/deployment-readiness-check/scripts/check_metadata.sh +0 -207
- package/skills/salesforce-experience-site/SKILL.md +0 -178
|
@@ -0,0 +1,803 @@
|
|
|
1
|
+
# Agent Validation and Debugging Reference
|
|
2
|
+
|
|
3
|
+
## Table of Contents
|
|
4
|
+
|
|
5
|
+
1. Validation
|
|
6
|
+
2. Error Taxonomy and Prevention
|
|
7
|
+
3. Preview
|
|
8
|
+
4. Session Traces
|
|
9
|
+
5. Diagnostic Patterns
|
|
10
|
+
6. Diagnostic Workflow
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 1. Validation
|
|
15
|
+
|
|
16
|
+
The `sf agent validate` command checks Agent Script files for syntax errors, structural issues, and missing declarations before you attempt to preview or deploy an agent.
|
|
17
|
+
|
|
18
|
+
### Running Validation
|
|
19
|
+
|
|
20
|
+
After modifying any `.agent` file, always run this command:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
sf agent validate authoring-bundle --api-name <AGENT_NAME> --json
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Replace `<AGENT_NAME>` with the directory name under `aiAuthoringBundles/` (without the `.agent` extension). Always include `--json` so the output is machine-readable.
|
|
27
|
+
|
|
28
|
+
Example:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
sf agent validate authoring-bundle --api-name Local_Info_Agent --json
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Interpreting Output
|
|
35
|
+
|
|
36
|
+
When validation succeeds, the JSON output contains `result.success` set to `true`:
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"status": 0,
|
|
41
|
+
"result": {
|
|
42
|
+
"success": true
|
|
43
|
+
},
|
|
44
|
+
"warnings": []
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
When validation fails, the CLI treats it as an error. The output uses the CLI error format, not a structured validation result. All useful information is in the `message` field. Ignore `stack`, `cause`, `code`, and `commandName` — these are CLI internals, not diagnostic content.
|
|
49
|
+
|
|
50
|
+
The `message` field contains the compilation errors. These errors may include ANSI terminal color codes (`\u001b[31m`, `\u001b[39m`, etc.) — strip these before interpreting the message. Errors typically include line and column references (e.g., `[Ln 92, Col 13]`) that map to the `.agent` file, but do not assume a fixed error format. Read the `message` content naturally and reason about what it tells you.
|
|
51
|
+
|
|
52
|
+
Do not attempt to preview or deploy until validation passes.
|
|
53
|
+
|
|
54
|
+
### Validation Checklist (Pre-Validate Mental Model)
|
|
55
|
+
|
|
56
|
+
Before running the validation command, mentally check these 14 items. This checklist prevents the most common errors and speeds up the feedback loop:
|
|
57
|
+
|
|
58
|
+
- Block ordering is correct: `system` → `config` → `variables` → `connections` → `knowledge` → `language` → `start_agent` → `topic` blocks
|
|
59
|
+
- `config` block has `developer_name` (required for service agents: also needs `default_agent_user`)
|
|
60
|
+
- `system` block has `messages.welcome`, `messages.error`, and `instructions`
|
|
61
|
+
- `start_agent` block exists with description and at least one transition action
|
|
62
|
+
- Each `topic` has a `description` and `reasoning` block
|
|
63
|
+
- All `mutable` variables have default values (required)
|
|
64
|
+
- All `linked` variables have `source` specified and NO default value
|
|
65
|
+
- Action `target` uses valid format (`flow://`, `apex://`, `prompt://`, etc.)
|
|
66
|
+
- Boolean values use `True`/`False` (capitalized, not `true`/`false`)
|
|
67
|
+
- `...` is used for LLM slot-filling in reasoning action inputs, not as variable defaults
|
|
68
|
+
- Transition syntax is correct: `@utils.transition to` in `reasoning.actions`, bare `transition to` in directive blocks
|
|
69
|
+
- Indentation is consistent (4 spaces recommended)
|
|
70
|
+
- Names follow naming rules (letters, numbers, underscores only; no spaces; start with letter)
|
|
71
|
+
- No duplicate block names or action names within the same scope
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## 2. Error Taxonomy and Prevention
|
|
76
|
+
|
|
77
|
+
Validation errors fall into several categories: block ordering, indentation, syntax, missing declarations, type mismatches, and structural violations. The following examples show the most common mistakes and their fixes.
|
|
78
|
+
|
|
79
|
+
### Common Mistakes with WRONG/RIGHT Pairs
|
|
80
|
+
|
|
81
|
+
**1. Wrong Transition Syntax**
|
|
82
|
+
|
|
83
|
+
```agentscript
|
|
84
|
+
# WRONG — bare transition in reasoning.actions
|
|
85
|
+
go_next: transition to @topic.next
|
|
86
|
+
|
|
87
|
+
# CORRECT — use @utils.transition to in reasoning.actions
|
|
88
|
+
go_next: @utils.transition to @topic.next
|
|
89
|
+
|
|
90
|
+
# CORRECT — use bare transition in directive blocks
|
|
91
|
+
after_reasoning:
|
|
92
|
+
transition to @topic.next
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
In reasoning actions (where the LLM decides what to do), use `@utils.transition to`. In directive blocks (`before_reasoning`, `after_reasoning`), use bare `transition to`. These are two different syntaxes for two different contexts.
|
|
96
|
+
|
|
97
|
+
**2. Missing Default for Mutable Variable**
|
|
98
|
+
|
|
99
|
+
```agentscript
|
|
100
|
+
# WRONG — mutable variables must have default values
|
|
101
|
+
count: mutable number
|
|
102
|
+
|
|
103
|
+
# CORRECT
|
|
104
|
+
count: mutable number = 0
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Mutable variables are initialized at runtime. They must have a default value so the runtime knows the initial state.
|
|
108
|
+
|
|
109
|
+
**3. Wrong Boolean Capitalization**
|
|
110
|
+
|
|
111
|
+
```agentscript
|
|
112
|
+
# WRONG — lowercase booleans
|
|
113
|
+
enabled: mutable boolean = true
|
|
114
|
+
|
|
115
|
+
# CORRECT — capitalized booleans
|
|
116
|
+
enabled: mutable boolean = True
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Agent Script requires `True`/`False` (capitalized). This is consistent across all boolean contexts: variable defaults, conditional comparisons, and field values.
|
|
120
|
+
|
|
121
|
+
**4. Using `...` as Variable Default (It's for Slot-Filling Only)**
|
|
122
|
+
|
|
123
|
+
```agentscript
|
|
124
|
+
# WRONG — `...` is slot-filling syntax, not a default value
|
|
125
|
+
my_var: mutable string = ...
|
|
126
|
+
|
|
127
|
+
# CORRECT
|
|
128
|
+
my_var: mutable string = ""
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
`...` tells the LLM "extract this value from the conversation" during reasoning actions. It cannot be a variable default.
|
|
132
|
+
|
|
133
|
+
**5. List Type for Linked Variables**
|
|
134
|
+
|
|
135
|
+
```agentscript
|
|
136
|
+
# WRONG — linked variables cannot be lists
|
|
137
|
+
items: linked list[string]
|
|
138
|
+
|
|
139
|
+
# CORRECT — mutable can be list
|
|
140
|
+
items: mutable list[string] = []
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Linked variables come from external context (session ID, user record, etc.) which are scalar values. Lists must be mutable.
|
|
144
|
+
|
|
145
|
+
**6. Default Value on Linked Variable**
|
|
146
|
+
|
|
147
|
+
```agentscript
|
|
148
|
+
# WRONG — linked variables get value from source, no default
|
|
149
|
+
session_id: linked string = ""
|
|
150
|
+
source: @session.sessionID
|
|
151
|
+
|
|
152
|
+
# CORRECT — no default, only source
|
|
153
|
+
session_id: linked string
|
|
154
|
+
source: @session.sessionID
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Linked variables are populated from their `source` at runtime. Do not assign a default value.
|
|
158
|
+
|
|
159
|
+
**7. Post-Action Directives on Utility Actions**
|
|
160
|
+
|
|
161
|
+
```agentscript
|
|
162
|
+
# WRONG — utilities don't support post-action directives
|
|
163
|
+
go_next: @utils.transition to @topic.next
|
|
164
|
+
set @variables.navigated = True
|
|
165
|
+
|
|
166
|
+
# CORRECT — only @actions support post-action directives
|
|
167
|
+
process: @actions.process_order
|
|
168
|
+
set @variables.result = @outputs.result
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Post-action directives (`set`, `run`, `if`, `transition`) only work after `@actions.*` invocations. Utility actions (`@utils.*`) and topic delegates (`@topic.*`) do not produce outputs, so post-action directives are not applicable.
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## 3. Preview
|
|
176
|
+
|
|
177
|
+
Preview lets you test an agent's behavior by sending utterances and observing responses. The preview workflow starts a session, sends one or more utterances, and captures session traces for analysis.
|
|
178
|
+
|
|
179
|
+
### Programmatic Workflow
|
|
180
|
+
|
|
181
|
+
ALWAYS use `--json` when calling from a script or AI assistant (not interactive REPL).
|
|
182
|
+
|
|
183
|
+
#### Step 1: Start a Session
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
sf agent preview start --authoring-bundle <BUNDLE_NAME> --json
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
This command returns a session ID. Capture it immediately — you need it for every subsequent command.
|
|
190
|
+
|
|
191
|
+
Example:
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
sf agent preview start --authoring-bundle Local_Info_Agent --json
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
#### Step 2: Send Utterances
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
sf agent preview send --authoring-bundle <BUNDLE_NAME> --session-id <SESSION_ID> -u "<MESSAGE>" --json
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Include the same `--authoring-bundle` name and the session ID from Step 1. You can send multiple utterances in the same session — do not end and restart between turns.
|
|
204
|
+
|
|
205
|
+
Example:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
sf agent preview send --authoring-bundle Local_Info_Agent --session-id abc123def456 -u "What's the weather?" --json
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
#### Step 3: End a Session (Optional)
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
sf agent preview end --authoring-bundle <BUNDLE_NAME> --session-id <SESSION_ID> --json
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
This command returns the path to session trace files. Call it when the conversation is complete. Do not end prematurely — if the user may ask follow-up questions, keep the session open.
|
|
218
|
+
|
|
219
|
+
### Execution Modes
|
|
220
|
+
|
|
221
|
+
Agent Script agents in authoring bundles support two preview execution modes: simulated (default) and live.
|
|
222
|
+
|
|
223
|
+
**Simulated Preview Mode (Default).** The LLM generates fake action outputs. Use simulated preview mode when:
|
|
224
|
+
- Backing Apex, Flows, or Prompt Templates don't exist yet (you're experimenting with instructions and flow before building actions)
|
|
225
|
+
- No default agent user is configured (live preview mode requires a real, active user; simulated preview mode skips this requirement)
|
|
226
|
+
|
|
227
|
+
Simulated preview mode speeds up inner-loop development but cannot validate real action outputs, variable-driven branching, or grounding behavior.
|
|
228
|
+
|
|
229
|
+
**Live Preview Mode.** Real backing code executes and returns real outputs. Pass `--use-live-actions`:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
sf agent preview start --authoring-bundle <BUNDLE_NAME> --use-live-actions --json
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Use live preview mode when:
|
|
236
|
+
- Backing code is deployed and a default agent user is configured
|
|
237
|
+
- Your test depends on real action output values (grounding validation, variable-driven branching, output formatting)
|
|
238
|
+
|
|
239
|
+
Live preview mode is required for reliable grounding testing. The grounding checker runs in both modes, but simulated preview mode generates fake action outputs via LLM, and those outputs can trigger false grounding failures because they don't match real data patterns. If you see grounding failures in simulated preview mode, switch to live preview mode before diagnosing — the failure may be an artifact of simulation, not a real problem.
|
|
240
|
+
|
|
241
|
+
CRITICAL: `--use-live-actions` is ONLY valid with `--authoring-bundle`. Published agents (`--api-name`) always execute real actions — do NOT pass `--use-live-actions` with `--api-name`.
|
|
242
|
+
|
|
243
|
+
### Agent Identification
|
|
244
|
+
|
|
245
|
+
Use exactly one of these mutually exclusive flags:
|
|
246
|
+
|
|
247
|
+
- `--authoring-bundle <name>` — for a local Agent Script agent. The name is the directory name under `aiAuthoringBundles/` (without the `.agent` extension).
|
|
248
|
+
- `--api-name <name>` — for a published agent in the org. The name is the directory name under `Bots/`.
|
|
249
|
+
|
|
250
|
+
These flags identify which agent to preview.
|
|
251
|
+
|
|
252
|
+
To use a published agent, switch from `--authoring-bundle` to `--api-name`. No additional setup is required. The agent runs real actions; `--use-live-actions` is not passed.
|
|
253
|
+
|
|
254
|
+
### Target Org
|
|
255
|
+
|
|
256
|
+
The CLI automatically uses the project's default target org. Always omit `--target-org` and rely on the project default. Only pass `--target-org` if the user explicitly tells you which org to use. Never guess or invent an org username.
|
|
257
|
+
|
|
258
|
+
### Common Preview Mistakes with WRONG/RIGHT Pairs
|
|
259
|
+
|
|
260
|
+
**1. Using the Interactive REPL from Automation**
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
# WRONG — requires terminal interaction (ESC to exit)
|
|
264
|
+
sf agent preview --authoring-bundle My_Bundle
|
|
265
|
+
|
|
266
|
+
# CORRECT — programmatic API
|
|
267
|
+
sf agent preview start --authoring-bundle My_Bundle --json
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
The bare `sf agent preview` command is an interactive REPL for humans. Automation cannot provide terminal input (ESC), so it hangs. Use `start`/`send`/`end` with `--json`.
|
|
271
|
+
|
|
272
|
+
**2. Combining `--authoring-bundle` and `--api-name`**
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
# WRONG — mutually exclusive flags
|
|
276
|
+
sf agent preview start --authoring-bundle My_Bundle --api-name My_Agent --json
|
|
277
|
+
|
|
278
|
+
# CORRECT — choose one
|
|
279
|
+
sf agent preview start --authoring-bundle My_Bundle --json
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
These flags are mutually exclusive. Use the one matching your agent type.
|
|
283
|
+
|
|
284
|
+
**3. Using `--authoring-bundle` to Verify a Published Agent**
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
# WRONG — publishes, then previews from LOCAL agent script (not what's published)
|
|
288
|
+
sf agent publish authoring-bundle --json --api-name My_Agent
|
|
289
|
+
sf agent preview start --json --authoring-bundle My_Agent
|
|
290
|
+
|
|
291
|
+
# CORRECT — publishes, then previews the PUBLISHED agent users interact with
|
|
292
|
+
sf agent publish authoring-bundle --json --api-name My_Agent
|
|
293
|
+
sf agent preview start --json --api-name My_Agent
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Use `agent preview` commands with `--api-name` to preview published agents.
|
|
297
|
+
|
|
298
|
+
**4. Sending Before Starting**
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
# WRONG — no session exists
|
|
302
|
+
sf agent preview send --authoring-bundle My_Bundle -u "Hello" --json
|
|
303
|
+
|
|
304
|
+
# CORRECT — start first, capture session ID
|
|
305
|
+
sf agent preview start --authoring-bundle My_Bundle --json
|
|
306
|
+
sf agent preview send --authoring-bundle My_Bundle --session-id <ID> -u "Hello" --json
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
Each session has a unique ID. You must start before sending.
|
|
310
|
+
|
|
311
|
+
**5. Forgetting the Agent Identifier on `send` and `end`**
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
# WRONG — missing --authoring-bundle
|
|
315
|
+
sf agent preview send --session-id <ID> -u "Hello" --json
|
|
316
|
+
|
|
317
|
+
# CORRECT
|
|
318
|
+
sf agent preview send --authoring-bundle My_Bundle --session-id <ID> -u "Hello" --json
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
Every command after `start` must include the same `--authoring-bundle` or `--api-name` flag.
|
|
322
|
+
|
|
323
|
+
**6. Omitting `--session-id` on `send` or `end`**
|
|
324
|
+
|
|
325
|
+
```bash
|
|
326
|
+
# WRONG — concurrent sessions collide
|
|
327
|
+
sf agent preview send --authoring-bundle My_Bundle -u "Hello" --json
|
|
328
|
+
|
|
329
|
+
# CORRECT — always include session ID
|
|
330
|
+
sf agent preview send --authoring-bundle My_Bundle --session-id <ID> -u "Hello" --json
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
If multiple agents have concurrent sessions against the same agent, omitting the session ID causes them to interfere. Always pass the session ID from `start`.
|
|
334
|
+
|
|
335
|
+
### Context Variable Limitations in Preview
|
|
336
|
+
|
|
337
|
+
Agent behavior requiring `@context` or `@session` variables for routing or guards CAN NOT be tested via `sf agent preview`. Commands in the `preview` topic DO NOT support context or session variable injection. Flags like `--context`, `--session-var`, or `--variables` DO NOT EXIST.
|
|
338
|
+
|
|
339
|
+
- `@session.sessionID`, `@context.customerId`, `@context.RoutableId` — do NOT work in preview.
|
|
340
|
+
- Mutable variables with default values — work normally in preview.
|
|
341
|
+
- `with param=...` (LLM slot-filling) — works normally in preview.
|
|
342
|
+
|
|
343
|
+
### Utterance Derivation
|
|
344
|
+
|
|
345
|
+
Utterances provided to `sf agent preview send` must be derived from the `.agent` file using these guidelines:
|
|
346
|
+
|
|
347
|
+
1. **One per non-start topic** — based on `description:` keywords. Pick the most natural user phrasing.
|
|
348
|
+
2. **One that should trigger each key action** — match the action's `description:` to a realistic user request.
|
|
349
|
+
3. **One off-topic utterance** — tests guardrails (e.g., "Tell me a joke", "What's the weather?").
|
|
350
|
+
4. **One multi-turn pair** — if agent has topic transitions, send two related utterances to test handoff (e.g., "Check my order" → "Actually I want to return it").
|
|
351
|
+
|
|
352
|
+
---
|
|
353
|
+
|
|
354
|
+
## 4. Session Traces
|
|
355
|
+
|
|
356
|
+
After each utterance in a preview session, the runtime writes trace files. Traces show the complete execution path: what topic was selected, what variables were set, what the LLM saw in its prompt, what it decided to do, and whether the response passed grounding.
|
|
357
|
+
|
|
358
|
+
### Trace File Location
|
|
359
|
+
|
|
360
|
+
Traces are stored locally at:
|
|
361
|
+
|
|
362
|
+
```
|
|
363
|
+
.sfdx/agents/<AGENT_NAME>/sessions/<SESSION_ID>/
|
|
364
|
+
├── metadata.json # Session metadata
|
|
365
|
+
├── transcript.jsonl # Conversation log (one JSON object per line)
|
|
366
|
+
└── traces/
|
|
367
|
+
└── <PLAN_ID>.json # Detailed execution trace for each turn
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
Replace `<AGENT_NAME>` with your authoring bundle name (e.g., `Local_Info_Agent`). The `<SESSION_ID>` is the value returned by `sf agent preview start`. A separate trace file (identified by `<PLAN_ID>`) is written for each conversation turn.
|
|
371
|
+
|
|
372
|
+
Traces are available immediately after each `send` — you do NOT need to end the session to read them.
|
|
373
|
+
|
|
374
|
+
### File Structure
|
|
375
|
+
|
|
376
|
+
**metadata.json** contains session-level information: `sessionId`, `agentId`, `startTime`, and `mockMode` (either `"Mock"` for simulated or `"Live Test"` for live).
|
|
377
|
+
|
|
378
|
+
**transcript.jsonl** is a conversation log with one JSON object per line. Each entry includes `timestamp`, `agentId`, `sessionId`, `role` (`"user"` or `"agent"`), and `text`. Agent responses also include a `raw` array with additional metadata — most importantly, the `planId` field that links to the corresponding trace file.
|
|
379
|
+
|
|
380
|
+
```json
|
|
381
|
+
{"timestamp":"...","agentId":"Local_Info_Agent","sessionId":"abc123","role":"user","text":"What's the weather?"}
|
|
382
|
+
{"timestamp":"...","agentId":"Local_Info_Agent","sessionId":"abc123","role":"agent","text":"The weather on 2026-02-19...","raw":[{"planId":"def456","isContentSafe":true,...}]}
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
To connect a failed turn to its trace, find the agent response in the transcript and read the `planId` from its `raw` array. That `planId` is the filename under `traces/`.
|
|
386
|
+
|
|
387
|
+
**traces/<PLAN_ID>.json** is the detailed execution log for a single turn. It contains top-level fields (`type`, `planId`, `sessionId`, `intent`, `topic`) and a `plan` array with execution steps in chronological order.
|
|
388
|
+
|
|
389
|
+
### Step Types (Reference Table)
|
|
390
|
+
|
|
391
|
+
Each trace step type reveals specific execution information:
|
|
392
|
+
|
|
393
|
+
- **`UserInputStep`** — The user's utterance that triggered this turn.
|
|
394
|
+
- **`SessionInitialStateStep`** — Variable values and directive context at turn start.
|
|
395
|
+
- **`NodeEntryStateStep`** — Which agent/topic is executing and its full state snapshot.
|
|
396
|
+
- **`VariableUpdateStep`** — A variable was changed — shows old/new value and reason.
|
|
397
|
+
- **`BeforeReasoningIterationStep`** — `before_reasoning` block ran — lists actions executed.
|
|
398
|
+
- **`EnabledToolsStep`** — Which tools/actions are available to the LLM for this reasoning cycle.
|
|
399
|
+
- **`LLMStep`** — The LLM call — full prompt, response, available tools, latency.
|
|
400
|
+
- **`FunctionStep`** — An action executed — shows input, output, and latency.
|
|
401
|
+
- **`ReasoningStep`** — Grounding check result — `GROUNDED` or `UNGROUNDED` with reason.
|
|
402
|
+
- **`TransitionStep`** — Topic transition — shows from/to topics and transition type.
|
|
403
|
+
- **`PlannerResponseStep`** — Final response delivered to user — includes safety scores.
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
### How to Read a Trace
|
|
407
|
+
|
|
408
|
+
Read steps in chronological order:
|
|
409
|
+
|
|
410
|
+
1. Locate `UserInputStep` — the trigger for this turn
|
|
411
|
+
2. Check `NodeEntryStateStep` — which topic is running and what is the current variable state?
|
|
412
|
+
3. Look for `EnabledToolsStep` — what actions are available to the LLM?
|
|
413
|
+
4. Find `LLMStep` — examine `messages_sent` (the full prompt), `tools_sent` (available actions), and `response_messages` (what the LLM chose to do)
|
|
414
|
+
5. If an action was called, find the corresponding `FunctionStep` — compare inputs sent and outputs received
|
|
415
|
+
6. Check `ReasoningStep` — did the response pass grounding?
|
|
416
|
+
7. Look for `TransitionStep` — did the agent move to another topic?
|
|
417
|
+
8. Check `PlannerResponseStep` — what did the user receive?
|
|
418
|
+
|
|
419
|
+
### The LLMStep in Detail
|
|
420
|
+
|
|
421
|
+
The `LLMStep` is the most diagnostic step type. It contains:
|
|
422
|
+
|
|
423
|
+
- `agent_name` — which topic or selector is running
|
|
424
|
+
- `messages_sent` — the FULL prompt sent to the LLM (system message, conversation history, and injected instructions)
|
|
425
|
+
- `tools_sent` — action names available to the LLM
|
|
426
|
+
- `response_messages` — the LLM's response (text or tool invocation)
|
|
427
|
+
- `execution_latency` — milliseconds for the LLM call
|
|
428
|
+
|
|
429
|
+
The `messages_sent` array shows you exactly what the LLM saw. This is invaluable for debugging because:
|
|
430
|
+
- You can see how Agent Script instructions were compiled into the system prompt
|
|
431
|
+
- You can see the full conversation history (including grounding retry injections)
|
|
432
|
+
- You can verify that variable interpolation (`{!@variables.x}`) worked correctly
|
|
433
|
+
- You can see platform-injected system prompts (tool usage protocol, safety routing, language guidelines) that your Agent Script instructions sit alongside
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
### When to Use Traces vs. Transcript
|
|
437
|
+
|
|
438
|
+
Use the **transcript** to quickly identify WHICH turn failed (unexpected response, wrong topic, agent crash).
|
|
439
|
+
|
|
440
|
+
Use the **trace files** when:
|
|
441
|
+
- The agent routes to the wrong topic
|
|
442
|
+
- An action isn't firing
|
|
443
|
+
- The response is unexpectedly worded
|
|
444
|
+
- Grounding is failing
|
|
445
|
+
- You need to understand variable values at a specific point in execution
|
|
446
|
+
- You need to see what the LLM actually saw in its prompt
|
|
447
|
+
|
|
448
|
+
The transcript is sufficient for conversation-level understanding. Traces provide execution-level detail needed for diagnosis.
|
|
449
|
+
|
|
450
|
+
### Trace Diagnostic Checks
|
|
451
|
+
|
|
452
|
+
Use these `jq` commands against trace files (`traces/<PLAN_ID>.json`) to quickly extract diagnostic information.
|
|
453
|
+
|
|
454
|
+
#### Check 1: Topic Routing
|
|
455
|
+
|
|
456
|
+
```bash
|
|
457
|
+
jq '[.steps[] | select(.stepType == "TransitionStep") | .data.to]' "$TRACE"
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
**Expected**: Array contains the target topic name (e.g., `["order_mgmt"]`). Empty array means the agent stayed in Topic Selector — topic descriptions are too vague. Wrong topic name means keyword overlap between topics.
|
|
461
|
+
|
|
462
|
+
#### Check 2: Action Invocation
|
|
463
|
+
|
|
464
|
+
```bash
|
|
465
|
+
jq '[.steps[] | select(.stepType == "FunctionStep") | .data.function]' "$TRACE"
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
**Expected**: Array contains the target action name. If missing: `available when:` guards too restrictive, action `description:` doesn't match user request, or action not listed in `reasoning.actions:` for this topic.
|
|
469
|
+
|
|
470
|
+
#### Check 3: Wrong Action Selected
|
|
471
|
+
|
|
472
|
+
Use the same `jq` as Check 2 — compare output against expected action name. If the wrong action fired, two actions have overlapping descriptions. Differentiate with exclusion language and `available when:` guards.
|
|
473
|
+
|
|
474
|
+
#### Check 4: Grounding Assessment
|
|
475
|
+
|
|
476
|
+
```bash
|
|
477
|
+
jq '[.steps[] | select(.stepType == "ReasoningStep") | .data.groundingAssessment]' "$TRACE"
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
**Expected**: `"GROUNDED"` for all reasoning steps. `"UNGROUNDED"` means the agent fabricated data instead of using action outputs or variable values. Add explicit data references in `instructions: ->` block using `{!@variables.X}` or `{!@outputs.Y}`.
|
|
481
|
+
|
|
482
|
+
#### Check 5: Safety Score
|
|
483
|
+
|
|
484
|
+
```bash
|
|
485
|
+
jq '.steps[] | select(.stepType == "PlannerResponseStep") | .data.safetyScore' "$TRACE"
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
**Expected**: `.overall >= 0.9`. Low score indicates the agent is revealing internal system details, responding to harmful prompts without guardrails, or missing safety instructions in `system:` block.
|
|
489
|
+
|
|
490
|
+
#### Check 6: Tool Visibility
|
|
491
|
+
|
|
492
|
+
```bash
|
|
493
|
+
jq '[.steps[] | select(.stepType == "EnabledToolsStep") | .data.enabled_tools]' "$TRACE"
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
**Expected**: Array includes the action names defined in the topic's `reasoning.actions:`. If missing: `available when:` conditions not met, action defined in wrong topic, or action `target:` protocol invalid (flow not deployed, apex class not found).
|
|
497
|
+
|
|
498
|
+
---
|
|
499
|
+
|
|
500
|
+
## 5. Diagnostic Patterns
|
|
501
|
+
|
|
502
|
+
These patterns map symptoms to trace analysis techniques. Each pattern follows the same structure: symptom → which trace steps to examine → root cause → fix (with code example).
|
|
503
|
+
|
|
504
|
+
### Pattern: Wrong Topic Routing
|
|
505
|
+
|
|
506
|
+
**Symptom:** The agent enters the wrong topic. For example, asking about weather sends the agent to the events topic instead.
|
|
507
|
+
|
|
508
|
+
**Trace Analysis:**
|
|
509
|
+
|
|
510
|
+
1. Find the `LLMStep` where `agent_name` is `topic_selector` (the entry point that routes to topics)
|
|
511
|
+
2. Examine `tools_sent` — are the transition actions for all expected topics listed? (e.g., `go_to_local_weather`, `go_to_local_events`, `go_to_resort_hours`)
|
|
512
|
+
3. Examine `response_messages` — which action tool did the LLM select?
|
|
513
|
+
4. Examine `messages_sent` — does the system prompt (what topic selector instructions were compiled to) give the LLM enough context to route correctly?
|
|
514
|
+
|
|
515
|
+
**Root Cause:** Topic selector instructions are ambiguous, missing context, or don't map user requests to the correct topics.
|
|
516
|
+
|
|
517
|
+
**Fix:** A minimal topic selector with well-named actions often routes correctly. When it doesn't, add routing instructions and action descriptions to give the LLM more context:
|
|
518
|
+
|
|
519
|
+
```agentscript
|
|
520
|
+
# BEFORE — relies on action names alone for routing
|
|
521
|
+
start_agent topic_selector:
|
|
522
|
+
description: "Route to appropriate topics"
|
|
523
|
+
reasoning:
|
|
524
|
+
actions:
|
|
525
|
+
go_to_weather: @utils.transition to @topic.local_weather
|
|
526
|
+
go_to_events: @utils.transition to @topic.local_events
|
|
527
|
+
|
|
528
|
+
# AFTER — explicit instructions and descriptions improve routing accuracy
|
|
529
|
+
start_agent topic_selector:
|
|
530
|
+
description: "Route to appropriate topics"
|
|
531
|
+
reasoning:
|
|
532
|
+
instructions: ->
|
|
533
|
+
| If the user asks about weather conditions, temperature, or forecasts, go to the weather topic.
|
|
534
|
+
If the user asks about local events, activities, or entertainment, go to the events topic.
|
|
535
|
+
If the user asks about facility hours, reservations, or amenities, go to the hours topic.
|
|
536
|
+
|
|
537
|
+
actions:
|
|
538
|
+
go_to_weather: @utils.transition to @topic.local_weather
|
|
539
|
+
description: "Route to weather topic for weather questions"
|
|
540
|
+
go_to_events: @utils.transition to @topic.local_events
|
|
541
|
+
description: "Route to events topic for local event questions"
|
|
542
|
+
go_to_hours: @utils.transition to @topic.resort_hours
|
|
543
|
+
description: "Route to hours topic for facility hours questions"
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
### Pattern: Actions Not Firing
|
|
548
|
+
|
|
549
|
+
**Symptom:** The agent doesn't call an action you expect it to. For example, the agent should fetch data but responds without calling the action.
|
|
550
|
+
|
|
551
|
+
**Trace Analysis:**
|
|
552
|
+
|
|
553
|
+
1. Find the `EnabledToolsStep` for the topic — is the expected action listed?
|
|
554
|
+
2. If missing:
|
|
555
|
+
- Check the action definition's `available when` condition (e.g., `available when @variables.guest_interests != ""`)
|
|
556
|
+
- Look at the `NodeEntryStateStep` to see if the gating variable has the expected value
|
|
557
|
+
- If the variable is empty or has the wrong value, the action is hidden
|
|
558
|
+
3. If listed but not called:
|
|
559
|
+
- Find the `LLMStep` response — did the LLM choose a different action or respond without using any tool?
|
|
560
|
+
- Compare `messages_sent` — does the instructions tell the LLM when to use this action?
|
|
561
|
+
|
|
562
|
+
**Root Cause:** Either the action is gated behind a condition that hasn't been satisfied, or the instructions don't tell the LLM to call it.
|
|
563
|
+
|
|
564
|
+
**Fix Example:**
|
|
565
|
+
|
|
566
|
+
```agentscript
|
|
567
|
+
# WRONG — action is hidden until guest_interests is set, but there's no way to set it
|
|
568
|
+
reasoning:
|
|
569
|
+
actions:
|
|
570
|
+
check_events: @actions.check_events
|
|
571
|
+
available when @variables.guest_interests != ""
|
|
572
|
+
with Event_Type = @variables.guest_interests
|
|
573
|
+
|
|
574
|
+
# CORRECT — first step collects interests, second action uses them
|
|
575
|
+
reasoning:
|
|
576
|
+
instructions: ->
|
|
577
|
+
| Ask about the guest's interests if you don't know them yet.
|
|
578
|
+
Once you know what they're interested in, look up matching events.
|
|
579
|
+
|
|
580
|
+
actions:
|
|
581
|
+
collect_interests: @utils.setVariables
|
|
582
|
+
description: "Collect the guest's interests"
|
|
583
|
+
with guest_interests = ...
|
|
584
|
+
|
|
585
|
+
check_events: @actions.check_events
|
|
586
|
+
description: "Look up local events matching the guest's interests"
|
|
587
|
+
available when @variables.guest_interests != ""
|
|
588
|
+
with Event_Type = @variables.guest_interests
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
### Pattern: Behavioral Loops
|
|
593
|
+
|
|
594
|
+
**Symptom:** The agent keeps asking the same question or repeating the same response across multiple turns, even though the user already provided the requested information.
|
|
595
|
+
|
|
596
|
+
**Diagnosis:** Observe the conversation output first — the behavioral symptom is often obvious (e.g., the agent asking the same question repeatedly). A common cause is instructions that collect information and act on it within the same topic — when the topic is re-entered, the collection logic runs again even though the data was already gathered.
|
|
597
|
+
|
|
598
|
+
**Fix Example:** In this real scenario, the `local_events` topic asks about interests and then looks up events. But each time the topic is re-entered, the agent asks about interests again instead of checking whether it already knows them:
|
|
599
|
+
|
|
600
|
+
```agentscript
|
|
601
|
+
# BEFORE — agent asks about interests every time the topic is entered
|
|
602
|
+
reasoning:
|
|
603
|
+
instructions: ->
|
|
604
|
+
| If you do not already know the guest's interests, ask them about their
|
|
605
|
+
interests so you can provide relevant event information.
|
|
606
|
+
Use the {!@actions.check_events} action to get a list of events once
|
|
607
|
+
you know what the guest is interested in.
|
|
608
|
+
|
|
609
|
+
actions:
|
|
610
|
+
collect_interests: @utils.setVariables
|
|
611
|
+
description: "Collect the guest's interests when they share them"
|
|
612
|
+
with guest_interests = ...
|
|
613
|
+
|
|
614
|
+
check_events: @actions.check_events
|
|
615
|
+
available when @variables.guest_interests != ""
|
|
616
|
+
with Event_Type = @variables.guest_interests
|
|
617
|
+
|
|
618
|
+
# AFTER — condition on the variable, not on re-asking
|
|
619
|
+
reasoning:
|
|
620
|
+
instructions: ->
|
|
621
|
+
| If @variables.guest_interests is empty, ask the guest about their interests.
|
|
622
|
+
If @variables.guest_interests is already set, use {!@actions.check_events}
|
|
623
|
+
to find matching events and present the results.
|
|
624
|
+
Do NOT ask about interests again if you already have them.
|
|
625
|
+
|
|
626
|
+
actions:
|
|
627
|
+
collect_interests: @utils.setVariables
|
|
628
|
+
description: "Collect the guest's interests when they share them"
|
|
629
|
+
with guest_interests = ...
|
|
630
|
+
|
|
631
|
+
check_events: @actions.check_events
|
|
632
|
+
available when @variables.guest_interests != ""
|
|
633
|
+
with Event_Type = @variables.guest_interests
|
|
634
|
+
```
|
|
635
|
+
|
|
636
|
+
The key difference: the AFTER version explicitly references the variable value to decide whether to ask or act, and includes a stop condition ("Do NOT ask about interests again").
|
|
637
|
+
|
|
638
|
+
Note: repeated `LLMStep` → `ReasoningStep` pairs in a trace may indicate grounding retry rather than a behavioral loop — see Diagnostic Workflow: Grounding subsection.
|
|
639
|
+
|
|
640
|
+
### Pattern: "Unexpected Error" Responses
|
|
641
|
+
|
|
642
|
+
**Symptom:** The agent returns "I apologize, but I encountered an unexpected error" instead of a normal response.
|
|
643
|
+
|
|
644
|
+
**Trace Analysis:**
|
|
645
|
+
|
|
646
|
+
1. Find the `PlannerResponseStep` — is the message the system error message?
|
|
647
|
+
2. Look backward through the trace for consecutive `ReasoningStep` entries with `category: "UNGROUNDED"` — two consecutive UNGROUNDED results cause this error
|
|
648
|
+
3. If no grounding failures, look for `FunctionStep` entries with error outputs (action execution failed)
|
|
649
|
+
4. Check if a topic transition failed (the target topic doesn't exist or has a circular reference)
|
|
650
|
+
|
|
651
|
+
**Root Cause:** Grounding failed twice in a row, OR an action returned an error, OR a topic transition is misconfigured.
|
|
652
|
+
|
|
653
|
+
**Fix:** See Diagnostic Workflow: Grounding subsection for grounding failures. For action errors, verify the backing Apex/Flow/Prompt Template is deployed and handles edge cases correctly. For transition errors, verify all referenced topics exist and are spelled correctly.
|
|
654
|
+
|
|
655
|
+
### Pattern: Agent Responds with Generic Message but No Data After Successful Action
|
|
656
|
+
|
|
657
|
+
**Symptom:** Action returns data (visible in `FunctionStep.function.output`) but the agent's text response is empty or generic (e.g., "Here are the results:").
|
|
658
|
+
|
|
659
|
+
**Trace Analysis:**
|
|
660
|
+
|
|
661
|
+
1. Check `EnabledToolsStep` — it lists both your defined actions and platform-injected tools. Any tool you did not define is a platform tool.
|
|
662
|
+
2. Find the `LLMStep` after the `FunctionStep`. If `response_messages` contains a `tool_invocation` targeting a platform tool instead of a text response, the LLM chose that tool over composing a reply.
|
|
663
|
+
|
|
664
|
+
**Fix:** Update reasoning instructions to direct the LLM to write specific field values from the action response in its text reply. Name the fields. Block the observed platform tool by name.
|
|
665
|
+
|
|
666
|
+
### Fix Strategies Quick Reference
|
|
667
|
+
|
|
668
|
+
| Failure | Target Block | Edit Strategy | Example |
|
|
669
|
+
|---------|-------------|---------------|---------|
|
|
670
|
+
| Topic not matched | `topic X: description:` | Add keywords from test utterance | `"Handle orders"` → `"Handle order queries, order status, package tracking, shipping updates"` |
|
|
671
|
+
| Action not invoked | `reasoning.actions: X description:` | Make description more trigger-specific | `"Get order"` → `"Look up order status when user asks about their order, package, or delivery"` |
|
|
672
|
+
| Action not invoked | `available when:` | Relax guard condition | Remove overly restrictive `@variables.X == True` if variable isn't set yet |
|
|
673
|
+
| Wrong action selected | Both competing `description:` fields | Differentiate with exclusion language | Add `"NOT for returns"` to order action, `"ONLY for returns"` to refund action |
|
|
674
|
+
| Ungrounded response | `reasoning: instructions: ->` | Add explicit data references | `"Help the customer"` → `"Help the customer using {!@variables.order_data} from Get_Order action"` |
|
|
675
|
+
| Low safety score | `system: instructions:` | Add safety guidelines | Add `CRITICAL: Never reveal internal system details or customer PII` |
|
|
676
|
+
| Tool not visible | `available when:` | Ensure guard matches test state | Set test variables before action, or remove guards for initial smoke test |
|
|
677
|
+
|
|
678
|
+
---
|
|
679
|
+
|
|
680
|
+
## 6. Diagnostic Workflow
|
|
681
|
+
|
|
682
|
+
Use this systematic 8-step approach when diagnosing any agent behavior issue.
|
|
683
|
+
|
|
684
|
+
1. **Reproduce** — Use `sf agent preview start/send/end` with `--json` to recreate the issue with the exact user input that triggered it
|
|
685
|
+
|
|
686
|
+
2. **Locate** — Open `transcript.jsonl` and find the failing agent turn. Read the `planId` from its `raw` array.
|
|
687
|
+
|
|
688
|
+
3. **Read the Trace** — Open `traces/<PLAN_ID>.json` for the failing turn. Read the plan array in order.
|
|
689
|
+
|
|
690
|
+
4. **Follow Execution** — As you read each step, note:
|
|
691
|
+
- Which topic was selected? (Look at `NodeEntryStateStep`)
|
|
692
|
+
- What state were variables in? (Look at `SessionInitialStateStep` and `VariableUpdateStep`)
|
|
693
|
+
- What actions were available vs. invoked? (Look at `EnabledToolsStep` and `LLMStep` response)
|
|
694
|
+
- What did the LLM see in its prompt? (Look at `LLMStep.messages_sent`)
|
|
695
|
+
- What did it respond with? (Look at `LLMStep.response_messages`)
|
|
696
|
+
- Did the response pass grounding? (Look at `ReasoningStep.category`)
|
|
697
|
+
|
|
698
|
+
5. **Identify the Gap** — Compare expected behavior to actual execution at each step. Use the diagnostic patterns (Section 5) to map symptoms to root causes.
|
|
699
|
+
|
|
700
|
+
6. **Fix** — Update Agent Script instructions, variable logic, or action definitions based on what you found.
|
|
701
|
+
|
|
702
|
+
7. **Validate** — Run `sf agent validate authoring-bundle --api-name <AGENT_NAME> --json` to ensure the fix doesn't introduce syntax errors.
|
|
703
|
+
|
|
704
|
+
8. **Re-Test** — Run a new preview session with the same input and compare traces. Verify the fix resolved the issue.
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
### Grounding
|
|
708
|
+
|
|
709
|
+
Grounding is a platform service that validates an agent's response against real action output data. When grounding fails, the platform gives the LLM a second chance. Understanding how grounding works, why it fails, and how to fix it is critical for behavioral diagnosis.
|
|
710
|
+
|
|
711
|
+
#### The Grounding Retry Mechanism
|
|
712
|
+
|
|
713
|
+
When the platform's grounding checker flags a response as UNGROUNDED:
|
|
714
|
+
|
|
715
|
+
1. The system injects an error message as a `role: "user"` message:
|
|
716
|
+
```
|
|
717
|
+
Error: The system determined your original response was ungrounded.
|
|
718
|
+
Reason the response was flagged: [explanation]
|
|
719
|
+
Try again. Make sure to follow all system instructions.
|
|
720
|
+
Original query: [original user message]
|
|
721
|
+
```
|
|
722
|
+
2. The LLM is given another chance to respond
|
|
723
|
+
3. If the second attempt is also UNGROUNDED, the agent returns the system error message ("I apologize, but I encountered an unexpected error") and gives up
|
|
724
|
+
4. This retry is visible in traces as repeated `LLMStep` → `ReasoningStep` pairs for the same topic
|
|
725
|
+
5. When this happens, the actual action output is still in the trace's `FunctionStep.function.output`. The LLM's failed response attempts are in the `LLMStep.response_messages`. Use these to understand what the agent tried to say versus what the action actually returned.
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
#### Non-Deterministic Behavior
|
|
729
|
+
|
|
730
|
+
The grounding checker is non-deterministic. The same response may be flagged as UNGROUNDED on one attempt and GROUNDED on the next. When diagnosing intermittent grounding failures, look for responses that require the grounding checker to make inferences (date inference, unit conversions, paraphrased values).
|
|
731
|
+
|
|
732
|
+
#### Common Grounding Failure Causes
|
|
733
|
+
|
|
734
|
+
- **Date Inference:** Function returns a specific date (e.g., "2025-02-19"), agent says "today" or "this week". The grounding checker cannot always infer that a relative date equals a specific date.
|
|
735
|
+
- **Unit Conversion:** Function returns Celsius, agent responds in Fahrenheit without the grounding checker recognizing the conversion.
|
|
736
|
+
- **Embellishment:** Agent adds details not in the function output (e.g., "gentle breeze" when the function only returned temperature data).
|
|
737
|
+
- **Loose Paraphrasing:** Agent restates function output in words that don't closely match the original.
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
#### Diagnosing Grounding Failures
|
|
741
|
+
|
|
742
|
+
1. Find the `ReasoningStep` with `category: "UNGROUNDED"`
|
|
743
|
+
2. Read the `reason` field — it explains exactly what the grounding checker flagged
|
|
744
|
+
3. Find the `FunctionStep` output for the action that was called
|
|
745
|
+
4. Find the `LLMStep` response — compare it to the function output
|
|
746
|
+
5. Identify where the response diverges from the function output (dates, numbers, names, facts)
|
|
747
|
+
|
|
748
|
+
**Example:** Function returns:
|
|
749
|
+
```json
|
|
750
|
+
{"date": "2025-02-19", "temperature": "48.5F"}
|
|
751
|
+
```
|
|
752
|
+
|
|
753
|
+
Agent responds: "Today will be around 50 degrees."
|
|
754
|
+
|
|
755
|
+
Grounding fails because: "today" requires inference (the checker doesn't know if 2025-02-19 is today), and "around 50" doesn't match the specific value "48.5F".
|
|
756
|
+
|
|
757
|
+
#### Fix Approach
|
|
758
|
+
|
|
759
|
+
Update Agent Script instructions to tell the agent to use specific values from action output verbatim rather than paraphrasing or inferring.
|
|
760
|
+
|
|
761
|
+
```agentscript
|
|
762
|
+
# WRONG — allows paraphrasing and inference
|
|
763
|
+
reasoning:
|
|
764
|
+
instructions: ->
|
|
765
|
+
| Tell the user about the weather.
|
|
766
|
+
|
|
767
|
+
# CORRECT — explicit instructions to use verbatim values
|
|
768
|
+
reasoning:
|
|
769
|
+
instructions: ->
|
|
770
|
+
| After getting weather results, respond using the exact date and temperature
|
|
771
|
+
values returned by the action. Do NOT paraphrase dates (say "2025-02-19",
|
|
772
|
+
not "today"). Do NOT round temperatures (say the exact value from the results).
|
|
773
|
+
Quote action output values verbatim whenever possible.
|
|
774
|
+
```
|
|
775
|
+
|
|
776
|
+
#### Grounding in Simulated Preview Mode
|
|
777
|
+
|
|
778
|
+
The grounding checker runs in both simulated and live preview modes. However, simulated preview mode generates fake action outputs via LLM, and those outputs can trigger false grounding failures because they don't match real data patterns. If you see grounding failures during simulated preview, switch to live preview mode (`--use-live-actions`) before investing time in diagnosis — the failure may be an artifact of simulation, not a real instruction problem.
|
|
779
|
+
|
|
780
|
+
### Iterative Debugging Patterns
|
|
781
|
+
|
|
782
|
+
When fixing errors through repeated preview cycles, track how the error message changes between attempts. A different error after a fix usually means progress, not regression.
|
|
783
|
+
|
|
784
|
+
**Anti-pattern: reverting a correct fix because a new error appeared.**
|
|
785
|
+
|
|
786
|
+
```
|
|
787
|
+
# WRONG — assumes changed error = bad fix
|
|
788
|
+
Preview attempt 1: "Invalid complex_data_type_name format"
|
|
789
|
+
→ Fix: change complex_data_type_name to "@apexClassType/c__MyClass$Result"
|
|
790
|
+
Preview attempt 2: "Action output type mismatch"
|
|
791
|
+
→ Conclusion: "My fix broke something, reverting"
|
|
792
|
+
|
|
793
|
+
# RIGHT — recognize error evolution as forward progress
|
|
794
|
+
Preview attempt 1: "Invalid complex_data_type_name format"
|
|
795
|
+
→ Fix: change complex_data_type_name to "@apexClassType/c__MyClass$Result"
|
|
796
|
+
Preview attempt 2: "Action output type mismatch"
|
|
797
|
+
→ Conclusion: "Format is now valid. New error is a different layer — diagnose the type mismatch separately."
|
|
798
|
+
```
|
|
799
|
+
|
|
800
|
+
**Rule:** Compare the error message text, not just pass/fail. If the error changed, the previous fix likely resolved its target issue. Diagnose the new error as a separate problem. Only revert a fix if the *same* error persists or worsens.
|
|
801
|
+
|
|
802
|
+
---
|
|
803
|
+
|