Language Characteristics
Agent Script Blocks
Specify Different Models
Flow of Control
Manage Agents
Download Documentation
Examples
Understanding the order of execution and flow of control helps you to design better agents. Agentforce has these main execution paths:
All requests, including the first request, begin at the agent router, the start_agent block. You typically use the start_agent subagent to set the initial value of variables, and to perform subagent classification. Subagent classification tells the LLM which subagent to choose based on the current context.
See Start Agent Block.
Agentforce uses a subagent’s text instructions, variables, if/else conditions, and other programmatic instructions to create an LLM prompt. The reasoning instructions are processed sequentially, in top-to-bottom order. While the reasoning instructions can contain programmatic logic and text instructions, the LLM only starts reasoning after it has received the resolved prompt, not while Agentforce is still parsing.
If reasoning instructions contain a transition command, Agentforce immediately transitions to the specified subagent, discarding any existing resolved prompt. The final prompt only contains instructions that were resolved from the second subagent.
Agentforce processes a subagent to create a prompt, which it then sends to the LLM. Consider this subagent.
1subagent Order_Management:
2 description: "Handles order inquiries."
3 reasoning:
4 instructions:->
5 set @variables.num_turns = @variables.num_turns + 1
6 run @actions.get_delivery_date
7 with order_ID=@variables.order_ID
8 set @variables.updated_delivery_date=@outputs.delivery_date
9
10 | Tell the user that the expected delivery date for order number {!@variables.order_ID} is {!@variables.updated_delivery_date}
11
12 run @actions.check_if_late
13 with order_ID=@variables.order_ID
14 with delivery_date=@variables.updated_delivery_date
15 set @variables.is_late = @outputs.is_late
16
17 if @variables.is_late == True:
18 | Apologize to the customer for the delay in receiving their order.
19 after_reasoning:
20 if @variables.num_turns > 5:
21 transition to @subagent.escalate_orderSuppose that:
1234February 10, 2026num_turns is 2Here’s the prompt that Agentforce creates after processing the reasoning instructions:
1Tell the user that the expected delivery date for order number 1234 is February 10, 2026.
2Apologize to the customer for the delay in receiving their order.To construct the prompt, Agentforce parses the reasoning instructions line by line, following these steps:
num_turns from 2 to 3.get_delivery_date.updated_delivery_date to the value of outputs.delivery_date, which was returned by the action.Tell the user that the expected delivery date for order number 1234 is February 10, 2026.check_if_late.is_late to the value of outputs.is_late, which was returned by the action.@variables.is_late == True.Apologize to the customer for the delay in receiving their order.after_reasoning instructions, which don’t transition because num_turns is 3.You can transition between subagents from a reasoning action, reasoning instructions, or before and after reasoning blocks. A transition (using @utils.transition to) is one-way and control doesn’t return to the previous subagent. Agentforce discards any prompt instructions from the previous subagent. Then, Agentforce reads the second subagent from top to bottom. The final prompt contains only instructions from the second subagent.
After the second subagent completes, Agentforce waits for the next customer utterance, at which point it returns to the start_agent subagent.
In this example, we’ve defined a reasoning action called go_to_account_help that transitions to the subagent account_help.
1reasoning:
2 actions:
3 go_to_account_help: @utils.transition to @subagent.account_help
4 description: "When a user needs help with account access"For more about transitions and subagents, see Referencing a Subagent as a Tool and the reference documentation for @utils.transition to.