Context Variables in Agentforce: Source, Security, and Practical Usage
Context variables in Agentforce are one of the main reasons an enterprise agent behaves like a controlled business system instead of just a text generator. Conversation variables are useful as short-term memory inside a chat, but context
variables represent the agent’s official execution environment. They carry structured values provided by the platform and the channel, and they help the agent make decisions and respond safely without guessing.
When an Agentforce agent is connected to customer messaging channels, it automatically has access to context variables. These variables are mapped from fields on the Messaging Session object. This includes not only standard fields, but
also custom fields you add to Messaging Session in your organization. In practical terms, that means your business can extend the session object with your own data, and the agent can receive that data as part of its context without extra manual input from
the user.
A key property of context variables is that they are read-only. The agent can use them, but it cannot change them. This is important because read-only data acts as a trusted source of truth. The values are either present because the system
provided them, or they are not present at all. The agent cannot rewrite reality or accidentally overwrite critical information. In Agentforce, context variables are identified by the prefix dollar sign Context, which makes it clear they come from the
system context rather than from temporary chat memory.
A simple and very useful example is the variable EndUserLanguage. This variable represents the user’s language as provided through the session context. Instead of asking the user which language they prefer, the agent can immediately
respond in the correct language from the first message. This improves the customer experience, reduces unnecessary questions, and speeds up resolution because the agent starts in the right mode right away.
This leads to the first big purpose of context variables, which is personalization without interrogation. Users do not want to repeat obvious information, and businesses do not want to waste time gathering data that already exists in the
system. Context variables allow the agent to behave as if it already understands the situation. It can choose language, tone, formatting, and even the right service style based on reliable session signals.
The second purpose is even more critical, which is security and governance. Context variables help the agent behave safely because they provide system-level facts that do not depend on what the user claims. A user can type anything in a
chat, but the session context remains stable. That reduces the risk of manipulation, social engineering, and accidental policy violations. It also supports deterministic control, because context variables are commonly used as conditions for filters that
restrict which topics and actions are available. When access is constrained by trusted context, the agent cannot perform a forbidden operation even if the user asks directly and even if the language model might otherwise attempt it.
To use context variables correctly, it helps to follow a simple rule about when to choose context variables versus conversation variables. Use context variables when the value already exists in the platform or the channel, when it must be
treated as reliable and authoritative, and when the agent must not be allowed to change it. This includes Messaging Session data, including your custom fields, as well as user and session attributes such as language, routing indicators, or access-related
signals. Use conversation variables when the value is discovered during the current dialogue, when it is a temporary preference or intermediate step, and when it only needs to live until the session ends. Conversation variables are ideal for short-lived
decisions, clarifications, and working state inside a single interaction.
A useful way to remember the difference is this. Context variables represent what the system already knows and what you can trust. Conversation variables represent what you learned during the chat and what is only relevant right now.
The next step is turning this into practice inside your agent design. In the next article, we will look at the syntax for inserting variables into instructions, including the format used to reference dollar sign Context values, and the
patterns that make agent behavior consistent and predictable without making the configuration complicated.