AI Agents

Deterministic Logic

Core concept: Deterministic logic

Make agents predictable: store facts in variables, gate subagents and actions with conditions, and put exact values into prompts with template expressions.

Core concept: Deterministic logic

Three tools for predictable agentsDETERMINISTIC LOGICThree tools for predictableagentsVariablesHold known factsfor the session.Filtersavailable when:gate subagentsand actions.Templateexpressions{!@variables.x}puts exactvalues inprompts.Same conditions, same behaviour, every time.

An LLM on its own can treat the same request differently each time. For anything with a business rule, you want the opposite: the same conditions should always lead to the same behaviour. That is deterministic logic.

The exam objective names three tools for it: variables, filters (conditions) and template expressions. In the new Agentforce Builder they are written in Agent Script; in the legacy builder they live in the Context panel. The ideas are the same.

Understanding agent variables

Variables are the agent’s memoryDETERMINISTIC LOGICVariables are the agent’s memoryInstructionsTailor a reply with astored value.ConditionsDecide whethersomething may run.Action inputsPass a value insteadof asking again.ActionoutputsStore a result forlater steps.Variables
Variables feeding actions (script view): (1) an action input taken from the VerifiedCustomerId variable, so the agent doesn’t ask again, (2) the same variable reused by another action.
Variables feeding actions (script view): (1) an action input taken from the VerifiedCustomerId variable, so the agent doesn’t ask again, (2) the same variable reused by another action.

Variables are the agent’s memory. They hold facts so the agent doesn’t have to rely on what the LLM remembers from the conversation.

  • Use a variable in instructions to tailor a reply.
  • Use it in a condition to decide whether something may run.
  • Bind it to an action input so the agent doesn’t ask again.
  • Store an action output in it so later steps can use the result.

Variables: Quick reference guide

Kinds of variableDETERMINISTIC LOGICKinds of variableContextAgentvariableLegacy customSet bySalesforce(session)Actions,logic or theLLMYou, in theContext panelAgent canchange?NoYes, ifmutableYesReference$Context.Field@variables.name{!VarName}The Agent API can also pass values in when asession starts.
Variables in Agentforce Builder: (1) a custom Boolean, isVerified, that the agent sets once the customer is verified, (2) context variables filled automatically from the Messaging Session, (3) create your own variable.
Variables in Agentforce Builder: (1) a custom Boolean, isVerified, that the agent sets once the customer is verified, (2) context variables filled automatically from the Messaging Session, (3) create your own variable.
Kind Where it comes from Can the agent change it?
Context (legacy builder: $Context) Supplied by Salesforce, for example from the Messaging Session: channel, language, verified user No, read-only
Agent variable (Agent Script: @variables) Declared in the script with a type, such as boolean, string or number Yes when declared mutable; set by actions, logic or the LLM
Conversation / custom (legacy builder) Created in the Context panel Yes

Variables can also be set by an external system through the Agent API when it starts a session, for example to pass a customer ID from your website.

Applying agent filters

A filter is a checkpointDETERMINISTIC LOGICA filter is a checkpoint1A variableFor example is_verified.2A conditionavailable when @variables.is_verified == True3On a tool or transitionHidden until the condition is true.4Condition metOnly then can the agent use it.
Filters in the agent script: (1) the verification subagent is available only while isVerified is False, (2) case, account and reservation subagents become available only once isVerified is True.
Filters in the agent script: (1) the verification subagent is available only while isVerified is False, (2) case, account and reservation subagents become available only once isVerified is True.

A filter is a checkpoint. If its condition is false, the agent can’t use the subagent or action at all, whatever the user says.

  • In Agent Script, write it as available when @variables.is_verified == True on the tool or transition.
  • In the legacy builder, build it from a variable, an operator and a value, and attach it to a topic or action.
  • Typical uses: identity verification, eligibility, channel- or role-specific actions.

Template expressions

Exact values in the promptDETERMINISTIC LOGICExact values in the promptWithout“Greet the customer byname”The LLM must recall thenameCan be wrong or missingWith a templateexpression“Greet{!@variables.first_name}”The stored value isinsertedAlways the right name

A template expression places a value into text at run time. In Agent Script, {!@variables.first_name} inside a prompt line inserts the stored name exactly. The LLM sees the value; it doesn’t have to guess or remember it.

If the question says the agent must use an exact value (an order number, a tier, a verified name), store it in a variable and insert it with a template expression.

Before you move on

  • Variables remove reliance on LLM memory.
  • Context variables are read-only and come from the session.
  • Filters (available when) hide subagents and actions until a condition is true.
  • Template expressions put exact values into prompts.

Next: Reasoning Engine

Go to the next lesson →