From agentforce-adlc
Builds, modifies, debugs, and deploys Salesforce Agentforce AI agents using Agent Script, .agent files, aiAuthoringBundle metadata, and sf CLI commands like generate/preview/publish/test.
npx claudepluginhub salesforceairesearch/agentforce-adlc --plugin agentforce-adlcThis skill uses the workspace's default tool permissions.
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.
README.mdassets/README-legacy.mdassets/agent-spec-template.mdassets/agents/README.mdassets/agents/hello-world.agentassets/agents/multi-subagent.agentassets/agents/order-service.agentassets/agents/production-faq.agentassets/agents/production-faq.bundle-meta.xmlassets/agents/simple-qa.agentassets/agents/verification-gate.agentassets/apex/models-api-queueable.clsassets/bundle-meta.xmlassets/components/apex-action.agentassets/components/error-handling.agentassets/components/escalation-setup.agentassets/components/flow-action.agentassets/components/n-ary-conditions.agentassets/components/subagent-with-actions.agentassets/deterministic-routing.agentBuilds, modifies, debugs, and deploys Salesforce Agentforce AI agents using Agent Script, .agent files, aiAuthoringBundle metadata, and sf CLI commands like generate, preview, publish, test.
Authors .agent files for deterministic Agentforce agents using FSM flows, topic routing, slot filling, and CLI workflows like sf agent generate/validate/publish/activate.
Provides guidance on Salesforce Agentforce AI agents, Atlas Reasoning Engine, components, and 2025 features for autonomous automation.
Share bugs, ideas, or general feedback.
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.
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.
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.
Every task domain below has Required Steps. Follow verbatim, in order. Do not substitute your own plan or skip steps.
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.
Read CLI for Agents for exact command syntax.
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.default_agent_user, connection messaging:, or MessagingSession linked variables. Remove if present. See Examples for a complete employee agent example.sf agent generate authoring-bundle --json --no-spec --name "<Label>" --api-name <Developer_Name>.agent file using reference files and templates. Do not create .agent or bundle-meta.xml files manually.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.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.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--use-live-actions) tested with representative utterances per subagentsf agent publish authoring-bundle --json --api-name <Developer_Name>
If publish fails, follow troubleshooting checklist in Metadata & Lifecycle, Section 5 before retrying.sf agent activate --json --api-name <Developer_Name>sf agent preview start --json --api-name <Developer_Name>
Use --api-name, not --authoring-bundle.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.".
sfdx-project.json to identify package directories. Find AiAuthoringBundle directory within them. Read .agent file and bundle-meta.xml..agent file.target, locate backing implementation (Apex class, Flow, Prompt Template) in project. Note input/output contracts..agent file explaining flow control decisions, gating rationale, and subagent relationships.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.
Read CLI for Agents for exact command syntax.
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..agent file to implement approved changes.sf agent validate authoring-bundle --json --api-name <Developer_Name>
If validation fails, read Validation & Debugging to diagnose and fix, then re-validate.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.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--use-live-actions) tested with representative utterances per subagentsf agent publish authoring-bundle --json --api-name <Developer_Name>
If publish fails, follow troubleshooting checklist in Metadata & Lifecycle, Section 5 before retrying.sf agent activate --json --api-name <Developer_Name>sf agent preview start --json --api-name <Developer_Name>
Use --api-name, not --authoring-bundle.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."
Read CLI for Agents for exact command syntax.
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..agent file that cause each error.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.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.
Read CLI for Agents for exact command syntax.
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.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.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.
Read CLI for Agents for exact command syntax.
sf agent validate authoring-bundle --json --api-name <Developer_Name>
Do not proceed if validation fails.AiAuthoringBundle and all backing logic (Apex classes, Flows, Prompt Templates) and dependencies to org.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--use-live-actions) tested with representative utterances per subagentsf agent publish authoring-bundle --json --api-name <Developer_Name>
If publish fails, follow Troubleshooting Publish Failures in Metadata & Lifecycle before retrying.sf agent activate --json --api-name <Developer_Name>sf agent preview start --json --api-name <Developer_Name>
Use --api-name, not --authoring-bundle.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.
Read CLI for Agents for exact command syntax.
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.User wants to remove agent or change its name. Maintenance tasks complicated by AiAuthoringBundle versioning and published version dependencies.
Read CLI for Agents for exact command syntax.
sf agent deactivate --json --api-name <Developer_Name>
Active agent cannot be deleted or renamed.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.
Read CLI for Agents for exact command syntax.
specs/<Agent_API_Name>-testSpec.yaml in SFDX project.AiEvaluationDefinition from test spec using CLI.AiEvaluationDefinition to org.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.
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.
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.
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.
system: → config: → variables: → connection: → knowledge: → language: → start_agent agent_router: → subagent: blocksTrue/False (capitalized)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: wrapperelse if — use compound if x and y: or sequential flat ifs@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.
Three primary FSM patterns. Full details with code in Architecture Patterns.
start_agent routes to specialized subagents. Each subagent has "back to hub" transition. Do NOT create a separate routing subagent.available when guards on protected transitions.instructions: -> trigger on re-resolution after action completes.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.
When user provides an existing .agent file (e.g., review path/to/file.agent):
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.
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.
Validate → deploy metadata → publish bundle → activate. See Deploy Reference for phases, error recovery, CI/CD, and rollback.
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.
| 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 |