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: >4 Agent Script DSL for deterministic Agentforce agents.5 TRIGGER when: user writes or edits .agent files, builds FSM-based agents,6 uses Agent Script CLI (sf agent generate authoring-bundle, sf agent validate7 authoring-bundle, sf agent preview, sf agent publish authoring-bundle, sf8 agent activate), or asks about deterministic agent patterns, slot filling, or9 instruction resolution.10 DO NOT TRIGGER when: Builder metadata work (use sf-ai-agentforce), agent11 testing (use sf-ai-agentforce-testing), or persona design12 (use sf-ai-agentforce-persona).13license: MIT14compatibility: "Requires Agentforce license and API v66.0+; Einstein Agent User is required for Service Agents only"15metadata:16 source: https://skillmd.com/skills/om-scogo/sf-ai-agentscript17 version: "2.9.0"18 author: "Jag Valaiyapathy"19 scoring: "100 points across 6 categories"20 validated: "0-shot generation tested against multiple representative sample agents. Agent user setup validated against representative Service Agent and Employee Agent scenarios."21 last_validated: "2026-03-20"22 validation_status: "PASS"23 validation_agents: "24"24 validate_by: "2026-04-10"25---2627# SF-AI-AgentScript Skill2829Agent 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.3031> Start with the shortest guide first: [references/activation-checklist.md](references/activation-checklist.md)32>33> Migrating from the Builder UI? Use [references/migration-guide.md](references/migration-guide.md)3435## When This Skill Owns the Task3637Use `sf-ai-agentscript` when the work involves:38- creating or editing `.agent` files39- deterministic topic routing, guards, and transitions40- 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`)41- slot filling, instruction resolution, post-action loops, or FSM design4243Delegate elsewhere when the user is:44- maintaining Builder metadata agents (`GenAiFunction`, `GenAiPlugin`, `GenAiPromptTemplate`, Models API, custom Lightning types) → [sf-ai-agentforce](../sf-ai-agentforce/SKILL.md)45- designing persona / tone / voice → [sf-ai-agentforce-persona](../sf-ai-agentforce-persona/SKILL.md)46- building formal test plans or coverage loops → [sf-ai-agentforce-testing](../sf-ai-agentforce-testing/SKILL.md)4748If the user is in Builder Script / Canvas view but the outcome is a `.agent` authoring bundle, keep the work in `sf-ai-agentscript`.4950---5152## Right-Size Determinism5354- Determinism is a dial, not a destination.55- Use Agent Script when “mostly right” is not acceptable: gates, mandatory sequencing, explicit state transitions, compliance, or drift control.56- If a workflow is fully static and linear, use Flow or Apex instead of scripting the conversation.57- Prefer a deterministic envelope: deterministic entry/gate → flexible middle → deterministic closeout.58- More determinism is not automatically better. Start minimal, then harden only the parts that show routing drift, sequencing failures, or compliance risk.5960---6162## Required Context to Gather First6364Ask for or infer:65- agent purpose and whether Agent Script is truly the right fit66- Service Agent vs Employee Agent67- target org and publish intent68- expected actions / targets (Flow, Apex, PromptTemplate, etc.)69- whether the request is authoring, validation, preview, or publish troubleshooting7071---7273## Activation Checklist7475Before you author or fix any `.agent` file, verify these first:76771. **Exactly one `start_agent` block**782. **No mixed tabs and spaces**793. **Booleans are `True` / `False`**804. **No `else if` and no nested `if`**815. **No top-level `actions:` block**826. **No `@inputs` in `set` expressions**837. **`linked` variables have no defaults**848. **`linked` variables do not use `object` / `list` types**859. **Use explicit `agent_type`**8610. **Use `@actions.` prefixes consistently**8711. **Use `run @actions.X` only when `X` is a topic-level action definition with `target:`**8812. **Do not branch directly on raw `@system_variables.user_input contains/startswith/endswith` for intent routing**8913. **On prompt-template outputs, prefer `is_displayable: False` + `is_used_by_planner: True`**9014. **Do not assume `@outputs.X` is scalar — inspect the output schema before branching or assignment**9192For the expanded version, use [references/activation-checklist.md](references/activation-checklist.md).9394---9596## Non-Negotiable Rules9798### 1) Service Agent vs Employee Agent99100| Agent type | Required | Forbidden / caution |101|---|---|---|102| `AgentforceServiceAgent` | Valid `default_agent_user`, correct permissions, target-org checks, prefer `sf org create agent-user` | Publishing without a real Einstein Agent User |103| `AgentforceEmployeeAgent` | Explicit `agent_type` | Supplying `default_agent_user` |104105Full details: [references/agent-user-setup.md](references/agent-user-setup.md)106107### 2) Recommended top-level block convention108109Use this order for consistency in this skill's examples and reviews:110111```yaml112config:113variables:114system:115connection:116knowledge:117language:118start_agent:119topic:120```121122Official 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.123124### 3) Critical config fields125126| Field | Rule |127|---|---|128| `developer_name` | Must match folder / bundle name |129| `description` | Public docs/examples should use this config field |130| `agent_type` | Set explicitly every time |131| `default_agent_user` | Service Agents only |132133Local tooling also accepts `agent_description:` for compatibility, but this skill's public docs and examples should prefer `description:`.134135### 4) Syntax blockers you should treat as immediate failures136137- `else if`138- nested `if`139- comment-only `if` bodies140- top-level `actions:`141- invocation-level `inputs:` / `outputs:` blocks142- reserved variable / field names like `description` and `label`143144Canonical rule set: [references/syntax-reference.md](references/syntax-reference.md) and [references/validator-rule-catalog.md](references/validator-rule-catalog.md)145146---147148## Recommended Workflow149150## Recommended Authoring Workflow151152### Phase 1 — design the agent153- decide whether the problem is actually deterministic enough for Agent Script154- model topics as states and transitions as edges155- define only the variables you truly need156157### Phase 2 — author the `.agent`158- create `config`, `system`, `start_agent`, and topics first159- add target-backed actions with full `inputs:` and `outputs:`160- use `available when` for deterministic tool visibility161- normalize raw intent/validation signals into booleans or enums before branching; avoid direct substring checks on raw user utterances for critical control flow162- keep post-action checks at the **top** of `instructions: ->`163164### Default authoring stance165166- Default to direct `.agent` authoring and edits in source control.167- Use `sf agent generate authoring-bundle --no-spec` only when the user wants local bundle scaffolding.168- Treat `sf agent generate agent-spec` as optional ideation / topic bootstrap, not the default workflow.169- Do not route Agent Script users toward `sf agent create` or `sf agent generate template`.170171### Phase 3 — validate continuously172Validation already runs automatically on write/edit. Use the CLI before publish:173174```bash175sf agent validate authoring-bundle --api-name MyAgent -o TARGET_ORG --json176```177178The 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).179180### Phase 4 — preview smoke test181Use the preview loop before publish:182- derive 3–5 smoke utterances183- start preview with the `start` / `send` / `end` subcommands, not bare `sf agent preview`184- if you use `--authoring-bundle`, always choose a mode explicitly: `--simulate-actions` or `--use-live-actions`185- inspect topic routing / action invocation / safety / grounding186- fix and rerun up to 3 times187188Full loop: [references/preview-test-loop.md](references/preview-test-loop.md)189190### Phase 5 — publish and activate191```bash192sf agent publish authoring-bundle --api-name MyAgent -o TARGET_ORG --json193194# Manual activation195sf agent activate --api-name MyAgent -o TARGET_ORG196197# CI / deterministic activation of a known BotVersion198sf agent activate --api-name MyAgent --version <n> -o TARGET_ORG --json199```200201Publishing does **not** activate the agent.202For automation, prefer `--version <n> --json` so activation is deterministic and machine-readable.203204---205206## Deterministic Building Blocks207208These execute as code, not suggestions:209- conditionals210- `available when` guards211- variable checks212- direct `set` / `transition to`213- `run @actions.X` **only when `X` is a topic-level action definition with `target:`**214- variable injection into LLM-facing text215216Important distinction:217- **Deterministic**: `set`, `transition to`, and `run @actions.X` for a target-backed topic action218- **LLM-directed**: `reasoning.actions:` utilities / delegations such as `@utils.setVariables`, `@utils.transition`, and `{!@actions.X}` instruction references219220If you need deterministic behavior for something that is currently modeled as a reasoning-level utility, either:221- rewrite it as direct `set` / `transition to`, or222- promote it to a topic-level target-backed action and `run` that action223224See [references/instruction-resolution.md](references/instruction-resolution.md) and [references/architecture-patterns.md](references/architecture-patterns.md).225226---227228## Cross-Skill Integration229230## Cross-Skill Orchestration231232| Task | Delegate to | Why |233|---|---|---|234| Build `flow://` targets | [sf-flow](../sf-flow/SKILL.md) | Flow creation / validation |235| Build Apex action targets | [sf-apex](../sf-apex/SKILL.md) | `@InvocableMethod` and business logic |236| Test topic routing / actions | [sf-ai-agentforce-testing](../sf-ai-agentforce-testing/SKILL.md) | Formal test specs and fix loops |237| Deploy / publish | [sf-deploy](../sf-deploy/SKILL.md) | Deployment orchestration |238239---240241## High-Signal Failure Patterns242243| Symptom | Likely cause | Read next |244|---|---|---|245| `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) |246| `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) |247| Parser rejects conditionals | `else if`, nested `if`, empty `if` body | [references/syntax-reference.md](references/syntax-reference.md) |248| Action target issues | missing Flow / Apex target, inactive Flow, bad schemas | [references/actions-reference.md](references/actions-reference.md) |249| 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) |250| 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) |251| `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) |252| 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) |253| `@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) |254| Preview and runtime disagree | linked vars / context / known platform issues | [references/known-issues.md](references/known-issues.md) |255| 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) |256257---258259## Reference Map260261### Start here262- [references/activation-checklist.md](references/activation-checklist.md)263- [references/syntax-reference.md](references/syntax-reference.md)264- [references/actions-reference.md](references/actions-reference.md)265266### Publish / runtime safety267- [references/agent-user-setup.md](references/agent-user-setup.md)268- [references/production-gotchas.md](references/production-gotchas.md)269- [references/customer-web-client.md](references/customer-web-client.md)270- [references/known-issues.md](references/known-issues.md)271272### Architecture / reasoning273- [references/architecture-patterns.md](references/architecture-patterns.md)274- [references/instruction-resolution.md](references/instruction-resolution.md)275- [references/fsm-architecture.md](references/fsm-architecture.md)276- [references/patterns-quick-ref.md](references/patterns-quick-ref.md)277278### Validation / testing / debugging279- [references/preview-test-loop.md](references/preview-test-loop.md)280- [references/testing-guide.md](references/testing-guide.md)281- [references/debugging-guide.md](references/debugging-guide.md)282- [references/validator-rule-catalog.md](references/validator-rule-catalog.md)283284### Examples / scaffolds285- [references/minimal-examples.md](references/minimal-examples.md)286- [references/migration-guide.md](references/migration-guide.md)287- [assets/](assets/)288- [assets/agents/](assets/agents/)289- [assets/patterns/](assets/patterns/)290291### Project documentation292- [references/version-history.md](references/version-history.md)293- [references/sources.md](references/sources.md)294295---296297## Score Guide298299| Score | Meaning |300|---|---|301| 90+ | Deploy with confidence |302| 75–89 | Good, review warnings |303| 60–74 | Needs focused revision |304| < 60 | Block publish |305306Full rubric: [references/scoring-rubric.md](references/scoring-rubric.md)307308---309310## Official Resources311312- [Agent Script Documentation](https://developer.salesforce.com/docs/ai/agentforce/guide/agent-script.html)313- [Agent Script Recipes](https://github.com/trailheadapps/agent-script-recipes)314- [Agentforce DX Guide](https://developer.salesforce.com/docs/ai/agentforce/guide/agent-dx.html)315- [references/official-sources.md](references/official-sources.md)