Agent Script Skill
What This Skill Is For
Agent Script is Salesforce's scripting language for authoring next-generation AI agents on the Atlas Reasoning Engine. Introduced in 2025 with zero training data in any AI model. Everything needed to write, modify, diagnose, or deploy Agent Script agents is in this skill's reference files.
⚠️CRITICAL: Agent Script is NOT AppleScript, JavaScript, Python, or any other
language. Do NOT confuse Agent Script syntax or semantics with any other
language you have been trained on.
Agent Script agents are defined by AiAuthoringBundle metadata — a directory with a .agent file containing Agent Script source that describes actions, instructions, subagents, flow control, and configuration; and a bundle-meta.xml file containing bundle metadata. Agents process utterances by routing through subagents, each with instructions and actions backed by Apex, Flows, Prompt Templates, and other types of backing logic.
This skill covers the full Agent Script lifecycle: designing agents,
writing Agent Script code, validating and debugging, deploying and
publishing, and testing.
How to Use This Skill
This file maps user intent to task domains and relevant reference files in references/. Detailed knowledge includes syntax rules, design patterns, CLI commands, debugging workflows, and more.
Identify user intent from task descriptions. ALWAYS read indicated reference files BEFORE starting work.
Rules That Always Apply
Always --json. ALWAYS include --json on EVERY sf CLI command. Do NOT pipe CLI output through jq or 2>/dev/null. Read the full JSON response directly — LLMs parse JSON natively.
Verify target org. Before any org interaction, run sf config get target-org --json to confirm a target org is set. If none configured, ask the user to set one with sf config set target-org <alias>.
Diagnose before you fix. When validating/debugging agent behavior,
ALWAYS --use-live-actions to preview authoring bundles. Send utterances
then read resulting session traces to ground your understanding of the
agent's behavior. Trace files reveal subagent selection, action I/O, and
LLM reasoning. DO NOT modify .agent files or backing logic without
this grounding. See Validation & Debugging
for trace file locations and diagnostic patterns.
Spec approval is a hard gate. Never proceed past Agent Spec
creation without explicit user approval.
Task Domains
Every task domain below has Required Steps. Follow verbatim, in order. Do not substitute your own plan or skip steps.
Create an Agent
User wants to build new agent from scratch. ALWAYS use Agent Script. Work with User to understand the agent's purpose, subagents, and actions using plain language without Salesforce-specific terminology.
Required Steps
Read CLI for Agents for exact command syntax.
- Design — Read Design & Agent Spec to draft an Agent Spec. Always ask if you should scan for existing backing logic. Unless instructed otherwise, scan by reading
sfdx-project.json to identify package directories, then search each for @InvocableMethod in classes/, AutoLaunchedFlow in flows/, and template metadata in promptTemplates/. Mark matches EXISTS; unmatched actions NEEDS STUB. Also scan objects/ for .object-meta.xml to discover custom objects — related objects often contain data the agent should expose even when not mentioned in the prompt. Always save Agent Spec as file.
- STOP for user approval of Agent Spec. Present to user. Ask for approval or feedback. Do not proceed without approval. Once approved, proceed without stopping unless a step fails.
- Validate environment prerequisites — Read Design & Agent Spec, Section 3 (Environment Prerequisites). Based on agent type from design, validate org environment:
- Employee agent: Confirm config block does NOT include
default_agent_user, connection messaging:, or MessagingSession linked variables. Remove if present. See Examples for a complete employee agent example.
- Service agent: Query org for Einstein Agent User. If one exists, confirm username with user. If none, guide user through creation. See CLI for Agents, Section 12 for creation steps and Agent User Setup for required permissions.
Do not proceed to code generation until environment is validated.
- Generate authoring bundle —
sf agent generate authoring-bundle --json --no-spec --name "<Label>" --api-name <Developer_Name>
- Write code — Read Core Language for syntax, block structure, and anti-patterns. Edit generated
.agent file using reference files and templates. Do not create .agent or bundle-meta.xml files manually.
- Validate compilation —
sf agent validate authoring-bundle --json --api-name <Developer_Name>
If validation fails, read Validation & Debugging to diagnose and fix, then re-validate. ALWAYS fix syntax and structural errors before generating backing logic.
- Generate backing logic — For each action marked NEEDS STUB:
sf template generate apex class --name <ClassName> --output-dir <PACKAGE_DIR>/main/default/classes
Replace class body with invocable pattern from Design & Agent Spec. ALWAYS deploy:
sf project deploy start --json --metadata ApexClass:<ClassName>
ALWAYS fix deploy errors BEFORE generating and deploying next stub.
- Validate behavior — Read Validation & Debugging for preview workflow and session trace analysis.
sf agent preview start --json --use-live-actions --authoring-bundle <Developer_Name>
If actions query data, ground test utterances with:
sf data query --json -q "SELECT <Relevant_Fields> FROM <SObject> LIMIT 100"
Send test utterances with:
sf agent preview send --json --authoring-bundle <Developer_Name> --session-id <ID> -u "<message>"
Confirm subagent routing, gating, and action invocations match Agent Spec. If behavior diverges, switch to Diagnose Behavioral Issues workflow. Return AFTER correcting issues.
CHECKPOINT — Do NOT proceed to Publish unless ALL are true:
validate authoring-bundle passes with zero errors
- Live preview (
--use-live-actions) tested with representative utterances per subagent
- Traces confirm correct subagent routing and action invocation
- User explicitly approves deployment
- Publish — Publish validates metadata structure, not agent behavior. Every publish creates permanent version number.
sf agent publish authoring-bundle --json --api-name <Developer_Name>
If publish fails, follow troubleshooting checklist in Metadata & Lifecycle, Section 5 before retrying.
- Activate — Makes new version available to users.
sf agent activate --json --api-name <Developer_Name>
- Verify published agent — Preview user-facing behavior AFTER activation with
sf agent preview start --json --api-name <Developer_Name>
Use --api-name, not --authoring-bundle.
- Configure end-user access — ONLY for employee agents. Read Agent Access Guide to configure perms and assign access.
Reference Files
- CLI for Agents — exact
command syntax for generate, validate, deploy, publish, activate;
Section 12 for Einstein Agent User creation
- Core Language — execution
model, syntax, block structure, anti-patterns
- Design & Agent Spec —
subagent graph design, flow control patterns, Agent Spec production,
backing logic analysis; Section 3 for environment prerequisites
- Subagent Map Diagrams —
Mermaid diagram conventions for visualizing the agent's subagent graph
- Agent User Setup & Permissions —
permission set assignment, object permissions, cross-subagent validation
- Metadata & Lifecycle —
directory structure, bundle metadata; publish troubleshooting
- Validation & Debugging —
validate the agent compiles, preview to confirm behavior
- Agent Access Guide — end-user
access permissions, visibility troubleshooting
- Known Issues — only load when errors
persist after code fixes
- Architecture Patterns — hub-and-spoke, verification gate, post-action loop
- Complex Data Types — type mapping decision tree
- Safety Review — 7-category safety review
- Discover Reference — target discovery CLI
- Scaffold Reference — stub generation CLI
- Deploy Reference — deployment lifecycle, error recovery
Comprehend an Existing Agent
User wants to understand Agent Script agent they didn't write or need to revisit. May point to AiAuthoringBundle directory or ask "what does this agent do?" or "I need to fix this agent but I don't understand how it works.".
Required Steps
- Locate agent — Read
sfdx-project.json to identify package directories. Find AiAuthoringBundle directory within them. Read .agent file and bundle-meta.xml.
- Read code — Read Core Language for syntax and execution model BEFORE parsing
.agent file.
- Map backing logic — For each action with
target, locate backing implementation (Apex class, Flow, Prompt Template) in project. Note input/output contracts.
- Reverse-engineer Agent Spec — Read Design & Agent Spec for Agent Spec structure. Produce Agent Spec from code and save as file.
- Produce Subagent Map diagram — Read Subagent Map Diagrams for Mermaid conventions. Generate flowchart of subagent graph showing transitions, gates, and action associations.
- Annotate source — Ask if user wants Agent Script source annotated with explanations. If requested, add inline comments to
.agent file explaining flow control decisions, gating rationale, and subagent relationships.
- Present to user — Share Agent Spec, Subagent Map, and annotated source if produced. Check Anti-Patterns section in Core Language reference and flag any matches found in code.
Reference Files
- Core Language — syntax,
execution model, anti-patterns
- Design & Agent Spec —
Agent Spec structure, flow control pattern recognition
- Subagent Map Diagrams —
Mermaid conventions for subagent graph visualization
- Metadata & Lifecycle —
directory conventions, bundle metadata
- Known Issues — only load when code
contains unexplained workaround patterns
Modify an Existing Agent
User wants to add, remove, or change subagents, actions, instructions, or flow control on existing agent. May describe change in plain language ("add a billing subagent") or reference specific Agent Script constructs.
Required Steps
Read CLI for Agents for exact command syntax.
- Comprehend — If no Agent Spec exists, reverse-engineer first by following "Comprehend an Existing Agent" workflow above.
- Update Agent Spec — Read Design & Agent Spec for flow control patterns and backing logic analysis. Modify Agent Spec to reflect intended changes. For new actions, always ask if you should scan for existing backing logic. Unless instructed otherwise, scan by reading
sfdx-project.json to identify package directories, then search each for @InvocableMethod in classes/, AutoLaunchedFlow in flows/, and template metadata in promptTemplates/. Mark matches EXISTS; unmatched actions NEEDS STUB. Always save updated Agent Spec as file.
- STOP for user approval of updated Agent Spec. Present to user. Ask for approval or feedback. Do not proceed without approval. Once approved, proceed without stopping unless a step fails.
- Edit code — Read Core Language for syntax and anti-patterns. Edit
.agent file to implement approved changes.
- Validate compilation —
sf agent validate authoring-bundle --json --api-name <Developer_Name>
If validation fails, read Validation & Debugging to diagnose and fix, then re-validate.
- Generate new backing logic — For each new action marked NEEDS STUB:
sf template generate apex class --name <ClassName> --output-dir <PACKAGE_DIR>/main/default/classes
Replace class body with invocable pattern from Design & Agent Spec. ALWAYS deploy:
sf project deploy start --json --metadata ApexClass:<ClassName>
ALWAYS fix deploy errors BEFORE generating and deploying next stub. Skip if no new actions added.
- Validate behavior — Read Validation & Debugging for preview workflow and session trace analysis.
sf agent preview start --json --use-live-actions --authoring-bundle <Developer_Name>
If actions query data, ground test utterances with:
sf data query --json -q "SELECT <Relevant_Fields> FROM <SObject> LIMIT 100"
Send test utterances with:
sf agent preview send --json --authoring-bundle <Developer_Name> --session-id <ID> -u "<message>"
Test changed paths first, then adjacent paths to catch regressions in existing behavior.
CHECKPOINT — Do NOT proceed to Publish unless ALL are true:
validate authoring-bundle passes with zero errors
- Live preview (
--use-live-actions) tested with representative utterances per subagent
- Traces confirm correct subagent routing and action invocation
- User explicitly approves deployment
- Publish — Publish validates metadata structure, not agent behavior. Every publish creates permanent version number.
sf agent publish authoring-bundle --json --api-name <Developer_Name>
If publish fails, follow troubleshooting checklist in Metadata & Lifecycle, Section 5 before retrying.
- Activate — Makes new version available to users.
sf agent activate --json --api-name <Developer_Name>
- Verify published agent — Preview user-facing behavior AFTER activation with
sf agent preview start --json --api-name <Developer_Name>
Use --api-name, not --authoring-bundle.
Reference Files
- CLI for Agents — exact
command syntax for validate, deploy, preview, publish, activate
- Core Language — syntax,
anti-patterns
- Design & Agent Spec —
Agent Spec updates, backing logic analysis
- Validation & Debugging —
compilation diagnosis, preview workflow, session trace analysis
- Known Issues — only load when errors
persist after code fixes
Diagnose Compilation Errors
User has Agent Script that won't compile. Errors surface from sf agent validate or sf agent preview start, or User describes symptoms like "I'm getting a validation error."
Required Steps
Read CLI for Agents for exact command syntax.
- Reproduce error — Run
sf agent validate authoring-bundle --json --api-name <Developer_Name>
to capture basic compile errors. If no errors, run
sf agent preview start --json --use-live-actions --authoring-bundle <Developer_Name>
to capture complex compile errors. If user provides specific error output, ALWAYS reproduce to confirm.
- Classify error — Read Validation & Debugging for error taxonomy. Map each error message to root cause category.
- Locate fault — Read Core Language to understand correct syntax. Find specific line(s) in
.agent file that cause each error.
- Fix code — Apply targeted fixes. Check Anti-Patterns section in Core Language reference to ensure you're not introducing known bad pattern.
- Re-validate — Run
sf agent validate authoring-bundle --json --api-name <Developer_Name>
then run
sf agent preview start --json --use-live-actions --authoring-bundle <Developer_Name>
Repeat steps 2–5 if errors persist.
- Explain fix — Tell user what was wrong and what you changed. Explain root cause in terms of Core Language agent execution model.
Reference Files
- Core Language — syntax,
block structure, anti-patterns
- Validation & Debugging —
error taxonomy, error-to-root-cause mapping
- Known Issues — only load when error
doesn't match user code; may be a platform bug
- Production Gotchas — only load
when error involves reserved keywords or lifecycle hook syntax
Diagnose Behavioral Issues
Agent compiles, preview can start and --use-live-actions, but agent does not behave as expected. User describes symptoms like "the agent keeps going to the wrong subagent" or "the action isn't being called." Fundamentally different from validate or preview start errors — code is valid but behavior is wrong.
Required Steps
Read CLI for Agents for exact command syntax.
- Establish baseline — Read Agent Spec. If no Agent Spec exists, follow Comprehend an Existing Agent workflow to reverse-engineer one, then continue.
- Form hypotheses — Read Core Language for execution model. Based on user's description, list candidate root causes. Think through: subagent routing, gating conditions, action availability, instruction clarity, variable state, and transition timing.
- Reproduce in preview — Read Validation & Debugging for preview workflow and session trace analysis. Start preview session:
sf agent preview start --json --use-live-actions --authoring-bundle <Developer_Name>
then send test messages covering EACH subagent with sf agent preview send. One message is not enough — confirm behavior per subagent before proceeding.
- Analyze session traces — Examine trace output to confirm subagent selection, action availability/execution, LLM reasoning, and where behavior diverges from Agent Spec. Do NOT skip this step — preview output alone is insufficient for diagnosis.
- Identify root cause — Match trace evidence to hypotheses. Consult Core Language reference and Gating Patterns in Design & Agent Spec reference to confirm absence of anti-patterns.
- Fix code — Apply targeted fix. If fix involves flow control changes, update Agent Spec to match.
- Re-validate and re-preview — Repeat steps 3–6 until behavior matches Agent Spec or you confirm a platform limitation. Run
validate authoring-bundle, then preview start --use-live-actions to verify fix using same utterances. Then test adjacent paths that might be affected by your changes.
- Explain fix — Tell user what was wrong and what you changed. Explain root cause in terms of Core Language agent execution model.
Reference Files
- Core Language — execution
model, anti-patterns
- Design & Agent Spec —
Agent Spec as behavioral baseline, gating patterns
- Validation & Debugging —
preview workflow, session trace analysis
- Known Issues — only load when behavior
is wrong but code logic is correct
Deploy, Publish, and Activate
User wants to take working agent from local development to running state in Salesforce org. Involves deploying AiAuthoringBundle and its dependencies, publishing to commit version, then activating to make it live.
Required Steps
Read CLI for Agents for exact command syntax.
- Validate compilation —
sf agent validate authoring-bundle --json --api-name <Developer_Name>
Do not proceed if validation fails.
- Deploy bundle and dependencies — Read Metadata & Lifecycle for dependency management and deploy commands. Deploy
AiAuthoringBundle and all backing logic (Apex classes, Flows, Prompt Templates) and dependencies to org.
- Live preview — Read Validation & Debugging for preview workflow and session trace analysis.
sf agent preview start --json --use-live-actions --authoring-bundle <Developer_Name>
then send test utterances with:
sf agent preview send --json --authoring-bundle <Developer_Name> --session-id <ID> -u "<message>"
Test key conversation paths to validate agent behavior when backed by live actions.
CHECKPOINT — Do NOT proceed to Publish unless ALL are true:
validate authoring-bundle passes with zero errors
- Live preview (
--use-live-actions) tested with representative utterances per subagent
- Traces confirm correct subagent routing and action invocation
- User explicitly approves deployment
- Publish — Publish validates metadata structure, not agent behavior. DO NOT publish as part of a dev/test inner loop. ONLY publish as the FINAL step prior to activating the agent and surfacing it to end users.
sf agent publish authoring-bundle --json --api-name <Developer_Name>
If publish fails, follow Troubleshooting Publish Failures in Metadata & Lifecycle before retrying.
- Activate — Makes new version available to users.
sf agent activate --json --api-name <Developer_Name>
- Verify published agent — Preview user-facing behavior AFTER activation with
sf agent preview start --json --api-name <Developer_Name>
Use --api-name, not --authoring-bundle.
- Configure end-user access — ONLY for employee agents. Read Agent Access Guide to configure perms and assign access.
Reference Files
- CLI for Agents — exact
command syntax for deploy, publish, activate, deactivate
- Validation & Debugging —
compilation validation, preview workflow
- Metadata & Lifecycle —
dependency management, deploy commands; publish troubleshooting
- Agent Access Guide — end-user
access permissions, visibility troubleshooting
- Known Issues — only load when deploy
hangs, publish fails, or activate fails unexpectedly
Diagnose Production Issues
User's agent is published and active but experiencing issues not caught during preview. Includes credit overconsumption, token or size limit failures, loop guardrail interruptions, reserved keyword runtime errors, VS Code sync failures, or unexpected behavioral differences between preview and production.
Required Steps
Read CLI for Agents for exact command syntax.
- Classify issue — Determine whether this is billing/cost concern, runtime limit, naming conflict, tooling issue, or behavioral difference between preview and production.
- Check known production gotchas — Read Production Gotchas for credit consumption, token limits, loop guardrails, reserved keywords, lifecycle hooks, and VS Code workarounds.
- Compare preview vs production behavior — If issue is behavioral, preview published agent with
sf agent preview start --json --api-name <Developer_Name>
(not --authoring-bundle). Compare against live-actions authoring bundle preview --authoring-bundle <Developer_Name> --use-live-actions to isolate preview-vs-production differences.
- Check known issues — Read Known Issues for platform bugs that may explain production-only failures.
- Fix and republish — Apply fixes, validate, re-preview, publish, activate, verify. Follow Deploy, Publish, and Activate steps.
- Explain diagnosis — Tell user what was happening and what you changed. Explain root cause.
Reference Files
- Production Gotchas — credit
consumption, token limits, loop guardrails, reserved keywords,
lifecycle hooks, VS Code workarounds
- CLI for Agents — command
syntax for preview, publish, activate
- Validation & Debugging —
preview workflow, session trace analysis
- Known Issues — only load when issue may
be a platform bug
Delete or Rename an Agent
User wants to remove agent or change its name. Maintenance tasks complicated by AiAuthoringBundle versioning and published version dependencies.
Required Steps
Read CLI for Agents for exact command syntax.
- Understand current state — Read Metadata & Lifecycle for versioning, delete mechanics, and rename mechanics. Identify whether agent has been published, how many versions exist, and whether it's currently active.
- Deactivate if active —
sf agent deactivate --json --api-name <Developer_Name>
Active agent cannot be deleted or renamed.
- Execute operation — For delete: follow delete mechanics in Metadata & Lifecycle reference. For rename: follow rename mechanics in same reference.
- Clean up orphans — Check for and remove orphaned metadata: Bot, BotVersion, GenAiPlannerBundle, GenAiPlugin, GenAiFunction. Metadata & Lifecycle reference details what to look for.
- Validate — Confirm operation completed cleanly. For rename, validate new bundle compiles and preview to confirm behavior.
Reference Files
- CLI for Agents — exact
command syntax for delete, deactivate, retrieve
- Validation & Debugging —
compilation validation, preview workflow
- Metadata & Lifecycle —
delete mechanics, rename mechanics, orphan cleanup
Test an Agent
User wants to create automated tests for Agent Script agent. Involves writing AiEvaluationDefinition test specs in YAML format that define test scenarios, expected behaviors, and quality metrics.
Required Steps
Read CLI for Agents for exact command syntax.
- Establish coverage baseline — Read Agent Spec. If no Agent Spec exists, reverse-engineer first by following Comprehend steps. Map every subagent, action, and flow control path to identify what needs test coverage.
- Design test scenarios — For test design methodology, expectations, metrics, test spec YAML format, and templates, use agentforce-test skill. That skill owns all testing content. For each coverage target, write one or more test scenarios: user utterance, expected subagent routing, expected action invocations, and expected agent response. Include both happy paths and edge cases.
- Write test spec YAML — Use template and reference files from agentforce-test skill. Save to
specs/<Agent_API_Name>-testSpec.yaml in SFDX project.
- Create test metadata — Generate
AiEvaluationDefinition from test spec using CLI.
- Deploy test — Deploy
AiEvaluationDefinition to org.
- Run tests — Execute test run using CLI. Capture results.
- Analyze results — Compare actual outcomes against expectations. For failures, identify whether issue is in agent code, backing logic, or test spec itself.
- Iterate — Fix agent code or test spec as needed, redeploy, and re-run until coverage targets are met.
Reference Files
- CLI for Agents — exact
command syntax for test create, test run, test results
- Core Language — agent
structure for designing meaningful tests
- Design & Agent Spec —
Agent Spec as test coverage baseline
- agentforce-test skill — test spec YAML format, expectations,
metrics, test design methodology, and test spec template
The Agent Spec
Agent Spec is the central artifact this skill produces and consumes. A structured design document representing agent's purpose, subagent graph, actions with backing logic, variables, gating logic, and behavioral intent.
Agent Specs evolve with the agent. Sparse during agent creation (purpose, topics, directional notes). Fleshed out during agent build (flowchart, backing logic mapped, gating documented). Reverse-engineered when comprehending existing agents. Critical for advanced troubleshooting, providing reference to compare expected vs. actual behavior. During testing, test coverage maps against it.
Always produce or update Agent Spec as first step of any operation that changes or analyzes agent. It is consistent grounding to work from, and a durable artifact a developer can review.
Read Design & Agent Spec for Agent Spec structure and production methodology.
Assets
The assets/ directory contains templates and examples. Read when you need a starting point or a concrete reference for artifacts and source files.
assets/agent-spec-template.md — Agent Spec template with all sections and placeholder content. Copy to <AgentName>-AgentSpec.md in project directory, then fill in during design. Save Agent Spec as file — significant design artifact that benefits from proper rendering, especially Mermaid Subagent Map diagram.
assets/local-info-agent-annotated.agent — Complete annotated example based on Local Info Agent, showing all major Agent Script constructs in context with inline comments explaining why each construct is used. Read when you need concrete reference for how concepts compose into working agent, or as fallback when focused examples in reference files aren't sufficient.
assets/template-single-subagent.agent — Minimal agent with one subagent. Copy and modify for simple agents.
assets/template-multi-subagent.agent — Minimal agent with multiple subagents and transitions. Copy and modify for complex agents.
assets/invocable-apex-template.cls — Reference for invocable Apex
classes. Copy and modify when complex Apex backing logic is desired.
Important Constraints
Use only Salesforce CLI and Salesforce org. Do not reference or depend on other skills, MCP servers, or external tooling. All commands use sf (Salesforce CLI).
Only certain backing logic types are valid for actions. For example, only invocable Apex (not arbitrary Apex classes) can back action. Similar constraints may apply to Flows and Prompt Templates. When wiring actions to backing logic, consult Design & Agent Spec reference file for valid types and stubbing methodology.
sf agent generate test-spec is not for agentic use. It is interactive, REPL-style command designed for humans. When creating test specs, start from boilerplate template in assets instead.
Common Issues Quick Reference
Internal Error, try again later during publish:
Invalid or missing default_agent_user. Re-run query from Design & Agent Spec, Section 3. Do not invent username.
Unable to access Salesforce Agent APIs... during preview:
default_agent_user lacks permissions. See Agent User Setup & Permissions. Do NOT publish as fix — --use-live-actions does not require published agent.
Permission error referencing different username than configured:
Same fix as above — error references org's default running user, but root cause is Einstein Agent User permissions.
Agent fails with permission error even though current subagent's actions work:
Planner validates ALL actions across ALL subagents at startup. One missing permission fails entire agent.
Apex action returns empty results in live preview but works in simulated:
WITH USER_MODE + missing object permissions = silent failure (0 rows, no error). See Agent User Setup & Permissions, Section 6.2.
Syntax Quick Reference
- Block order:
system: → config: → variables: → connection: → knowledge: → language: → start_agent agent_router: → subagent: blocks
- Indentation: 4 spaces per indent level. Never use tabs. Mixing spaces and tabs breaks the parser.
- Booleans:
True/False (capitalized)
- Strings: always double-quoted
- Numeric action I/O: bare
number works for variables but fails at publish in action I/O. Use object + complex_data_type_name for numeric action parameters. See Complex Data Types for the full decision tree.
after_reasoning: has NO instructions: wrapper
- No
else if — use compound if x and y: or sequential flat ifs
- Reserved
@InvocableVariable names: model, description, label — cannot be used as Apex parameter names
@inputs and @outputs are ephemeral: @inputs only in with; @outputs only in set/if immediately after the action. @inputs in set = silent failure.
See Complex Data Types for the full Lightning type mapping decision tree. See Instruction Resolution for the 3-phase runtime model.
Architecture Patterns
Three primary FSM patterns. Full details with code in Architecture Patterns.
- Hub-and-Spoke (most common):
start_agent routes to specialized subagents. Each subagent has "back to hub" transition. Do NOT create a separate routing subagent.
- Verification Gate: Identity verification before protected subagents.
available when guards on protected transitions.
- Post-Action Loop: Post-action checks at TOP of
instructions: -> trigger on re-resolution after action completes.
Scoring Rubric
Score every generated agent on 100 points across 7 categories: Structure (15), Safety (15), Deterministic Logic (20), Instruction Resolution (20), FSM Architecture (10), Action Configuration (10), Deployment Readiness (10).
See Scoring Rubric for the complete rubric.
Review Mode
When user provides an existing .agent file (e.g., review path/to/file.agent):
- Read the file
- Score against the 100-point rubric
- List every issue grouped by category
- Provide corrected code snippets
- Offer to apply fixes
Safety Review
7-category LLM-driven safety review for .agent files. Integrated into Phase 0 of authoring and deployment. Categories: Identity & Transparency, User Safety, Data Handling, Content Safety, Fairness, Deception, Scope & Boundaries.
See Safety Review for the complete framework, severity levels, false positive guidance, and adversarial test prompts.
Discover & Scaffold
Validate action targets exist in org and generate stubs for missing ones.
See Discover Reference and Scaffold Reference.
CRITICAL: Stubs must return realistic data, not 'TODO'. Placeholder responses cause SMALL_TALK grounding because the LLM falls back to training data.
Deploy Lifecycle
Validate → deploy metadata → publish bundle → activate. See Deploy Reference for phases, error recovery, CI/CD, and rollback.
Template Assets
Ready-to-use .agent templates in assets/agents/ (hello-world, simple-qa, multi-subagent, production-faq, order-service, verification-gate). See also assets/patterns/ for 11+ reusable design patterns and Examples for inline walkthroughs.
Additional References
| Topic |
File |
| Architecture patterns |
architecture-patterns.md |
| Type mapping decision tree |
complex-data-types.md |
| Feature validity by context |
feature-validity.md |
| Instruction resolution model |
instruction-resolution.md |
| Complete agent examples |
examples.md |
1---2name: agentforce-generate3description: Build, modify, debug, and deploy agents with Agentforce Agent Script. TRIGGER when: user creates, modifies, or asks about .agent files or aiAuthoringBundle metadata; changes agent behavior, responses, or conversation logic; designs agent actions, tools, subagents, or flow control; writes or reviews an Agent Spec; previews, debugs, deploys, publishes, or tests agents; uses Agent Script CLI commands (sf agent generate/preview/publish/test). DO NOT TRIGGER when: Apex development, Flow building, Prompt Template authoring, Experience Cloud configuration, or general Salesforce CLI tasks unrelated to Agent Script.4---56# Agent Script Skill78## What This Skill Is For910Agent Script is Salesforce's scripting language for authoring next-generation AI agents on the Atlas Reasoning Engine. Introduced in 2025 with zero training data in any AI model. Everything needed to write, modify, diagnose, or deploy Agent Script agents is in this skill's reference files.1112**⚠️CRITICAL:** Agent Script is NOT AppleScript, JavaScript, Python, or any other13language. Do NOT confuse Agent Script syntax or semantics with any other14language you have been trained on.1516Agent Script agents are defined by `AiAuthoringBundle` metadata — a directory with a `.agent` file containing Agent Script source that describes actions, instructions, subagents, flow control, and configuration; and a `bundle-meta.xml` file containing bundle metadata. Agents process utterances by routing through subagents, each with instructions and actions backed by Apex, Flows, Prompt Templates, and other types of backing logic.1718This skill covers the full Agent Script lifecycle: designing agents,19writing Agent Script code, validating and debugging, deploying and20publishing, and testing.2122## How to Use This Skill2324This file maps user intent to task domains and relevant reference files in `references/`. Detailed knowledge includes syntax rules, design patterns, CLI commands, debugging workflows, and more.2526Identify user intent from task descriptions. ALWAYS read indicated reference files BEFORE starting work.2728## Rules That Always Apply29301. **Always `--json`.** ALWAYS include `--json` on EVERY `sf` CLI command. Do NOT pipe CLI output through `jq` or `2>/dev/null`. Read the full JSON response directly — LLMs parse JSON natively.31322. **Verify target org.** Before any org interaction, run `sf config get target-org --json` to confirm a target org is set. If none configured, ask the user to set one with `sf config set target-org <alias>`.33343. **Diagnose before you fix.** When validating/debugging agent behavior,35 ALWAYS `--use-live-actions` to preview authoring bundles. Send utterances36 then read resulting session traces to ground your understanding of the37 agent's behavior. Trace files reveal subagent selection, action I/O, and38 LLM reasoning. DO NOT modify `.agent` files or backing logic without39 this grounding. See [Validation & Debugging](references/agent-validation-and-debugging.md)40 for trace file locations and diagnostic patterns.41424. **Spec approval is a hard gate.** Never proceed past Agent Spec43 creation without explicit user approval.4445## Task Domains4647Every task domain below has **Required Steps**. Follow verbatim, in order. Do not substitute your own plan or skip steps.4849### Create an Agent5051User wants to build new agent from scratch. ALWAYS use Agent Script. Work with User to understand the agent's purpose, subagents, and actions using plain language without Salesforce-specific terminology.5253#### Required Steps5455Read [CLI for Agents](references/salesforce-cli-for-agents.md) for exact command syntax.56571. **Design** — Read [Design & Agent Spec](references/agent-design-and-spec-creation.md) to draft an Agent Spec. Always ask if you should scan for existing backing logic. Unless instructed otherwise, scan by reading `sfdx-project.json` to identify package directories, then search each for `@InvocableMethod` in `classes/`, `AutoLaunchedFlow` in `flows/`, and template metadata in `promptTemplates/`. Mark matches `EXISTS`; unmatched actions `NEEDS STUB`. Also scan `objects/` for `.object-meta.xml` to discover custom objects — related objects often contain data the agent should expose even when not mentioned in the prompt. **Always save Agent Spec as file.**582. **STOP for user approval of Agent Spec.** Present to user. Ask for approval or feedback. **Do not proceed** without approval. Once approved, proceed without stopping unless a step fails.593. **Validate environment prerequisites** — Read [Design & Agent Spec](references/agent-design-and-spec-creation.md), Section 3 (Environment Prerequisites). Based on agent type from design, validate org environment:60 - **Employee agent**: Confirm config block does NOT include `default_agent_user`, `connection messaging:`, or MessagingSession linked variables. Remove if present. See [Examples](references/examples.md) for a complete employee agent example.61 - **Service agent**: Query org for Einstein Agent User. If one exists, confirm username with user. If none, guide user through creation. See [CLI for Agents](references/salesforce-cli-for-agents.md), Section 12 for creation steps and [Agent User Setup](references/agent-user-setup.md) for required permissions.62 **Do not proceed to code generation until environment is validated.**634. **Generate authoring bundle** —64 `sf agent generate authoring-bundle --json --no-spec --name "<Label>" --api-name <Developer_Name>`655. **Write code** — Read [Core Language](references/agent-script-core-language.md) for syntax, block structure, and anti-patterns. Edit generated `.agent` file using reference files and templates. Do not create `.agent` or `bundle-meta.xml` files manually.666. **Validate compilation** —67 `sf agent validate authoring-bundle --json --api-name <Developer_Name>`68 If validation fails, read [Validation & Debugging](references/agent-validation-and-debugging.md) to diagnose and fix, then re-validate. ALWAYS fix syntax and structural errors before generating backing logic.697. **Generate backing logic** — For each action marked NEEDS STUB:70 `sf template generate apex class --name <ClassName> --output-dir <PACKAGE_DIR>/main/default/classes`71 Replace class body with invocable pattern from [Design & Agent Spec](references/agent-design-and-spec-creation.md). ALWAYS deploy:72 `sf project deploy start --json --metadata ApexClass:<ClassName>`73 ALWAYS fix deploy errors BEFORE generating and deploying next stub.748. **Validate behavior** — Read [Validation & Debugging](references/agent-validation-and-debugging.md) for preview workflow and session trace analysis.75 `sf agent preview start --json --use-live-actions --authoring-bundle <Developer_Name>`76 If actions query data, ground test utterances with:77 `sf data query --json -q "SELECT <Relevant_Fields> FROM <SObject> LIMIT 100"`78 Send test utterances with:79 `sf agent preview send --json --authoring-bundle <Developer_Name> --session-id <ID> -u "<message>"`80 Confirm subagent routing, gating, and action invocations match Agent Spec. If behavior diverges, switch to **Diagnose Behavioral Issues** workflow. Return AFTER correcting issues.81 **CHECKPOINT — Do NOT proceed to Publish unless ALL are true:**82 - `validate authoring-bundle` passes with zero errors83 - Live preview (`--use-live-actions`) tested with representative utterances per subagent84 - Traces confirm correct subagent routing and action invocation85 - User explicitly approves deployment869. **Publish** — Publish validates metadata structure, not agent behavior. Every publish creates permanent version number.87 `sf agent publish authoring-bundle --json --api-name <Developer_Name>`88 If publish fails, follow troubleshooting checklist in [Metadata & Lifecycle](references/agent-metadata-and-lifecycle.md), Section 5 before retrying.8910. **Activate** — Makes new version available to users.90 `sf agent activate --json --api-name <Developer_Name>`9111. **Verify published agent** — Preview user-facing behavior AFTER activation with92 `sf agent preview start --json --api-name <Developer_Name>`93 Use `--api-name`, not `--authoring-bundle`.9412. **Configure end-user access** — ONLY for employee agents. Read [Agent Access Guide](references/agent-access-guide.md) to configure perms and assign access.9596#### Reference Files97981. [CLI for Agents](references/salesforce-cli-for-agents.md) — exact99 command syntax for generate, validate, deploy, publish, activate;100 Section 12 for Einstein Agent User creation1012. [Core Language](references/agent-script-core-language.md) — execution102 model, syntax, block structure, anti-patterns1033. [Design & Agent Spec](references/agent-design-and-spec-creation.md) —104 subagent graph design, flow control patterns, Agent Spec production,105 backing logic analysis; Section 3 for environment prerequisites1064. [Subagent Map Diagrams](references/agent-subagent-map-diagrams.md) —107 Mermaid diagram conventions for visualizing the agent's subagent graph1085. [Agent User Setup & Permissions](references/agent-user-setup.md) —109 permission set assignment, object permissions, cross-subagent validation1106. [Metadata & Lifecycle](references/agent-metadata-and-lifecycle.md) —111 directory structure, bundle metadata; publish troubleshooting1127. [Validation & Debugging](references/agent-validation-and-debugging.md) —113 validate the agent compiles, preview to confirm behavior1148. [Agent Access Guide](references/agent-access-guide.md) — end-user115 access permissions, visibility troubleshooting1169. [Known Issues](references/known-issues.md) — only load when errors117 persist after code fixes11810. [Architecture Patterns](references/architecture-patterns.md) — hub-and-spoke, verification gate, post-action loop11911. [Complex Data Types](references/complex-data-types.md) — type mapping decision tree12012. [Safety Review](references/safety-review-reference.md) — 7-category safety review12113. [Discover Reference](references/discover-reference.md) — target discovery CLI12214. [Scaffold Reference](references/scaffold-reference.md) — stub generation CLI12315. [Deploy Reference](references/deploy-reference.md) — deployment lifecycle, error recovery124125### Comprehend an Existing Agent126127User wants to understand Agent Script agent they didn't write or need to revisit. May point to `AiAuthoringBundle` directory or ask "what does this agent do?" or "I need to fix this agent but I don't understand how it works.".128129#### Required Steps1301311. **Locate agent** — Read `sfdx-project.json` to identify package directories. Find `AiAuthoringBundle` directory within them. Read `.agent` file and `bundle-meta.xml`.1322. **Read code** — Read [Core Language](references/agent-script-core-language.md) for syntax and execution model BEFORE parsing `.agent` file.1333. **Map backing logic** — For each action with `target`, locate backing implementation (Apex class, Flow, Prompt Template) in project. Note input/output contracts.1344. **Reverse-engineer Agent Spec** — Read [Design & Agent Spec](references/agent-design-and-spec-creation.md) for Agent Spec structure. Produce Agent Spec from code and save as file.1355. **Produce Subagent Map diagram** — Read [Subagent Map Diagrams](references/agent-subagent-map-diagrams.md) for Mermaid conventions. Generate flowchart of subagent graph showing transitions, gates, and action associations.1366. **Annotate source** — Ask if user wants Agent Script source annotated with explanations. If requested, add inline comments to `.agent` file explaining flow control decisions, gating rationale, and subagent relationships.1377. **Present to user** — Share Agent Spec, Subagent Map, and annotated source if produced. Check Anti-Patterns section in Core Language reference and flag any matches found in code.138139#### Reference Files1401411. [Core Language](references/agent-script-core-language.md) — syntax,142 execution model, anti-patterns1432. [Design & Agent Spec](references/agent-design-and-spec-creation.md) —144 Agent Spec structure, flow control pattern recognition1453. [Subagent Map Diagrams](references/agent-subagent-map-diagrams.md) —146 Mermaid conventions for subagent graph visualization1474. [Metadata & Lifecycle](references/agent-metadata-and-lifecycle.md) —148 directory conventions, bundle metadata1495. [Known Issues](references/known-issues.md) — only load when code150 contains unexplained workaround patterns151152### Modify an Existing Agent153154User wants to add, remove, or change subagents, actions, instructions, or flow control on existing agent. May describe change in plain language ("add a billing subagent") or reference specific Agent Script constructs.155156#### Required Steps157158Read [CLI for Agents](references/salesforce-cli-for-agents.md) for exact command syntax.1591601. **Comprehend** — If no Agent Spec exists, reverse-engineer first by following "Comprehend an Existing Agent" workflow above.1612. **Update Agent Spec** — Read [Design & Agent Spec](references/agent-design-and-spec-creation.md) for flow control patterns and backing logic analysis. Modify Agent Spec to reflect intended changes. For new actions, always ask if you should scan for existing backing logic. Unless instructed otherwise, scan by reading `sfdx-project.json` to identify package directories, then search each for `@InvocableMethod` in `classes/`, `AutoLaunchedFlow` in `flows/`, and template metadata in `promptTemplates/`. Mark matches `EXISTS`; unmatched actions `NEEDS STUB`. **Always save updated Agent Spec as file.**1623. **STOP for user approval of updated Agent Spec.** Present to user. Ask for approval or feedback. **Do not proceed** without approval. Once approved, proceed without stopping unless a step fails.1634. **Edit code** — Read [Core Language](references/agent-script-core-language.md) for syntax and anti-patterns. Edit `.agent` file to implement approved changes.1645. **Validate compilation** —165 `sf agent validate authoring-bundle --json --api-name <Developer_Name>`166 If validation fails, read [Validation & Debugging](references/agent-validation-and-debugging.md) to diagnose and fix, then re-validate.1676. **Generate new backing logic** — For each new action marked NEEDS STUB:168 `sf template generate apex class --name <ClassName> --output-dir <PACKAGE_DIR>/main/default/classes`169 Replace class body with invocable pattern from [Design & Agent Spec](references/agent-design-and-spec-creation.md). ALWAYS deploy:170 `sf project deploy start --json --metadata ApexClass:<ClassName>`171 ALWAYS fix deploy errors BEFORE generating and deploying next stub. Skip if no new actions added.1727. **Validate behavior** — Read [Validation & Debugging](references/agent-validation-and-debugging.md) for preview workflow and session trace analysis.173 `sf agent preview start --json --use-live-actions --authoring-bundle <Developer_Name>`174 If actions query data, ground test utterances with:175 `sf data query --json -q "SELECT <Relevant_Fields> FROM <SObject> LIMIT 100"`176 Send test utterances with:177 `sf agent preview send --json --authoring-bundle <Developer_Name> --session-id <ID> -u "<message>"`178 Test changed paths first, then adjacent paths to catch regressions in existing behavior.179 **CHECKPOINT — Do NOT proceed to Publish unless ALL are true:**180 - `validate authoring-bundle` passes with zero errors181 - Live preview (`--use-live-actions`) tested with representative utterances per subagent182 - Traces confirm correct subagent routing and action invocation183 - User explicitly approves deployment1848. **Publish** — Publish validates metadata structure, not agent behavior. Every publish creates permanent version number.185 `sf agent publish authoring-bundle --json --api-name <Developer_Name>`186 If publish fails, follow troubleshooting checklist in [Metadata & Lifecycle](references/agent-metadata-and-lifecycle.md), Section 5 before retrying.1879. **Activate** — Makes new version available to users.188 `sf agent activate --json --api-name <Developer_Name>`18910. **Verify published agent** — Preview user-facing behavior AFTER activation with190 `sf agent preview start --json --api-name <Developer_Name>`191 Use `--api-name`, not `--authoring-bundle`.192193#### Reference Files1941951. [CLI for Agents](references/salesforce-cli-for-agents.md) — exact196 command syntax for validate, deploy, preview, publish, activate1972. [Core Language](references/agent-script-core-language.md) — syntax,198 anti-patterns1993. [Design & Agent Spec](references/agent-design-and-spec-creation.md) —200 Agent Spec updates, backing logic analysis2014. [Validation & Debugging](references/agent-validation-and-debugging.md) —202 compilation diagnosis, preview workflow, session trace analysis2035. [Known Issues](references/known-issues.md) — only load when errors204 persist after code fixes205206### Diagnose Compilation Errors207208User has Agent Script that won't compile. Errors surface from `sf agent validate` or `sf agent preview start`, or User describes symptoms like "I'm getting a validation error."209210#### Required Steps211212Read [CLI for Agents](references/salesforce-cli-for-agents.md) for exact command syntax.2132141. **Reproduce error** — Run215 `sf agent validate authoring-bundle --json --api-name <Developer_Name>`216 to capture basic compile errors. If no errors, run217 `sf agent preview start --json --use-live-actions --authoring-bundle <Developer_Name>`218 to capture complex compile errors. If user provides specific error output, ALWAYS reproduce to confirm.2192. **Classify error** — Read [Validation & Debugging](references/agent-validation-and-debugging.md) for error taxonomy. Map each error message to root cause category.2203. **Locate fault** — Read [Core Language](references/agent-script-core-language.md) to understand correct syntax. Find specific line(s) in `.agent` file that cause each error.2214. **Fix code** — Apply targeted fixes. Check Anti-Patterns section in Core Language reference to ensure you're not introducing known bad pattern.2225. **Re-validate** — Run223 `sf agent validate authoring-bundle --json --api-name <Developer_Name>`224 then run225 `sf agent preview start --json --use-live-actions --authoring-bundle <Developer_Name>`226 Repeat steps 2–5 if errors persist.2276. **Explain fix** — Tell user what was wrong and what you changed. Explain root cause in terms of *Core Language* agent execution model.228229#### Reference Files2302311. [Core Language](references/agent-script-core-language.md) — syntax,232 block structure, anti-patterns2332. [Validation & Debugging](references/agent-validation-and-debugging.md) —234 error taxonomy, error-to-root-cause mapping2353. [Known Issues](references/known-issues.md) — only load when error236 doesn't match user code; may be a platform bug2374. [Production Gotchas](references/production-gotchas.md) — only load238 when error involves reserved keywords or lifecycle hook syntax239240### Diagnose Behavioral Issues241242Agent compiles, preview can start and `--use-live-actions`, but agent does not behave as expected. User describes symptoms like "the agent keeps going to the wrong subagent" or "the action isn't being called." Fundamentally different from `validate` or `preview start` errors — code is valid but behavior is wrong.243244#### Required Steps245246Read [CLI for Agents](references/salesforce-cli-for-agents.md) for exact command syntax.2472481. **Establish baseline** — Read Agent Spec. If no Agent Spec exists, follow *Comprehend an Existing Agent* workflow to reverse-engineer one, then continue.2492. **Form hypotheses** — Read [Core Language](references/agent-script-core-language.md) for execution model. Based on user's description, list candidate root causes. Think through: subagent routing, gating conditions, action availability, instruction clarity, variable state, and transition timing.2503. **Reproduce in preview** — Read [Validation & Debugging](references/agent-validation-and-debugging.md) for preview workflow and session trace analysis. Start preview session:251 `sf agent preview start --json --use-live-actions --authoring-bundle <Developer_Name>`252 then send test messages covering EACH subagent with `sf agent preview send`. One message is not enough — confirm behavior per subagent before proceeding.2534. **Analyze session traces** — Examine trace output to confirm subagent selection, action availability/execution, LLM reasoning, and where behavior diverges from Agent Spec. Do NOT skip this step — preview output alone is insufficient for diagnosis.2545. **Identify root cause** — Match trace evidence to hypotheses. Consult *Core Language reference and Gating Patterns* in [Design & Agent Spec](references/agent-design-and-spec-creation.md) reference to confirm absence of anti-patterns.2556. **Fix code** — Apply targeted fix. If fix involves flow control changes, update Agent Spec to match.2567. **Re-validate and re-preview** — Repeat steps 3–6 until behavior matches Agent Spec or you confirm a platform limitation. Run `validate authoring-bundle`, then `preview start --use-live-actions` to verify fix using same utterances. Then test adjacent paths that might be affected by your changes.2578. **Explain fix** — Tell user what was wrong and what you changed. Explain root cause in terms of *Core Language* agent execution model.258259#### Reference Files2602611. [Core Language](references/agent-script-core-language.md) — execution262 model, anti-patterns2632. [Design & Agent Spec](references/agent-design-and-spec-creation.md) —264 Agent Spec as behavioral baseline, gating patterns2653. [Validation & Debugging](references/agent-validation-and-debugging.md) —266 preview workflow, session trace analysis2674. [Known Issues](references/known-issues.md) — only load when behavior268 is wrong but code logic is correct269270### Deploy, Publish, and Activate271272User wants to take working agent from local development to running state in Salesforce org. Involves deploying `AiAuthoringBundle` and its dependencies, publishing to commit version, then activating to make it live.273274#### Required Steps275276Read [CLI for Agents](references/salesforce-cli-for-agents.md) for exact command syntax.2772781. **Validate compilation** —279 `sf agent validate authoring-bundle --json --api-name <Developer_Name>`280 Do not proceed if validation fails.2812. **Deploy bundle and dependencies** — Read [Metadata & Lifecycle](references/agent-metadata-and-lifecycle.md) for dependency management and deploy commands. Deploy `AiAuthoringBundle` and all backing logic (Apex classes, Flows, Prompt Templates) and dependencies to org.2823. **Live preview** — Read [Validation & Debugging](references/agent-validation-and-debugging.md) for preview workflow and session trace analysis.283 `sf agent preview start --json --use-live-actions --authoring-bundle <Developer_Name>`284 then send test utterances with:285 `sf agent preview send --json --authoring-bundle <Developer_Name> --session-id <ID> -u "<message>"`286 Test key conversation paths to validate agent behavior when backed by live actions.287 **CHECKPOINT — Do NOT proceed to Publish unless ALL are true:**288 - `validate authoring-bundle` passes with zero errors289 - Live preview (`--use-live-actions`) tested with representative utterances per subagent290 - Traces confirm correct subagent routing and action invocation291 - User explicitly approves deployment2924. **Publish** — Publish validates metadata structure, not agent behavior. DO NOT publish as part of a dev/test inner loop. ONLY publish as the FINAL step prior to activating the agent and surfacing it to end users.293 `sf agent publish authoring-bundle --json --api-name <Developer_Name>`294 If publish fails, follow *Troubleshooting Publish Failures* in [Metadata & Lifecycle](references/agent-metadata-and-lifecycle.md) before retrying.2955. **Activate** — Makes new version available to users.296 `sf agent activate --json --api-name <Developer_Name>`2976. **Verify published agent** — Preview user-facing behavior AFTER activation with298 `sf agent preview start --json --api-name <Developer_Name>`299 Use `--api-name`, not `--authoring-bundle`.3007. **Configure end-user access** — ONLY for employee agents. Read [Agent Access Guide](references/agent-access-guide.md) to configure perms and assign access.301302#### Reference Files3033041. [CLI for Agents](references/salesforce-cli-for-agents.md) — exact305 command syntax for deploy, publish, activate, deactivate3062. [Validation & Debugging](references/agent-validation-and-debugging.md) —307 compilation validation, preview workflow3083. [Metadata & Lifecycle](references/agent-metadata-and-lifecycle.md) —309 dependency management, deploy commands; publish troubleshooting3104. [Agent Access Guide](references/agent-access-guide.md) — end-user311 access permissions, visibility troubleshooting3125. [Known Issues](references/known-issues.md) — only load when deploy313 hangs, publish fails, or activate fails unexpectedly314315### Diagnose Production Issues316317User's agent is published and active but experiencing issues not caught during preview. Includes credit overconsumption, token or size limit failures, loop guardrail interruptions, reserved keyword runtime errors, VS Code sync failures, or unexpected behavioral differences between preview and production.318319#### Required Steps320321Read [CLI for Agents](references/salesforce-cli-for-agents.md) for exact command syntax.3223231. **Classify issue** — Determine whether this is billing/cost concern, runtime limit, naming conflict, tooling issue, or behavioral difference between preview and production.3242. **Check known production gotchas** — Read [Production Gotchas](references/production-gotchas.md) for credit consumption, token limits, loop guardrails, reserved keywords, lifecycle hooks, and VS Code workarounds.3253. **Compare preview vs production behavior** — If issue is behavioral, preview published agent with326 `sf agent preview start --json --api-name <Developer_Name>`327 (not `--authoring-bundle`). Compare against live-actions authoring bundle preview `--authoring-bundle <Developer_Name> --use-live-actions` to isolate preview-vs-production differences.3284. **Check known issues** — Read [Known Issues](references/known-issues.md) for platform bugs that may explain production-only failures.3295. **Fix and republish** — Apply fixes, validate, re-preview, publish, activate, verify. Follow Deploy, Publish, and Activate steps.3306. **Explain diagnosis** — Tell user what was happening and what you changed. Explain root cause.331332#### Reference Files3333341. [Production Gotchas](references/production-gotchas.md) — credit335 consumption, token limits, loop guardrails, reserved keywords,336 lifecycle hooks, VS Code workarounds3372. [CLI for Agents](references/salesforce-cli-for-agents.md) — command338 syntax for preview, publish, activate3393. [Validation & Debugging](references/agent-validation-and-debugging.md) —340 preview workflow, session trace analysis3414. [Known Issues](references/known-issues.md) — only load when issue may342 be a platform bug343344### Delete or Rename an Agent345346User wants to remove agent or change its name. Maintenance tasks complicated by `AiAuthoringBundle` versioning and published version dependencies.347348#### Required Steps349350Read [CLI for Agents](references/salesforce-cli-for-agents.md) for exact command syntax.3513521. **Understand current state** — Read [Metadata & Lifecycle](references/agent-metadata-and-lifecycle.md) for versioning, delete mechanics, and rename mechanics. Identify whether agent has been published, how many versions exist, and whether it's currently active.3532. **Deactivate if active** —354 `sf agent deactivate --json --api-name <Developer_Name>`355 Active agent cannot be deleted or renamed.3563. **Execute operation** — For delete: follow delete mechanics in Metadata & Lifecycle reference. For rename: follow rename mechanics in same reference.3574. **Clean up orphans** — Check for and remove orphaned metadata: Bot, BotVersion, GenAiPlannerBundle, GenAiPlugin, GenAiFunction. Metadata & Lifecycle reference details what to look for.3585. **Validate** — Confirm operation completed cleanly. For rename, validate new bundle compiles and preview to confirm behavior.359360#### Reference Files3613621. [CLI for Agents](references/salesforce-cli-for-agents.md) — exact363 command syntax for delete, deactivate, retrieve3642. [Validation & Debugging](references/agent-validation-and-debugging.md) —365 compilation validation, preview workflow3663. [Metadata & Lifecycle](references/agent-metadata-and-lifecycle.md) —367 delete mechanics, rename mechanics, orphan cleanup368369### Test an Agent370371User wants to create automated tests for Agent Script agent. Involves writing `AiEvaluationDefinition` test specs in YAML format that define test scenarios, expected behaviors, and quality metrics.372373#### Required Steps374375Read [CLI for Agents](references/salesforce-cli-for-agents.md) for exact command syntax.3763771. **Establish coverage baseline** — Read Agent Spec. If no Agent Spec exists, reverse-engineer first by following Comprehend steps. Map every subagent, action, and flow control path to identify what needs test coverage.3782. **Design test scenarios** — For test design methodology, expectations, metrics, test spec YAML format, and templates, use **agentforce-test** skill. That skill owns all testing content. For each coverage target, write one or more test scenarios: user utterance, expected subagent routing, expected action invocations, and expected agent response. Include both happy paths and edge cases.3793. **Write test spec YAML** — Use template and reference files from **agentforce-test** skill. Save to `specs/<Agent_API_Name>-testSpec.yaml` in SFDX project.3804. **Create test metadata** — Generate `AiEvaluationDefinition` from test spec using CLI.3815. **Deploy test** — Deploy `AiEvaluationDefinition` to org.3826. **Run tests** — Execute test run using CLI. Capture results.3837. **Analyze results** — Compare actual outcomes against expectations. For failures, identify whether issue is in agent code, backing logic, or test spec itself.3848. **Iterate** — Fix agent code or test spec as needed, redeploy, and re-run until coverage targets are met.385386#### Reference Files3873881. [CLI for Agents](references/salesforce-cli-for-agents.md) — exact389 command syntax for test create, test run, test results3902. [Core Language](references/agent-script-core-language.md) — agent391 structure for designing meaningful tests3923. [Design & Agent Spec](references/agent-design-and-spec-creation.md) —393 Agent Spec as test coverage baseline3944. **agentforce-test** skill — test spec YAML format, expectations,395 metrics, test design methodology, and test spec template396397## The Agent Spec398399**Agent Spec** is the central artifact this skill produces and consumes. A structured design document representing agent's purpose, subagent graph, actions with backing logic, variables, gating logic, and behavioral intent.400401Agent Specs evolve with the agent. Sparse during agent creation (purpose, topics, directional notes). Fleshed out during agent build (flowchart, backing logic mapped, gating documented). Reverse-engineered when comprehending existing agents. Critical for advanced troubleshooting, providing reference to compare expected vs. actual behavior. During testing, test coverage maps against it.402403Always produce or update Agent Spec as first step of any operation that changes or analyzes agent. It is consistent grounding to work from, and a durable artifact a developer can review.404405Read [Design & Agent Spec](references/agent-design-and-spec-creation.md) for Agent Spec structure and production methodology.406407## Assets408409The `assets/` directory contains templates and examples. Read when you need a starting point or a concrete reference for artifacts and source files.410411- **`assets/agent-spec-template.md`** — Agent Spec template with all sections and placeholder content. Copy to `<AgentName>-AgentSpec.md` in project directory, then fill in during design. Save Agent Spec as file — significant design artifact that benefits from proper rendering, especially Mermaid Subagent Map diagram.412413- **`assets/local-info-agent-annotated.agent`** — Complete annotated example based on Local Info Agent, showing all major Agent Script constructs in context with inline comments explaining why each construct is used. Read when you need concrete reference for how concepts compose into working agent, or as fallback when focused examples in reference files aren't sufficient.414415- **`assets/template-single-subagent.agent`** — Minimal agent with one subagent. Copy and modify for simple agents.416417- **`assets/template-multi-subagent.agent`** — Minimal agent with multiple subagents and transitions. Copy and modify for complex agents.418419- **`assets/invocable-apex-template.cls`** — Reference for invocable Apex420 classes. Copy and modify when complex Apex backing logic is desired.421422## Important Constraints423424- **Use only Salesforce CLI and Salesforce org.** Do not reference or depend on other skills, MCP servers, or external tooling. All commands use `sf` (Salesforce CLI).425426- **Only certain backing logic types are valid for actions.** For example, only invocable Apex (not arbitrary Apex classes) can back action. Similar constraints may apply to Flows and Prompt Templates. When wiring actions to backing logic, consult Design & Agent Spec reference file for valid types and stubbing methodology.427428- **`sf agent generate test-spec` is not for agentic use.** It is interactive, REPL-style command designed for humans. When creating test specs, start from boilerplate template in assets instead.429430## Common Issues Quick Reference431432**`Internal Error, try again later` during publish:**433Invalid or missing `default_agent_user`. Re-run query from [Design & Agent Spec](references/agent-design-and-spec-creation.md), Section 3. Do not invent username.434435**`Unable to access Salesforce Agent APIs...` during preview:**436`default_agent_user` lacks permissions. See [Agent User Setup & Permissions](references/agent-user-setup.md). Do NOT publish as fix — `--use-live-actions` does not require published agent.437438**Permission error referencing different username than configured:**439Same fix as above — error references org's default running user, but root cause is Einstein Agent User permissions.440441**Agent fails with permission error even though current subagent's actions work:**442Planner validates ALL actions across ALL subagents at startup. One missing permission fails entire agent.443444**Apex action returns empty results in live preview but works in simulated:**445`WITH USER_MODE` + missing object permissions = silent failure (0 rows, no error). See [Agent User Setup & Permissions](references/agent-user-setup.md), Section 6.2.446447## Syntax Quick Reference448449- Block order: `system:` → `config:` → `variables:` → `connection:` → `knowledge:` → `language:` → `start_agent agent_router:` → `subagent:` blocks450- Indentation: **4 spaces** per indent level. Never use tabs. Mixing spaces and tabs breaks the parser.451- Booleans: `True`/`False` (capitalized)452- Strings: always double-quoted453- Numeric action I/O: bare `number` works for variables but **fails at publish** in action I/O. Use `object` + `complex_data_type_name` for numeric action parameters. See [Complex Data Types](references/complex-data-types.md) for the full decision tree.454- `after_reasoning:` has NO `instructions:` wrapper455- No `else if` — use compound `if x and y:` or sequential flat ifs456- Reserved `@InvocableVariable` names: `model`, `description`, `label` — cannot be used as Apex parameter names457- `@inputs` and `@outputs` are ephemeral: `@inputs` only in `with`; `@outputs` only in `set`/`if` immediately after the action. `@inputs` in `set` = silent failure.458459See [Complex Data Types](references/complex-data-types.md) for the full Lightning type mapping decision tree. See [Instruction Resolution](references/instruction-resolution.md) for the 3-phase runtime model.460461## Architecture Patterns462463Three primary FSM patterns. Full details with code in [Architecture Patterns](references/architecture-patterns.md).464465- **Hub-and-Spoke** (most common): `start_agent` routes to specialized subagents. Each subagent has "back to hub" transition. Do NOT create a separate routing subagent.466- **Verification Gate**: Identity verification before protected subagents. `available when` guards on protected transitions.467- **Post-Action Loop**: Post-action checks at TOP of `instructions: ->` trigger on re-resolution after action completes.468469## Scoring Rubric470471Score every generated agent on 100 points across 7 categories: Structure (15), Safety (15), Deterministic Logic (20), Instruction Resolution (20), FSM Architecture (10), Action Configuration (10), Deployment Readiness (10).472473See [Scoring Rubric](references/scoring-rubric.md) for the complete rubric.474475## Review Mode476477When user provides an existing `.agent` file (e.g., `review path/to/file.agent`):4784791. Read the file4802. Score against the 100-point rubric4813. List every issue grouped by category4824. Provide corrected code snippets4835. Offer to apply fixes484485## Safety Review4864877-category LLM-driven safety review for `.agent` files. Integrated into Phase 0 of authoring and deployment. Categories: Identity & Transparency, User Safety, Data Handling, Content Safety, Fairness, Deception, Scope & Boundaries.488489See [Safety Review](references/safety-review-reference.md) for the complete framework, severity levels, false positive guidance, and adversarial test prompts.490491## Discover & Scaffold492493Validate action targets exist in org and generate stubs for missing ones.494495See [Discover Reference](references/discover-reference.md) and [Scaffold Reference](references/scaffold-reference.md).496497**CRITICAL:** Stubs must return realistic data, not `'TODO'`. Placeholder responses cause SMALL_TALK grounding because the LLM falls back to training data.498499## Deploy Lifecycle500501Validate → deploy metadata → publish bundle → activate. See [Deploy Reference](references/deploy-reference.md) for phases, error recovery, CI/CD, and rollback.502503## Template Assets504505Ready-to-use `.agent` templates in `assets/agents/` (hello-world, simple-qa, multi-subagent, production-faq, order-service, verification-gate). See also `assets/patterns/` for 11+ reusable design patterns and [Examples](references/examples.md) for inline walkthroughs.506507## Additional References508509| Topic | File |510|-------|------|511| Architecture patterns | [architecture-patterns.md](references/architecture-patterns.md) |512| Type mapping decision tree | [complex-data-types.md](references/complex-data-types.md) |513| Feature validity by context | [feature-validity.md](references/feature-validity.md) |514| Instruction resolution model | [instruction-resolution.md](references/instruction-resolution.md) |515| Complete agent examples | [examples.md](references/examples.md) |