Agent Script
Get to know the language for building agents in Agentforce Builder. Whether you’re working in Canvas view, Script view, or chatting with Agentforce to build and customize your agent, you’re writing Agent Script. Use Agent Script to build predictable, context-aware agent workflows that don’t rely solely on interpretation by an LLM.
Required Editions
| Available in: Lightning Experience |
| Available in: Enterprise, Performance, Unlimited, and Developer Editions. Required add-on licenses vary by agent type. |
What's Agent Script?
Agent Script is the language for building agents in Agentforce Builder. Script combines the flexibility of natural language instructions for handling conversational tasks with the reliability of programmatic expressions for handling business rules. In script, you use expressions to define if/else conditions, transitions, and other logic; set, modify, and compare variables; and select subagents and actions. You can build predictable, context-aware agent workflows that don’t rely solely on interpretation by an LLM. For example, you can use script to control when your agent transitions from one subagent to another or when actions are run in a particular sequence (sometimes called action chaining).
Agentforce Builder gives you several ways to write Agent Script.
- You can chat with Agentforce and explain what you want your agent to be able to do (for example, “If the order total is over $100, then offer free shipping.”). Agentforce converts your request into subagents, actions, instructions, and other expressions.
- In Canvas view, Agent Script is summarized into easily understandable blocks, which you can expand to view the underlying script. You can edit your agent with the help of quick action shortcuts. Type / to add expressions for common patterns (for example, if/else conditionals) and @ to add resources (subagents, actions, and variables).
- Advanced users can switch to Script view to write and edit script directly, with developer-friendly aids like syntax highlighting, autocompletion, and validation.
Developers can also use Agentforce DX to generate or retrieve a script file into their local Salesforce DX project and then work with it in Visual Studio Code. The Agentforce DX VS Code Extension fully supports the Agent Script language with standard code editing features.
What can you do with Agent Script?
Agent Script preserves the conversational skills and complex reasoning ability derived from natural language prompts, and it adds the determinism of programmatic instructions. For example, in Agent Script, you can define:
- Specific areas where an LLM is free to make reasoning decisions.
- Specific areas where the agent must execute deterministically.
- Variables to reliably store information about the agent's current state, rather than relying on LLM context memory.
- Conditional expressions (if/else) to determine the agent's execution path or LLM's
utterances. For example, you can instruct the agent to speak differently to the customer
based on the value of the
is_member variable. Or, you can deterministically specify which action to run based on the value of theappointment_typevariable. - Conditions under which the agent transitions to a new subagent. You can deterministically transition to a new subagent. Or you can expose a subagent transition to the LLM as an action, allowing the LLM to decide when and whether to switch subagents.
Example Agent Script
Here’s a simple example of what Agent Script looks like.
system:
instructions: "You are a friendly and empathetic agent that helps customers with their questions."
messages:
error: "Sorry, something went wrong."
welcome: "Hello! How are you feeling today?"
variables:
isPremiumUser: mutable boolean = False
description: "Indicates whether the user is a premium user."
config:
agent_name: "HelloWorldBot"
default_agent_user: "hello@world.com"
user_locale: "en_US"
start_agent hello_world:
description: "Respond to the user."
reasoning:
instructions: ->
if @variables.isPremiumUser:
| ensure you ask the user if they want to redeem their Premium points
else:
| ensure you ask the user if they want to upgrade to Premium service.
Where can you learn more?
To learn more about how to build agents with Agent Script in Canvas view, see Building Agents in Canvas View.
To learn more about using the language directly in Script view, see the Agent Script Developer Guide.

