SF-AI-AgentScript Skill
Agent Script is the code-first path for deterministic Agentforce agents. Use this skill when the user is authoring .agent files, building finite-state topic flows, or needs repeatable control over routing, variables, actions, and publish behavior.
Start with the shortest guide first: references/activation-checklist.md
Migrating from the Builder UI? Use references/migration-guide.md
When This Skill Owns the Task
Use sf-ai-agentscript when the work involves:
- creating or editing
.agent files
- deterministic topic routing, guards, and transitions
- Agent Script CLI workflows (
sf agent generate authoring-bundle, sf agent validate authoring-bundle, sf agent preview, sf agent publish authoring-bundle, sf agent activate)
- slot filling, instruction resolution, post-action loops, or FSM design
Delegate elsewhere when the user is:
If the user is in Builder Script / Canvas view but the outcome is a .agent authoring bundle, keep the work in sf-ai-agentscript.
Right-Size Determinism
- Determinism is a dial, not a destination.
- Use Agent Script when “mostly right” is not acceptable: gates, mandatory sequencing, explicit state transitions, compliance, or drift control.
- If a workflow is fully static and linear, use Flow or Apex instead of scripting the conversation.
- Prefer a deterministic envelope: deterministic entry/gate → flexible middle → deterministic closeout.
- More determinism is not automatically better. Start minimal, then harden only the parts that show routing drift, sequencing failures, or compliance risk.
Required Context to Gather First
Ask for or infer:
- agent purpose and whether Agent Script is truly the right fit
- Service Agent vs Employee Agent
- target org and publish intent
- expected actions / targets (Flow, Apex, PromptTemplate, etc.)
- whether the request is authoring, validation, preview, or publish troubleshooting
Activation Checklist
Before you author or fix any .agent file, verify these first:
- Exactly one
start_agent block
- No mixed tabs and spaces
- Booleans are
True / False
- No
else if and no nested if
- No top-level
actions: block
- No
@inputs in set expressions
linked variables have no defaults
linked variables do not use object / list types
- Use explicit
agent_type
- Use
@actions. prefixes consistently
- Use
run @actions.X only when X is a topic-level action definition with target:
- Do not branch directly on raw
@system_variables.user_input contains/startswith/endswith for intent routing
- On prompt-template outputs, prefer
is_displayable: False + is_used_by_planner: True
- Do not assume
@outputs.X is scalar — inspect the output schema before branching or assignment
For the expanded version, use references/activation-checklist.md.
Non-Negotiable Rules
1) Service Agent vs Employee Agent
| Agent type |
Required |
Forbidden / caution |
AgentforceServiceAgent |
Valid default_agent_user, correct permissions, target-org checks, prefer sf org create agent-user |
Publishing without a real Einstein Agent User |
AgentforceEmployeeAgent |
Explicit agent_type |
Supplying default_agent_user |
Full details: references/agent-user-setup.md
2) Recommended top-level block convention
Use this order for consistency in this skill's examples and reviews:
config:
variables:
system:
connection:
knowledge:
language:
start_agent:
topic:
Official Salesforce materials present top-level blocks in differing sequences, and local validation evidence indicates multiple orderings compile. Treat this as a style convention, not a standalone correctness or publish blocker.
3) Critical config fields
| Field |
Rule |
developer_name |
Must match folder / bundle name |
description |
Public docs/examples should use this config field |
agent_type |
Set explicitly every time |
default_agent_user |
Service Agents only |
Local tooling also accepts agent_description: for compatibility, but this skill's public docs and examples should prefer description:.
4) Syntax blockers you should treat as immediate failures
else if
- nested
if
- comment-only
if bodies
- top-level
actions:
- invocation-level
inputs: / outputs: blocks
- reserved variable / field names like
description and label
Canonical rule set: references/syntax-reference.md and references/validator-rule-catalog.md
Recommended Workflow
Recommended Authoring Workflow
Phase 1 — design the agent
- decide whether the problem is actually deterministic enough for Agent Script
- model topics as states and transitions as edges
- define only the variables you truly need
Phase 2 — author the .agent
- create
config, system, start_agent, and topics first
- add target-backed actions with full
inputs: and outputs:
- use
available when for deterministic tool visibility
- normalize raw intent/validation signals into booleans or enums before branching; avoid direct substring checks on raw user utterances for critical control flow
- keep post-action checks at the top of
instructions: ->
Default authoring stance
- Default to direct
.agent authoring and edits in source control.
- Use
sf agent generate authoring-bundle --no-spec only when the user wants local bundle scaffolding.
- Treat
sf agent generate agent-spec as optional ideation / topic bootstrap, not the default workflow.
- Do not route Agent Script users toward
sf agent create or sf agent generate template.
Phase 3 — validate continuously
Validation already runs automatically on write/edit. Use the CLI before publish:
sf agent validate authoring-bundle --api-name MyAgent -o TARGET_ORG --json
The validator covers structure, runtime gotchas, target readiness, and org-aware Service Agent checks. Rule IDs live in references/validator-rule-catalog.md.
Phase 4 — preview smoke test
Use the preview loop before publish:
- derive 3–5 smoke utterances
- start preview with the
start / send / end subcommands, not bare sf agent preview
- if you use
--authoring-bundle, always choose a mode explicitly: --simulate-actions or --use-live-actions
- inspect topic routing / action invocation / safety / grounding
- fix and rerun up to 3 times
Full loop: references/preview-test-loop.md
Phase 5 — publish and activate
sf agent publish authoring-bundle --api-name MyAgent -o TARGET_ORG --json
# Manual activation
sf agent activate --api-name MyAgent -o TARGET_ORG
# CI / deterministic activation of a known BotVersion
sf agent activate --api-name MyAgent --version <n> -o TARGET_ORG --json
Publishing does not activate the agent.
For automation, prefer --version <n> --json so activation is deterministic and machine-readable.
Deterministic Building Blocks
These execute as code, not suggestions:
- conditionals
available when guards
- variable checks
- direct
set / transition to
run @actions.X only when X is a topic-level action definition with target:
- variable injection into LLM-facing text
Important distinction:
- Deterministic:
set, transition to, and run @actions.X for a target-backed topic action
- LLM-directed:
reasoning.actions: utilities / delegations such as @utils.setVariables, @utils.transition, and {!@actions.X} instruction references
If you need deterministic behavior for something that is currently modeled as a reasoning-level utility, either:
- rewrite it as direct
set / transition to, or
- promote it to a topic-level target-backed action and
run that action
See references/instruction-resolution.md and references/architecture-patterns.md.
Cross-Skill Integration
Cross-Skill Orchestration
| Task |
Delegate to |
Why |
Build flow:// targets |
sf-flow |
Flow creation / validation |
| Build Apex action targets |
sf-apex |
@InvocableMethod and business logic |
| Test topic routing / actions |
sf-ai-agentforce-testing |
Formal test specs and fix loops |
| Deploy / publish |
sf-deploy |
Deployment orchestration |
High-Signal Failure Patterns
| Symptom |
Likely cause |
Read next |
Internal Error during publish |
invalid Service Agent user or missing action I/O |
references/agent-user-setup.md, references/actions-reference.md |
invalid input/output parameters on prompt template action |
Target template is in Draft status — activate it first |
references/action-prompt-templates.md |
| Parser rejects conditionals |
else if, nested if, empty if body |
references/syntax-reference.md |
| Action target issues |
missing Flow / Apex target, inactive Flow, bad schemas |
references/actions-reference.md |
| Prompt template runs but user sees blank response |
prompt output marked is_displayable: True |
references/production-gotchas.md, references/action-prompt-templates.md |
| Prompt action runs but planner behaves like output is missing |
output hidden from direct display but not planner-visible |
references/production-gotchas.md, references/actions-reference.md |
ACTION_NOT_IN_SCOPE on run @actions.X |
run points at a utility / delegation / unresolved action instead of a topic-level target-backed definition |
references/syntax-reference.md, references/instruction-resolution.md |
| Deterministic cancel / revise / URL checks behave inconsistently |
raw @system_variables.user_input matching or string-method guards are being used as control-flow-critical validation |
references/syntax-reference.md, references/production-gotchas.md |
@outputs.X comparisons or assignments behave unexpectedly |
the action output is structured/wrapped, not a plain scalar |
references/actions-reference.md, references/syntax-reference.md |
| Preview and runtime disagree |
linked vars / context / known platform issues |
references/known-issues.md |
| Validate passes but publish fails |
org-specific user / permission / retrieve-back issue |
references/production-gotchas.md, references/cli-guide.md |
Reference Map
Start here
- references/activation-checklist.md
- references/syntax-reference.md
- references/actions-reference.md
Publish / runtime safety
- references/agent-user-setup.md
- references/production-gotchas.md
- references/customer-web-client.md
- references/known-issues.md
Architecture / reasoning
- references/architecture-patterns.md
- references/instruction-resolution.md
- references/fsm-architecture.md
- references/patterns-quick-ref.md
Validation / testing / debugging
- references/preview-test-loop.md
- references/testing-guide.md
- references/debugging-guide.md
- references/validator-rule-catalog.md
Examples / scaffolds
- references/minimal-examples.md
- references/migration-guide.md
- assets/
- assets/agents/
- assets/patterns/
Project documentation
- references/version-history.md
- references/sources.md
Score Guide
| Score |
Meaning |
| 90+ |
Deploy with confidence |
| 75–89 |
Good, review warnings |
| 60–74 |
Needs focused revision |
| < 60 |
Block publish |
Full rubric: references/scoring-rubric.md
Official Resources
1---2name: sf-ai-agentscript3description: Agent Script DSL for deterministic Agentforce agents. TRIGGER when: user writes or edits .agent files, builds FSM-based agents, uses Agent Script CLI (sf agent generate authoring-bundle, sf agent validate authoring-bundle, sf agent preview, sf agent publish authoring-bundle, sf agent activate), or asks about deterministic agent patterns, slot filling, or instruction resolution. DO NOT TRIGGER when: Builder metadata work (use sf-ai-agentforce), agent testing (use sf-ai-agentforce-testing), or persona design (use sf-ai-agentforce-persona).4license: MIT5---67# SF-AI-AgentScript Skill89Agent Script is the **code-first** path for deterministic Agentforce agents. Use this skill when the user is authoring `.agent` files, building finite-state topic flows, or needs repeatable control over routing, variables, actions, and publish behavior.1011> Start with the shortest guide first: [references/activation-checklist.md](references/activation-checklist.md)12>13> Migrating from the Builder UI? Use [references/migration-guide.md](references/migration-guide.md)1415## When This Skill Owns the Task1617Use `sf-ai-agentscript` when the work involves:18- creating or editing `.agent` files19- deterministic topic routing, guards, and transitions20- Agent Script CLI workflows (`sf agent generate authoring-bundle`, `sf agent validate authoring-bundle`, `sf agent preview`, `sf agent publish authoring-bundle`, `sf agent activate`)21- slot filling, instruction resolution, post-action loops, or FSM design2223Delegate elsewhere when the user is:24- maintaining Builder metadata agents (`GenAiFunction`, `GenAiPlugin`, `GenAiPromptTemplate`, Models API, custom Lightning types) → [sf-ai-agentforce](../sf-ai-agentforce/SKILL.md)25- designing persona / tone / voice → [sf-ai-agentforce-persona](../sf-ai-agentforce-persona/SKILL.md)26- building formal test plans or coverage loops → [sf-ai-agentforce-testing](../sf-ai-agentforce-testing/SKILL.md)2728If the user is in Builder Script / Canvas view but the outcome is a `.agent` authoring bundle, keep the work in `sf-ai-agentscript`.2930---3132## Right-Size Determinism3334- Determinism is a dial, not a destination.35- Use Agent Script when “mostly right” is not acceptable: gates, mandatory sequencing, explicit state transitions, compliance, or drift control.36- If a workflow is fully static and linear, use Flow or Apex instead of scripting the conversation.37- Prefer a deterministic envelope: deterministic entry/gate → flexible middle → deterministic closeout.38- More determinism is not automatically better. Start minimal, then harden only the parts that show routing drift, sequencing failures, or compliance risk.3940---4142## Required Context to Gather First4344Ask for or infer:45- agent purpose and whether Agent Script is truly the right fit46- Service Agent vs Employee Agent47- target org and publish intent48- expected actions / targets (Flow, Apex, PromptTemplate, etc.)49- whether the request is authoring, validation, preview, or publish troubleshooting5051---5253## Activation Checklist5455Before you author or fix any `.agent` file, verify these first:56571. **Exactly one `start_agent` block**582. **No mixed tabs and spaces**593. **Booleans are `True` / `False`**604. **No `else if` and no nested `if`**615. **No top-level `actions:` block**626. **No `@inputs` in `set` expressions**637. **`linked` variables have no defaults**648. **`linked` variables do not use `object` / `list` types**659. **Use explicit `agent_type`**6610. **Use `@actions.` prefixes consistently**6711. **Use `run @actions.X` only when `X` is a topic-level action definition with `target:`**6812. **Do not branch directly on raw `@system_variables.user_input contains/startswith/endswith` for intent routing**6913. **On prompt-template outputs, prefer `is_displayable: False` + `is_used_by_planner: True`**7014. **Do not assume `@outputs.X` is scalar — inspect the output schema before branching or assignment**7172For the expanded version, use [references/activation-checklist.md](references/activation-checklist.md).7374---7576## Non-Negotiable Rules7778### 1) Service Agent vs Employee Agent7980| Agent type | Required | Forbidden / caution |81|---|---|---|82| `AgentforceServiceAgent` | Valid `default_agent_user`, correct permissions, target-org checks, prefer `sf org create agent-user` | Publishing without a real Einstein Agent User |83| `AgentforceEmployeeAgent` | Explicit `agent_type` | Supplying `default_agent_user` |8485Full details: [references/agent-user-setup.md](references/agent-user-setup.md)8687### 2) Recommended top-level block convention8889Use this order for consistency in this skill's examples and reviews:9091```yaml92config:93variables:94system:95connection:96knowledge:97language:98start_agent:99topic:100```101102Official Salesforce materials present top-level blocks in differing sequences, and local validation evidence indicates multiple orderings compile. Treat this as a style convention, not a standalone correctness or publish blocker.103104### 3) Critical config fields105106| Field | Rule |107|---|---|108| `developer_name` | Must match folder / bundle name |109| `description` | Public docs/examples should use this config field |110| `agent_type` | Set explicitly every time |111| `default_agent_user` | Service Agents only |112113Local tooling also accepts `agent_description:` for compatibility, but this skill's public docs and examples should prefer `description:`.114115### 4) Syntax blockers you should treat as immediate failures116117- `else if`118- nested `if`119- comment-only `if` bodies120- top-level `actions:`121- invocation-level `inputs:` / `outputs:` blocks122- reserved variable / field names like `description` and `label`123124Canonical rule set: [references/syntax-reference.md](references/syntax-reference.md) and [references/validator-rule-catalog.md](references/validator-rule-catalog.md)125126---127128## Recommended Workflow129130## Recommended Authoring Workflow131132### Phase 1 — design the agent133- decide whether the problem is actually deterministic enough for Agent Script134- model topics as states and transitions as edges135- define only the variables you truly need136137### Phase 2 — author the `.agent`138- create `config`, `system`, `start_agent`, and topics first139- add target-backed actions with full `inputs:` and `outputs:`140- use `available when` for deterministic tool visibility141- normalize raw intent/validation signals into booleans or enums before branching; avoid direct substring checks on raw user utterances for critical control flow142- keep post-action checks at the **top** of `instructions: ->`143144### Default authoring stance145146- Default to direct `.agent` authoring and edits in source control.147- Use `sf agent generate authoring-bundle --no-spec` only when the user wants local bundle scaffolding.148- Treat `sf agent generate agent-spec` as optional ideation / topic bootstrap, not the default workflow.149- Do not route Agent Script users toward `sf agent create` or `sf agent generate template`.150151### Phase 3 — validate continuously152Validation already runs automatically on write/edit. Use the CLI before publish:153154```bash155sf agent validate authoring-bundle --api-name MyAgent -o TARGET_ORG --json156```157158The validator covers structure, runtime gotchas, target readiness, and org-aware Service Agent checks. Rule IDs live in [references/validator-rule-catalog.md](references/validator-rule-catalog.md).159160### Phase 4 — preview smoke test161Use the preview loop before publish:162- derive 3–5 smoke utterances163- start preview with the `start` / `send` / `end` subcommands, not bare `sf agent preview`164- if you use `--authoring-bundle`, always choose a mode explicitly: `--simulate-actions` or `--use-live-actions`165- inspect topic routing / action invocation / safety / grounding166- fix and rerun up to 3 times167168Full loop: [references/preview-test-loop.md](references/preview-test-loop.md)169170### Phase 5 — publish and activate171```bash172sf agent publish authoring-bundle --api-name MyAgent -o TARGET_ORG --json173174# Manual activation175sf agent activate --api-name MyAgent -o TARGET_ORG176177# CI / deterministic activation of a known BotVersion178sf agent activate --api-name MyAgent --version <n> -o TARGET_ORG --json179```180181Publishing does **not** activate the agent.182For automation, prefer `--version <n> --json` so activation is deterministic and machine-readable.183184---185186## Deterministic Building Blocks187188These execute as code, not suggestions:189- conditionals190- `available when` guards191- variable checks192- direct `set` / `transition to`193- `run @actions.X` **only when `X` is a topic-level action definition with `target:`**194- variable injection into LLM-facing text195196Important distinction:197- **Deterministic**: `set`, `transition to`, and `run @actions.X` for a target-backed topic action198- **LLM-directed**: `reasoning.actions:` utilities / delegations such as `@utils.setVariables`, `@utils.transition`, and `{!@actions.X}` instruction references199200If you need deterministic behavior for something that is currently modeled as a reasoning-level utility, either:201- rewrite it as direct `set` / `transition to`, or202- promote it to a topic-level target-backed action and `run` that action203204See [references/instruction-resolution.md](references/instruction-resolution.md) and [references/architecture-patterns.md](references/architecture-patterns.md).205206---207208## Cross-Skill Integration209210## Cross-Skill Orchestration211212| Task | Delegate to | Why |213|---|---|---|214| Build `flow://` targets | [sf-flow](../sf-flow/SKILL.md) | Flow creation / validation |215| Build Apex action targets | [sf-apex](../sf-apex/SKILL.md) | `@InvocableMethod` and business logic |216| Test topic routing / actions | [sf-ai-agentforce-testing](../sf-ai-agentforce-testing/SKILL.md) | Formal test specs and fix loops |217| Deploy / publish | [sf-deploy](../sf-deploy/SKILL.md) | Deployment orchestration |218219---220221## High-Signal Failure Patterns222223| Symptom | Likely cause | Read next |224|---|---|---|225| `Internal Error` during publish | invalid Service Agent user or missing action I/O | [references/agent-user-setup.md](references/agent-user-setup.md), [references/actions-reference.md](references/actions-reference.md) |226| `invalid input/output parameters` on prompt template action | **Target template is in Draft status** — activate it first | [references/action-prompt-templates.md](references/action-prompt-templates.md#draft-template-publish-errors) |227| Parser rejects conditionals | `else if`, nested `if`, empty `if` body | [references/syntax-reference.md](references/syntax-reference.md) |228| Action target issues | missing Flow / Apex target, inactive Flow, bad schemas | [references/actions-reference.md](references/actions-reference.md) |229| Prompt template runs but user sees blank response | prompt output marked `is_displayable: True` | [references/production-gotchas.md](references/production-gotchas.md), [references/action-prompt-templates.md](references/action-prompt-templates.md) |230| Prompt action runs but planner behaves like output is missing | output hidden from direct display but not planner-visible | [references/production-gotchas.md](references/production-gotchas.md), [references/actions-reference.md](references/actions-reference.md) |231| `ACTION_NOT_IN_SCOPE` on `run @actions.X` | `run` points at a utility / delegation / unresolved action instead of a topic-level target-backed definition | [references/syntax-reference.md](references/syntax-reference.md), [references/instruction-resolution.md](references/instruction-resolution.md) |232| Deterministic cancel / revise / URL checks behave inconsistently | raw `@system_variables.user_input` matching or string-method guards are being used as control-flow-critical validation | [references/syntax-reference.md](references/syntax-reference.md), [references/production-gotchas.md](references/production-gotchas.md) |233| `@outputs.X` comparisons or assignments behave unexpectedly | the action output is structured/wrapped, not a plain scalar | [references/actions-reference.md](references/actions-reference.md), [references/syntax-reference.md](references/syntax-reference.md) |234| Preview and runtime disagree | linked vars / context / known platform issues | [references/known-issues.md](references/known-issues.md) |235| Validate passes but publish fails | org-specific user / permission / retrieve-back issue | [references/production-gotchas.md](references/production-gotchas.md), [references/cli-guide.md](references/cli-guide.md) |236237---238239## Reference Map240241### Start here242- [references/activation-checklist.md](references/activation-checklist.md)243- [references/syntax-reference.md](references/syntax-reference.md)244- [references/actions-reference.md](references/actions-reference.md)245246### Publish / runtime safety247- [references/agent-user-setup.md](references/agent-user-setup.md)248- [references/production-gotchas.md](references/production-gotchas.md)249- [references/customer-web-client.md](references/customer-web-client.md)250- [references/known-issues.md](references/known-issues.md)251252### Architecture / reasoning253- [references/architecture-patterns.md](references/architecture-patterns.md)254- [references/instruction-resolution.md](references/instruction-resolution.md)255- [references/fsm-architecture.md](references/fsm-architecture.md)256- [references/patterns-quick-ref.md](references/patterns-quick-ref.md)257258### Validation / testing / debugging259- [references/preview-test-loop.md](references/preview-test-loop.md)260- [references/testing-guide.md](references/testing-guide.md)261- [references/debugging-guide.md](references/debugging-guide.md)262- [references/validator-rule-catalog.md](references/validator-rule-catalog.md)263264### Examples / scaffolds265- [references/minimal-examples.md](references/minimal-examples.md)266- [references/migration-guide.md](references/migration-guide.md)267- [assets/](assets/)268- [assets/agents/](assets/agents/)269- [assets/patterns/](assets/patterns/)270271### Project documentation272- [references/version-history.md](references/version-history.md)273- [references/sources.md](references/sources.md)274275---276277## Score Guide278279| Score | Meaning |280|---|---|281| 90+ | Deploy with confidence |282| 75–89 | Good, review warnings |283| 60–74 | Needs focused revision |284| < 60 | Block publish |285286Full rubric: [references/scoring-rubric.md](references/scoring-rubric.md)287288---289290## Official Resources291292- [Agent Script Documentation](https://developer.salesforce.com/docs/ai/agentforce/guide/agent-script.html)293- [Agent Script Recipes](https://github.com/trailheadapps/agent-script-recipes)294- [Agentforce DX Guide](https://developer.salesforce.com/docs/ai/agentforce/guide/agent-dx.html)295- [references/official-sources.md](references/official-sources.md)