1.2 How an Agent Works & the Building Blocks of Agent Script

Key Takeaways

  • Every user message starts at the starting subagent, which by default is the Agent Router defined with the start_agent block.
  • Agentforce resolves a subagent's reasoning instructions top to bottom without an LLM, then sends the resolved prompt plus reasoning actions to the LLM.
  • Salesforce documents up to seven reasoning loops, and Agentforce Service agents run a final response validation before replying.
  • In Agent Script, the arrow (->) marks deterministic logic, the pipe (|) marks prompt text, and the at sign (@) references variables, actions, and subagents.
  • An agent's Agent Script lives in a .agent file inside the AiAuthoringBundle metadata component.
Last updated: September 2026

1.2 How an Agent Works & the Building Blocks of Agent Script

Quick Answer: Agentforce agents run on the Atlas reasoning engine, which Salesforce describes as graph-based: agents follow nodes, variables, and transitions instead of relying only on a long prompt. Each message goes to a starting subagent (by default the Agent Router). The agent resolves reasoning instructions deterministically and then sends a focused prompt to the LLM. The LLM reasons over the allowed reasoning actions and responds. Agent Script is the language behind all of this.

This objective asks you to explain how an agent works and its basic building blocks. Exam scenarios usually test whether you know which parts run deterministically and which parts the LLM decides.

The Parts of an Agent

Building blockWhat it isWho decides when it's used
Agent-level (system) instructions and messagesPersona and global guidance, plus required welcome and error messagesIncluded in every prompt
Subagents (formerly topics)A job the agent can do, with a name, description, reasoning instructions, and actionsThe Agent Router classifies to one, or logic transitions to one
Reasoning instructionsA mix of deterministic logic and natural-language prompt textLogic runs in order; prompt text goes to the LLM
ActionsTools backed by flows, Apex, prompt templates, APIs, or MCP toolsEither run deterministically in instructions or chosen by the LLM as reasoning actions
VariablesStored state that persists across turnsSet by logic, action outputs, or the LLM through a utility
ConnectionsChannel settings such as Messaging, Enhanced Chat v2, Slack, or telephonyDetermine where and how the agent responds

The Runtime Journey of a Message

Salesforce Help breaks the journey into seven steps:

  1. A user sends a message.
  2. The agent goes to the starting subagent. In Agent Script, that's the block that uses the start_agent prefix. By default it's the Agent Router, which compares the recent conversation with subagent names and descriptions. From April 2026, agents built from the default Employee and Service agent templates in the new builder use the Salesforce-owned HyperClassifier model for this classification step.
  3. The agent resolves the subagent's reasoning instructions top to bottom. No LLM is involved yet. Resources are replaced with values, inline actions run, and conditions are evaluated. If logic triggers a transition, the agent moves to the other subagent before any reasoning happens.
  4. The agent builds a prompt from four ingredients: agent-level instructions, recent conversation history, the resolved subagent instructions, and the subagent's reasoning actions.
  5. The LLM reasons and acts. It can run an action or utility, ask for more information, ask a clarifying question, or answer directly. After each action it reviews the output and decides the next step. Salesforce documents up to seven reasoning loops.
  6. Agentforce Service agents validate the final response. The response is checked for grounding, scope and instruction adherence, hallucinations, and possible prompt injection. If it fails, the agent generates a new one. If no response passes, the agent tells the user it can't help. This step applies to Service agents only.
  7. The agent sends the response. The user's next message starts the journey again.
Loading diagram...
Runtime journey of one user message

Agent Script: The Language Behind the Builder

Whether you edit in Canvas view, edit in Script view, or ask the Agentforce assistant to make changes, you're producing Agent Script. The script is stored in a .agent file inside the AiAuthoringBundle metadata component, which developers can retrieve into a Salesforce DX project and edit in VS Code with Agentforce DX.

Core syntax

SymbolMeaningExample
key: valueProperty-based declarationsagent_name: "OrderHelper"
IndentationDefines structure; use spaces, not tabsNested blocks under reasoning:
@References a resource defined in the script@variables.order_id, @actions.get_order, @subagent.Escalation
->Starts logic instructions that run deterministicallyinstructions: ->
|Starts prompt text that goes to the LLM| Help the customer with their order.
{! }Template expression that resolves a value into prompt text{!@variables.customer_name}
...Slot-fill token: the LLM supplies an action inputwith order_id = ...
#Comment# verify before lookup

The main blocks

  • system – Agent-level instructions and the required welcome and error messages. A subagent can override system.instructions when it needs a different persona.
  • config – Agent identity such as agent_name. Agentforce Service agents also need default_agent_user, the agent user the agent runs as; Employee agents don't require it.
  • variables – Global state. Linked variables map to a source such as a Messaging Session field; mutable variables hold custom values.
  • language and connection – Supported locales and channel connections such as Enhanced Chat.
  • start_agent – The entry point for every user message, normally the Agent Router.
  • subagent blocks – Each has a description, action definitions (actions: with targets such as flow://Get_Order), and a reasoning: block with instructions and reasoning actions. The older topic keyword is deprecated in favor of subagent.
  • after_reasoning – Optional logic that runs after the reasoning loop exits.

A small example

system:
    instructions: "You are a friendly agent that helps customers with orders."
    messages:
        welcome: "Hi! How can I help with your order today?"
        error: "Sorry, something went wrong."
variables:
    is_premium: mutable boolean = False
        description: "Whether the customer is a premium member"
start_agent agent_router:
    description: "Welcome the user and route to the right subagent"
    reasoning:
        instructions: ->
            if @variables.is_premium:
                | Thank the customer for being a premium member.
            else:
                | Offer information about the premium program.

When is_premium is True, the LLM receives only the "thank the customer" line. The other branch never reaches the prompt. That selective, logic-driven prompt construction is the foundation of hybrid reasoning, covered in the next section.

Two Ways to Call an Action

Where the action appearsBehaviorUse it when
In reasoning instructions with run @actions.nameRuns deterministically before reasoning; you must bind inputs (with) and store outputs (set) yourselfThe step must always happen, such as loading an order summary before the conversation continues
In reasoning actions (reasoning: actions:)Exposed as a tool the LLM may choose, guided by its description and any available when filterThe user's request should decide whether the action runs

Exam Traps

  • Classification isn't the whole engine. The Agent Router selects a subagent, but logic inside the subagent can transition elsewhere before any LLM call.
  • Logic doesn't use the LLM. Conditions, run, set, and transition to in instructions all execute before reasoning.
  • Final response validation is Service-agent specific. Don't attribute it to Employee agents.
  • Descriptions matter. Subagent descriptions drive classification, and action descriptions drive tool choice.
Test Your Knowledge

In the Agentforce runtime journey, what happens when an agent first moves into a subagent?

A
B
C
D
Test Your Knowledge

Which Agent Script symbol marks text that is added to the prompt sent to the LLM?

A
B
C
D
Test Your Knowledge

An architect adds run @actions.get_order_summary inside a subagent's reasoning instructions. How does the action behave?

A
B
C
D
Test Your Knowledge

Which step in the runtime journey applies only to Agentforce Service agents?

A
B
C
D