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.
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 block | What it is | Who decides when it's used |
|---|---|---|
| Agent-level (system) instructions and messages | Persona and global guidance, plus required welcome and error messages | Included in every prompt |
| Subagents (formerly topics) | A job the agent can do, with a name, description, reasoning instructions, and actions | The Agent Router classifies to one, or logic transitions to one |
| Reasoning instructions | A mix of deterministic logic and natural-language prompt text | Logic runs in order; prompt text goes to the LLM |
| Actions | Tools backed by flows, Apex, prompt templates, APIs, or MCP tools | Either run deterministically in instructions or chosen by the LLM as reasoning actions |
| Variables | Stored state that persists across turns | Set by logic, action outputs, or the LLM through a utility |
| Connections | Channel settings such as Messaging, Enhanced Chat v2, Slack, or telephony | Determine where and how the agent responds |
The Runtime Journey of a Message
Salesforce Help breaks the journey into seven steps:
- A user sends a message.
- The agent goes to the starting subagent. In Agent Script, that's the block that uses the
start_agentprefix. 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. - 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.
- The agent builds a prompt from four ingredients: agent-level instructions, recent conversation history, the resolved subagent instructions, and the subagent's reasoning actions.
- 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.
- 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.
- The agent sends the response. The user's next message starts the journey again.
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
| Symbol | Meaning | Example |
|---|---|---|
key: value | Property-based declarations | agent_name: "OrderHelper" |
| Indentation | Defines structure; use spaces, not tabs | Nested blocks under reasoning: |
@ | References a resource defined in the script | @variables.order_id, @actions.get_order, @subagent.Escalation |
-> | Starts logic instructions that run deterministically | instructions: -> |
| | 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 input | with order_id = ... |
# | Comment | # verify before lookup |
The main blocks
system– Agent-level instructions and the required welcome and error messages. A subagent can overridesystem.instructionswhen it needs a different persona.config– Agent identity such asagent_name. Agentforce Service agents also needdefault_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.languageandconnection– Supported locales and channel connections such as Enhanced Chat.start_agent– The entry point for every user message, normally the Agent Router.subagentblocks – Each has adescription, action definitions (actions:with targets such asflow://Get_Order), and areasoning:block withinstructionsand reasoningactions. The oldertopickeyword is deprecated in favor ofsubagent.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 appears | Behavior | Use it when |
|---|---|---|
In reasoning instructions with run @actions.name | Runs deterministically before reasoning; you must bind inputs (with) and store outputs (set) yourself | The 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 filter | The 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, andtransition toin 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.
In the Agentforce runtime journey, what happens when an agent first moves into a subagent?
Which Agent Script symbol marks text that is added to the prompt sent to the LLM?
An architect adds run @actions.get_order_summary inside a subagent's reasoning instructions. How does the action behave?
Which step in the runtime journey applies only to Agentforce Service agents?