Section 4 · AI Agents · 35% of exam
4.5 Filters, Variables, and Template Expressions
Exam objective
Explain how variables, filters, and expressions can make agent behavior more controlled, context-aware, and consistent.
Variables store usable context
Variables store values an agent can reuse in reasoning and interactions. A value might represent whether a customer has been verified, which product they selected, or an output returned by an action. Variables can be referenced in instructions, expressions, action inputs, and filter conditions. This is safer and more consistent than asking a language model to reconstruct a value from a long conversation every time. In current Agentforce Builder, variables can be created in the Variables page, and an action output can be mapped to a variable. Some context values are read-only or have restrictions on when they can be set, so check the current variable definition and API behavior before designing around it.
Filters limit availability
A filter makes a topic or subagent or action available only when specified conditions are met. A condition typically compares a variable with a value using an operator. Multiple conditions can be configured to require all conditions or any condition, depending on the intended logic. For example, a verified-customer variable can control access to a refund action. A filter affects whether the agent can use that asset; it is not merely a suggestion to the model. Apply filters to the correct subagent or action, and make sure the variables have trustworthy values before the decision is made.
Expressions and resource references
Agent Script uses expressions to compare values, set variables, and control transitions. Salesforce documents a variable reference format for instructions, {!@variables.VariableName}, and for logical expressions, @variables.VariableName. These references allow instructions and conditions to use the current value rather than hard-coded text. The variable must exist and be set at the right time. Check spelling, value type, null behavior, and whether the expression is evaluated before or after an action. Template expressions can make instructions context-aware, but they do not validate that the source value is accurate or authorized.
Design a controlled path
Suppose an agent can submit a replacement order only after checking eligibility. A lookup action returns order status and purchase date. Map reliable action outputs to variables, calculate or evaluate eligibility with deterministic logic, and add a filter so the replacement action is available only when the eligibility condition is true. If details are missing, ask for them or run a permitted lookup. If the user is not authenticated, route to verification rather than exposing an action. Test each state: verified and eligible, verified but ineligible, unverified, missing order, and action failure. This verifies the whole dependency chain rather than only the filter formula.
TIP: When a filter does not behave as expected, check the variable’s source and timing first, then inspect the condition, operator, value type, and asset where the filter is applied.
Filters restrict agent access to configured assets; Salesforce sharing, object permissions, field-level security, and action-level authorization remain separate controls.
Extra concept: A variable mapped directly from an action output is usually more dependable for a gating decision than a value inferred from ambiguous prose.
Official references:
- Create Variables in Agentforce Builder https://help.salesforce.com/s/articleView?id=ai.agent_builder_variables_create.htm&language=en_US&type=5
- Variables https://help.salesforce.com/s/articleView?id=ai.agent_parent_variables.htm&language=en_US&type=5
- Create a Filter to Control Access to Subagents and Actions in the Legacy Builder https://help.salesforce.com/s/articleView?id=ai.agent_asset_filters.htm&language=en_US&type=5
Key takeaways
- Variables store and reuse values across instructions, filters, expressions, and action inputs.
- Filters make an asset available only when its configured conditions are met.
- Validate the data source and timing for variables that control sensitive actions.
