# Deterministic control with variables, filters and expressions

*Agentforce Specialist Study Guide · AI Agents · Last updated November 6, 2026 · https://www.certifyforce.com/study-guide/agentforce-specialist/ai-agents/deterministic-control-with-variables-filters-and-expressions*

How custom, context and system variables hold agent state, why gate variables default closed and must be set by code, how available-when filters hide actions and subagents, and how conditionals, template expressions and transitions enforce a workflow without action loops.

- Certification: Salesforce Agentforce Specialist
- Exam section: AI Agents
- Study guide: https://www.certifyforce.com/study-guide/agentforce-specialist

**Official exam objective:**

> Given a use case, manage deterministic behavior for the agent using mechanisms like filters, variables, and template expressions.

## What the exam expects

- Choose the variable type (custom, context or system) for a piece of agent state, and decide who may set it.
- Give gate variables a fail-closed default and a deterministic code path that sets them.
- Use filters (available when) to hide actions and subagents until conditions hold, and know when a conditional transition is needed instead.
- Write conditional expressions, guard clauses and template expressions so exact values reach the customer.
- Enforce deterministic transitions and stop action loops.
- Key terms: **custom variable** (agent-defined state; `mutable` permits changes); **context variable** (linked to an object field such as a Messaging Session field); **filter** (an `available when` condition that hides a subagent or action); **guard clause** (an unconditional precondition check in script); **template expression** (`{!...}` that resolves a value inside prompt text).

## Key facts

| Fact | Detail | Source |
|---|---|---|
| Variable scope | Defined in the variables block; every subagent can access them | [Variables Reference](https://developer.salesforce.com/docs/ai/agentforce/guide/ascript-ref-variables.html) |
| Linked (context) variables | Can't have a default, can't be set by the agent, can't be an object or list | [Variables Reference](https://developer.salesforce.com/docs/ai/agentforce/guide/ascript-ref-variables.html) |
| Visibility | Custom variables default to Internal; External lets the Agent API set them | [Variables Reference](https://developer.salesforce.com/docs/ai/agentforce/guide/ascript-ref-variables.html) |
| System variables | Predefined and read-only, such as user_input (the most recent utterance) and current_modality | [System Variables](https://developer.salesforce.com/docs/ai/agentforce/guide/ascript-ref-variables-system.html) |
| Reference syntax | `@variables.x` in logic; `{!@variables.x}` in prompt text | [Create Variables](https://help.salesforce.com/s/articleView?id=ai.agent_builder_variables_create.htm&language=en_US&type=5) |
| False values close a filter | None, False, 0 or an empty string suppress the action | [Hybrid Reasoning](https://architect.salesforce.com/docs/architect/fundamentals/guide/hybrid-reasoning-agentforce-builder-agent-script) |
| Gate default | Initialise gate booleans to False so the gate starts closed | [Hybrid Reasoning](https://architect.salesforce.com/docs/architect/fundamentals/guide/hybrid-reasoning-agentforce-builder-agent-script) |
| No auto-suppression | The platform doesn't suppress an action after it has been called | [Hybrid Reasoning](https://architect.salesforce.com/docs/architect/fundamentals/guide/hybrid-reasoning-agentforce-builder-agent-script) |
| `is None` vs `== ""` | `is None` checks an unassigned value; `== ""` checks an empty string | [Using Conditionals](https://developer.salesforce.com/docs/ai/agentforce/guide/ascript-patterns-conditionals.html) |
| Filters vs required flow | Filters remove options; a conditional transition guarantees the workflow | [Required Workflows](https://developer.salesforce.com/docs/ai/agentforce/guide/ascript-patterns-required-flow.html) |

## Check yourself

- Why is `_parcel__code_` an invalid Agent Script variable name?
- When will a number passed to `concat()` cause an error instead of being appended as text?
- What separator does `concat()` insert when its optional `sep` argument is omitted?

## Sources

- [Hybrid Reasoning with New Agentforce Builder and Agent Script](https://architect.salesforce.com/docs/architect/fundamentals/guide/hybrid-reasoning-agentforce-builder-agent-script)
- [Create Variables in Agentforce Builder](https://help.salesforce.com/s/articleView?id=ai.agent_builder_variables_create.htm&language=en_US&type=5)
- [Agent Script Reference: Variables](https://developer.salesforce.com/docs/ai/agentforce/guide/ascript-ref-variables.html)
- [Agent Script Pattern: Using Variables Effectively](https://developer.salesforce.com/docs/ai/agentforce/guide/ascript-patterns-variables.html)
- [Agent Script Pattern: Enforce Business Rules with Filters](https://developer.salesforce.com/docs/ai/agentforce/guide/ascript-patterns-filtering.html)
- [Agent Script Pattern: Enforce Required Workflows for a Subagent](https://developer.salesforce.com/docs/ai/agentforce/guide/ascript-patterns-required-flow.html)
- [Agent Script Pattern: Using Conditionals](https://developer.salesforce.com/docs/ai/agentforce/guide/ascript-patterns-conditionals.html)
- [Agent Script Reference](https://developer.salesforce.com/docs/ai/agentforce/guide/ascript-reference.html)
- [Building Agents in Canvas View](https://help.salesforce.com/s/articleView?id=ai.agent_canvas.htm&language=en_US&type=5)
- [Agent Script](https://developer.salesforce.com/docs/ai/agentforce/guide/agent-script.html)
- [Agent Script Pattern: Subagent Transitions](https://developer.salesforce.com/docs/ai/agentforce/guide/ascript-patterns-transitions.html)
- [Agent Script Reference: System Variables](https://developer.salesforce.com/docs/ai/agentforce/guide/ascript-ref-variables-system.html)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit and reading progress are included in the full study guide. The separate practice exams option includes the reviewed question bank and timed mock exams. The bundle includes both where available. See [current options and prices](https://www.certifyforce.com/pricing).
