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 typeRequiredForbidden / cautionAgentforceServiceAgentValid default_agent_user, correct permissions, target-org checks, prefer sf org create agent-userPublishing without a real Einstein Agent UserAgentforceEmployeeAgentExplicit agent_typeSupplying default_agent_user
Full details: references/agent-user-setup.md
Use this order for consistency in this skill's examples and reviews:
yaml
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.
FieldRuledeveloper_nameMust match folder / bundle namedescriptionPublic docs/examples should use this config fieldagent_typeSet explicitly every timedefault_agent_userService 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
.agent#config, 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:
bash
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
bash
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.
TaskDelegate toWhyBuild flow:// targetssf-flowFlow creation / validationBuild Apex action targetssf-apex@InvocableMethod and business logicTest topic routing / actionssf-ai-agentforce-testingFormal test specs and fix loopsDeploy / publishsf-deployDeployment orchestration
SymptomLikely causeRead nextInternal Error during publishinvalid Service Agent user or missing action I/Oreferences/agent-user-setup.md, references/actions-reference.mdinvalid input/output parameters on prompt template actionTarget template is in Draft status — activate it firstreferences/action-prompt-templates.mdParser rejects conditionalselse if, nested if, empty if bodyreferences/syntax-reference.mdAction target issuesmissing Flow / Apex target, inactive Flow, bad schemasreferences/actions-reference.mdPrompt template runs but user sees blank responseprompt output marked is_displayable: Truereferences/production-gotchas.md, references/action-prompt-templates.mdPrompt action runs but planner behaves like output is missingoutput hidden from direct display but not planner-visiblereferences/production-gotchas.md, references/actions-reference.mdACTION_NOT_IN_SCOPE on run @actions.X``run points at a utility / delegation / unresolved action instead of a topic-level target-backed definitionreferences/syntax-reference.md, references/instruction-resolution.mdDeterministic cancel / revise / URL checks behave inconsistentlyraw @system_variables.user_input matching or string-method guards are being used as control-flow-critical validationreferences/syntax-reference.md, references/production-gotchas.md@outputs.X comparisons or assignments behave unexpectedlythe action output is structured/wrapped, not a plain scalarreferences/actions-reference.md, references/syntax-reference.mdPreview and runtime disagreelinked vars / context / known platform issuesreferences/known-issues.mdValidate passes but publish failsorg-specific user / permission / retrieve-back issuereferences/production-gotchas.md, references/cli-guide.md
ScoreMeaning90+Deploy with confidence75–89Good, review warnings60–74Needs focused revision< 60Block publish
Full rubric: references/scoring-rubric.md