
This is the code-first path for building deterministic Agentforce agents using Agent Script DSL and .agent files. It's for when you need repeatable control over routing, slot filling, and state transitions instead of letting the planner improvise. The skill walks you through finite-state topic flows, CLI workflows (generate, validate, preview, publish), and the gotchas that break compilation: no else-if, no nested ifs, booleans are True/False, and tabs will ruin your day. It includes an activation checklist, Service vs Employee Agent setup rules, and validator error IDs. Use this when you're authoring bundles or need compliance-grade guardrails. Delegate to sf-ai-agentforce if you're working in Builder metadata or building test coverage loops.
$ npx -y skills add jaganpro/sf-skills --skill sf-ai-agentscript --agent claude-codeInstalls into .claude/skills of the current project.
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
Use sf-ai-agentscript when the work involves:
.agent filessf agent generate authoring-bundle, sf agent validate authoring-bundle, sf agent preview, sf agent publish authoring-bundle, sf agent activate)Delegate elsewhere when the user is:
GenAiFunction, GenAiPlugin, GenAiPromptTemplate, Models API, custom Lightning types) → sf-ai-agentforceIf the user is in Builder Script / Canvas view but the outcome is a .agent authoring bundle, keep the work in sf-ai-agentscript.
Ask for or infer:
Before you author or fix any .agent file, verify these first:
start_agent blockTrue / Falseelse if and no nested ifactions: block@inputs in set expressionslinked variables have no defaultslinked variables do not use object / list typesagent_type@actions. prefixes consistentlyrun @actions.X only when X is a topic-level action definition with target:@system_variables.user_input contains/startswith/endswith for intent routingis_displayable: False + is_used_by_planner: True@outputs.X is scalar — inspect the output schema before branching or assignmentFor the expanded version, use references/activation-checklist.md.
| 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
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.
| 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:.
else ififif bodiesactions:inputs: / outputs: blocksdescription and labelCanonical rule set: references/syntax-reference.md and references/validator-rule-catalog.md
.agentconfig, system, start_agent, and topics firstinputs: and outputs:available when for deterministic tool visibilityinstructions: ->.agent authoring and edits in source control.sf agent generate authoring-bundle --no-spec only when the user wants local bundle scaffolding.sf agent generate agent-spec as optional ideation / topic bootstrap, not the default workflow.sf agent create or sf agent generate template.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.
Use the preview loop before publish:
start / send / end subcommands, not bare sf agent preview--authoring-bundle, always choose a mode explicitly: --simulate-actions or --use-live-actionsFull loop: references/preview-test-loop.md
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.
These execute as code, not suggestions:
available when guardsset / transition torun @actions.X only when X is a topic-level action definition with target:Important distinction:
set, transition to, and run @actions.X for a target-backed topic actionreasoning.actions: utilities / delegations such as @utils.setVariables, @utils.transition, and {!@actions.X} instruction referencesIf you need deterministic behavior for something that is currently modeled as a reasoning-level utility, either:
set / transition to, orrun that actionSee references/instruction-resolution.md and references/architecture-patterns.md.
| 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 |
| 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 |
| 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
Sponsors