Using Variables in Agentforce: Passing Data Between Actions and Managing the Session 

Using Variables in Agentforce: Passing Data Between Actions and Managing the Session

In Agentforce, variables are not just convenient placeholders for context. In real implementations, they act as the data transport layer that connects actions into reliable sequences, helps the agent maintain continuity across a session, and makes behavior predictable and governable. Actions are the operations an agent can execute, such as calling a system, retrieving data, or completing a workflow step. Variables are the wiring that carries information from one action to the next, so the agent can behave like a process executor rather than a text-only assistant.

A key capability is assigning a variable as an action input. Every action has input parameters, and in Agentforce Builder you can configure each input parameter to take its value from a variable instead of trying to extract it from the user’s message every time. This is how you reduce ambiguity and increase determinism. The same state produces the same variable values, the same variable values produce the same action inputs, and the agent’s execution becomes consistent. This works whether the value comes from context variables provided by the platform, conversation variables collected during the current chat, or custom variables you define for your business process.

The next capability is mapping an action’s output into a variable. After an action runs, it often returns results such as a status, a flag, an identifier, or a piece of structured data. In Agentforce Builder, you can take that output value and map it directly into a variable through the output parameter configuration. This step is what turns “a one-time action result” into “persistent session state.” Once the output is stored in a variable, the agent can use it later without repeating the same action and without relying on the model to remember it implicitly.

This is where variables become more than memory. When an action output is mapped into a variable, that value can immediately drive governance and behavior. The variable can be referenced by filters to control which topics and actions are allowed next. It can also be referenced by instructions to shape how the agent responds going forward. For example, if an action returns a verification status, the agent can unlock or block sensitive actions based on that status. If an action returns a priority level, the agent can adopt a more confirmation-heavy and risk-aware style in subsequent messages. This is how action results become decision signals, not just text displayed to the user.

Variables also help you control the session from outside the conversation itself. In Agentforce, variables can be set at the start of a session, or when messages are sent through the Agent API. This means the agent can begin the conversation with the correct state already in place, without spending early messages collecting information the business already knows. It also means you can update variables as new external facts arrive, so the agent stays aligned with what is happening in the surrounding system, not just what the user has typed in the chat.

A simple mini-example shows the pattern clearly. Imagine an action called Capture Preferences. Its purpose is to determine what matters for the rest of the interaction, such as the user’s preferred language or communication style. The action runs, produces an output value for preferred language, and that output is mapped into a variable called PreferredLanguage. From that moment, the agent can use PreferredLanguage consistently. Instructions can reference it to ensure every response remains in the correct language. Other actions can take it as an input to generate localized templates or choose language-specific resources. Even if the user changes the topic mid-session, the agent does not lose the established preference because it is stored as structured state, not as a fragile assumption.

The overall result is a clean and repeatable design. Action inputs read from variables. Action outputs write into variables. Those variables then control what becomes available through filters and how the agent behaves through instructions. And because variables can be initialized or updated through the Agent API, you can manage the session proactively rather than reactively.

Now that variables give us structured state and reliable data flow, the next step is governance. This is where filters enter as the “door lock” for topics and actions. Variables describe what is true right now, and filters turn that truth into hard boundaries by controlling what the reasoning engine is allowed to choose.