Language Characteristics
Agent Script Blocks
Specify Different Models
Flow of Control
Manage Agents
Download Documentation
Examples
Agent Script is a language designed by Salesforce specifically to build Agentforce agents. This page covers some key characteristics of the language before digging into the specifics.
Agent Script is a compiled language. When you save a version of the agent, the script compiles into lower-level metadata that is used by the reasoning engine.
Agent Script combines deterministic logic with LLM reasoning in a single workflow. This hybrid approach gives you predictable execution where you need it, while preserving the LLM’s ability to handle nuanced conversations.
->) run deterministically every time. Use them for business rules, running actions, setting variables, and conditional branching.|) are natural language sent to the LLM. The LLM interprets these instructions and decides how to respond to the customer.See Flow of Control, Agent Script Patterns, and Reasoning Instructions.
Agent Script has elements of both declarative and procedural languages so that you can build an agent that is both predictable and easy to maintain.
Agent Script is designed to be human-readable so that even non-developers can get a basic understanding of how the agent works.
Agent Script is made up of a collection of properties. Each property is shown as key: value. Some properties are multiple lines and some properties contain sub-properties, but the key is always before the colon (:) and the value is always after the colon.
1description: "Get account info"The top-level properties are called blocks. For instance, we call this section the config block.
1config:
2 developer_name: "Demo_Agent_1"
3 agent_label: "Demo Agent"
4 description: "This is my demo agent"Agent Script is whitespace-sensitive, similar to languages like Python or YAML, meaning that indentation is used to indicate structure and relationships between properties. To indicate that a value belongs to the previous line’s property, indent with at least 2 spaces or 1 tab. However, you must choose one indentation method and use it consistently throughout the entire script. All lines at the same nesting level must use the same indentation, and mixing spaces and tabs will cause parsing errors.
1inputs:
2 input_1: string
3 input_2: stringTo specify logic instructions, use the arrow symbol ( -> ) followed by indented instructions.
1instructions: ->
2 if @variables.ready_to_book:
3 run @actions.get_account_info
4 with account_id=@variables.account_id
5 set @variables.hotel_code=@outputs.hotel_codeTo specify multiline strings in reasoning instructions, descriptions, and system messages, use the pipe symbol ( | ).
1instructions:|
2 Welcome to our service!
3 Please provide details about your request.
4 I'll help you with whatever you need.The pipe symbol can also be used to switch to a prompt from logic-based instructions.
1reasoning:
2 instructions: ->
3 | You are assessing the customer's timing for making a decision.
4 Follow these rules to determine what to ask:
5
6 if @variables.Lead_Record.S4STiming != "":
7 | Existing timing data found.
8 Current Timing Value: {! @variables.Lead_Record.S4STiming }
9
10 Ask: "From what we have, you're looking to make a decision by {! @variables.Lead_Record.S4STiming }. Is that still correct?"
11
12 Wait for their response before proceeding.See Reasoning Instructions in the Agent Script Reference.
You can access resources, such as actions, subagents, and variables, using the @ symbol.
@actions.<action_name>: References an action.@subagent.<subagent_name>: References a subagent.@variables.<variable_name>: References a variable.@outputs.<output_name>: References an action output.To run an action, use the run command. Use the with command to provide inputs and use the set command to store outputs.
1run @actions.show_great_example
2 with QuestionRecordId=@variables.my_great_question
3 set @variables.my_great_answer = @outputs.AnswerDescriptionSee Actions in the Agent Script Reference.
When referencing a variable from within prompt text in reasoning instructions, you must specify the variable within brackets: {!@variables.<variable_name>}. For example:
1| Ask the user this question: {!@variables.my_question}See Variables in the Agent Script Reference.
You can specify a subagent as a tool available to the LLM. For more information, see Tools (Reasoning Actions).
Agent Script uses familiar flow control syntax, such as if and else. It also uses basic mathematical expressions (+, -) and comparison expressions (==, !=, >, <). You can check for empty values using is None and is not None.
1if @variables.count >= 10:
2 run @actions.count_achieved_announcement
3else:
4 run @actions.count_missed_announcementSee Conditional Expressions and Supported Operators in the Agent Script Reference.
You can specify comments in Agent Script with the pound (#) symbol followed by the comment. The script ignores any content on the line after the pound symbol. Use this mechanism to document the script within the script.
1# This is an agent sample script that demonstrates deterministic behavior