Sub topic 2
Topics: Scoping What the Agent Does
This chapter assumes you understand LLM agents, prompts, actions, variables, and basic if/else logic. Agent Script is Salesforce Agentforce’s scripting language for defining an agent’s fixed behavior while leaving suitable decisions to the model.
Topics: scoped responsibilities
A topic is a named area of work. It contains the description, instructions, actions, and transitions needed for one responsibility. Topics reduce confusion by giving the model a smaller set of relevant rules.
For example, an order topic can handle delivery questions without also exposing refund actions. A topic should describe what it handles and what it should not handle.
topic order_status:
description: "Answer questions about an existing order"A topic is a boundary, not just a prompt label. Put required steps and permitted actions inside the topic that owns them.
The starting topic routes the first request
The start_agent declaration identifies the topic that receives the first request. It commonly acts as a router. The model can classify the request, but the script defines the destinations it may choose.
start_agent topic_selector:
description: "Route the customer to the right topic"
reasoning:
instructions: ->
| Decide whether the customer is asking about an order.
actions:
go_to_order_status: @utils.transition to @topic.order_statusThe transition target is fixed: go_to_order_status always leads to order_status. The model decides when to use the transition, based on the routing instructions.
Instructions mix prompt text with logic
An instruction block can contain natural-language prompt text and procedural logic. The logic is evaluated by the script. The resulting text is then supplied to the model.
topic order_status:
reasoning:
instructions: ->
if @variables.order_id == "":
| Ask for the order number before doing anything else.
else:
| Help with order {[email protected]_id}.Here, the model writes the response, but the script decides which instruction it receives.
Conditions branch on state
A condition checks a value, such as whether order_id is empty. Variables preserve state across turns, so a later turn can follow a different branch. This prevents the agent from relying on the model to remember a required sequence.
Exercise
Why is the order-number check better in a condition than only in a natural-language prompt?
Show answer
The condition applies the required branch consistently, even when the model might otherwise skip the question.