---
schema_version: "1"
id: c22226304fa94700e658627f8f5cc925859643e3b5b2daa18d98c4164d812f94
title: Agent Script
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/ai/264-0-0/agent_script.md
canonical_url: https://help.salesforce.com/s/articleView?id=ai.agent_script.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: a91db2d1e63861d5ddadd2e6d37446eb3e207bdc887fb1aa7828911613dfda5f
description: 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.
products:
  - Agentforce
  - Cross Cloud
release: "264"
---
# 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

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>Enterprise</strong>, <strong>Performance</strong>, <strong>Unlimited</strong>, and <strong>Developer</strong> Editions. <a href="https://help.salesforce.com/s/articleView?id=ai.agent_setup_explore_types.htm&amp;release=264.0.0&amp;type=5" title="Learn about agent types and default templates for specific clouds and common use cases.">Required add-on licenses vary by agent type.</a></td></tr></tbody></table>

## 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 Agent Optimizer](https://help.salesforce.com/s/articleView?id=ai.agent_optimize_dev.htm&release=264.0.0&type=5 "Focus on what you want your agent to do, not how to configure or fix it. Agent Optimizer is a built-in coding agent that extends, refines, and troubleshoots your agents directly in Agentforce Builder, at no additional cost. Explore use cases and considerations for working with Optimizer.") 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](https://developer.salesforce.com/docs/ai/agentforce/guide/agent-dx.html) 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 the `appointment_type` variable.
- 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](https://help.salesforce.com/s/articleView?id=ai.agent_canvas.htm&release=264.0.0&type=5 "Get to know the features of Agentforce Builder’s Canvas view that help you build powerful and reliable agents with Agent Script.").

To learn more about using the language directly in Script view, see the [Agent Script Developer Guide](https://developer.salesforce.com/docs/ai/agentforce/guide/agent-script.html).

- **[Example: More Reliable Agent Instructions with Agent Script](https://help.salesforce.com/s/articleView?id=ai.agent_example_script_before_after.htm&release=264.0.0&type=5)**  
    Agent Script in the new Agentforce Builder makes it possible to build enterprise-ready agents that get your business processes right every time. This example highlights a few ways Agent Script can help you write instructions that manage instruction overload, reduce latency, and improve overall agent accuracy, instruction adherence, and response quality.