Get Started with Agent Script
Get to know the language for building agents in Agentforce Builder. Use Agent Script to build predictable, context-aware agent workflows that don't rely solely on interpretation by an LLM.

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 topics 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 topic 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 topics, 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 (topics, 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. See Agentforce DX for more details.
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. See Reasoning Instructions.
- Specific areas where the agent must execute deterministically. See Reasoning Instructions.
- Variables to reliably store information about the agent's current state, rather than relying on LLM context memory. See Variables.
- Conditional expressions 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_membervariable. Or you can deterministically specify which action to run based on the value of theappointment_typevariable. See Conditional Expressions. - Conditions under which the agent transitions to a new topic. You can deterministically transition to a new topic. Or you can expose a topic transition to the LLM as a tool, allowing the LLM to decide when and whether to switch topics. See Tools and Utils.
Example Agent Script
Here’s a simple example of what Agent Script looks like.
1system:
2 instructions: "You are a friendly and empathetic agent that helps customers with their questions."
3 messages:
4 error: "Sorry, something went wrong."
5 welcome: "Hello! How are you feeling today?"
6
7config:
8 agent_name: "HelloWorldBot"
9 default_agent_user: "hello@world.com"
10
11language:
12 default_locale: "en_US"
13 additional_locales: ""
14
15variables:
16 isPremiumUser: mutable boolean = False
17 description: "Indicates whether the user is a premium user."
18
19start_agent hello_world:
20 description: "Respond to the user."
21 reasoning:
22 instructions: ->
23 if @variables.isPremiumUser:
24 | ask the user if they want to redeem their Premium points
25 else:
26 | ask the user if they want to upgrade to Premium serviceAmong other compelling features, you can see in the above reasoning instructions that you can specify conditional logic (after the ->) alongside LLM prompts (after the |). This combination gives you the advantages of predictable, deterministic logic, alongside the power of LLM reasoning.
Next Steps
To learn how to build agents in Canvas view or by chatting with Agentforce, see Build Enterprise-Ready Agents with the New Agentforce Builder in Salesforce Help.
To learn more about Agent Script, review these topics.
- Language Characteristics
- Agent Script Blocks
- Flow of Control
- Agent Script Patterns
- Agent Script Examples
- Manage Agent Script Agents
- Agent Script Reference