Sub topic 1
Why agents need both fixed rules and model judgement
This chapter explains why an agent built only from prompts behaves inconsistently, and why Agent Script mixes fixed logic with model judgement. The rest of the tutorial builds on this idea.
Prerequisites
This chapter assumes you already know the following:
- What an LLM-based agent is: a model that reads a conversation and decides what to say or do next.
- How prompts, tools (also called actions), and conversation turns work.
- Basic programming ideas: variables, if/else conditions, and function calls.
You do not need to know Agent Script yet. It is introduced in the next chapter.
Two kinds of behaviour
An agent's behaviour comes from two sources.
- Probabilistic behaviour comes from the model. The model reads the prompt and the conversation, then picks the most likely useful response. Two runs with the same input can differ in wording, in the tools chosen, or in the order of steps.
- Deterministic behaviour comes from fixed logic. Given the same state, a condition such as
if order_id == ""always takes the same branch.
Neither source is better. They solve different problems.
| Property | Model judgement | Fixed rules |
|---|---|---|
| Handles open-ended language | Yes | No |
| Same input gives same path | Not guaranteed | Always |
| Easy to audit | Hard | Easy |
| Good for | Understanding intent, phrasing replies | Required steps, limits, compliance |
Where prompt-only agents fail
A prompt-only agent puts every rule in text, for example: "Always verify the customer's identity before sharing order details." The model usually follows this. Usually is the problem.
Common failure modes:
- Skipped steps. The model answers a question directly and never asks for the order number.
- Reordered steps. The model issues a refund before it checks eligibility.
- Drift over a long conversation. An early instruction loses weight as the conversation grows.
- Different tool choices. The model calls one action on Monday and a different one on Tuesday for the same request.
These failures are hard to test for. A conversation can pass ten times and fail on the eleventh. Adding more warnings to the prompt ("IMPORTANT: ALWAYS verify first") lowers the failure rate but never removes it.
Splitting the work
The practical answer is to divide responsibilities.
- Put rules that must always hold into fixed logic: required order of steps, checks on state, and which actions are allowed at a given moment.
- Leave language tasks to the model: reading what the customer means, choosing a tone, and writing the reply.
A check such as "no order number yet" becomes an ordinary condition. The model never has to remember it. Only when the condition decides what to ask does the model's wording come into play.
The fixed logic decides which branch runs. The model works inside the branch.
What this looks like in Agent Script
Agent Script is the language for defining Salesforce Agentforce agents. It lets you write fixed logic and natural-language prompt text in the same file. The sketch below is illustrative, and you should check exact keys against the current documentation. It shows the idea only.
# Illustrative sketch: fixed logic decides which prompt text the model sees.
topic order_status:
description: "Answer questions about an existing order"
reasoning:
instructions: ->
if @variables.order_id == "":
| Ask the customer for their order number before doing anything else.
else:
| Help the customer with order {[email protected]_id}.The if runs the same way every time. The lines starting with | are prompt text for the model. The order-number check no longer depends on the model remembering to ask.
Choosing where a rule belongs
Ask these questions about each rule.
- Would breaking it cause real harm or cost? Use fixed logic.
- Does it depend on a value you can store and compare, such as a flag or an ID? Use fixed logic.
- Does it depend on understanding free-form language? Leave it to the model.
- Is it about style or tone? Leave it to the model.
Too much fixed logic makes the agent rigid and brittle. Too little brings back the failures above. Later chapters show how to find the balance.
Exercise
An agent must never issue a refund until it has confirmed the order is eligible. Should this rule live only in the prompt, or in fixed logic? Give one reason, and name one task you would still leave to the model.
Show answer
Put it in fixed logic. A prompt-only rule can be skipped or reordered by the model, and a wrong refund has a real cost. A condition on stored state, such as an eligibility flag, runs the same way every time. The model can still interpret the customer's request and write the reply.