---
schema_version: "1"
id: 004f5c9a93153f18f46e896fcedcb2eeaf797ed06cb37e5ff86f47634000bca7
title: Use Context Variables in Messaging Conversations
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/ai/264-0-0/service_agent_context_variables.md
canonical_url: https://help.salesforce.com/s/articleView?id=ai.service_agent_context_variables.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 3e413b93f296bd7ad55906f7a431d4841f0d3a85bb87d0230489df0f116466af
description: Personalize agent conversations over messaging channels with context variables. Context variables let your agent use Messaging Session record fields as action inputs.
products:
  - Agentforce
  - Cross Cloud
release: "264"
---
# Use Context Variables in Messaging Conversations

Personalize agent conversations over messaging channels with context variables. Context variables let your agent use Messaging Session record fields as action inputs.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition">
        <colgroup>
          <col>
        </colgroup>
        <tbody>
          <tr class="">
            <td class="slds-cell-wrap" style="vertical-align:top;">Available in: Lightning Experience</td>

          </tr>
          <tr class="">
            <td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>Enterprise</strong>, <strong>Performance</strong>, <strong>Unlimited</strong>, and
              <strong>Developer</strong> Editions. <a href="https://help.salesforce.com/s/articleView?id=ai.agent_setup_explore_types.htm&amp;release=264.0.0&amp;type=5" title="Learn about agent types and default templates for specific clouds and common use cases.">Required
                add-on licenses vary by agent type.</a>
            </td>

          </tr>
          <tr class="">
            <td class="slds-cell-wrap" style="vertical-align:top;">
              <p><span style="vertical-align:text-bottom;display:inline-block;"><img style="margin-bottom:0;" src="https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ai-generative_ai-264-0-0-production-enus/f8ef6498-d7b2-44e3-9b34-ffd5a850aae9/resources-global/_corporate/images/checkmark.png" alt="Check mark"></span>This article applies to: Agentforce Service agents and Agentforce Employee
                agents</p>
              <p style="margin-bottom:0;">To learn about channel support for other agent types, see the documentation for
                that type.</p>
            </td>

          </tr>
        </tbody>
      </table> <table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="text-align:center;vertical-align:top;" id="d136903e95">User Permissions Needed</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d136903e98">&nbsp;</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d136903e95 ">To build and manage Service agents:</td>

            <td data-label="" class="slds-cell-wrap" style="vertical-align:top;" headers="d136903e98 ">
              <p>Manage Agentforce Service Agents AND Manage AI Agents</p>
              <p>OR</p>
              <p style="margin-bottom:0;">Customize Application</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d136903e95 ">To build and manage Employee agents:</td>

            <td data-label="" class="slds-cell-wrap" style="vertical-align:top;" headers="d136903e98 ">
              <p>Manage AI Agents and Manage Agentforce Employee Agents</p>
              <p dir="ltr">OR</p>
              <p style="margin-bottom:0;" dir="ltr">Customize Application</p>
            </td>

          </tr>
        </tbody>
      </table>

Before you begin:

- [Connect a Service agent to a Messaging channel](https://help.salesforce.com/s/articleView?id=ai.service_agent_messaging.htm&release=264.0.0&type=5 "Route conversations to a service agent with enhanced messaging channels, including Bring Your Own Channel (BYOC).").
- [Deactivate your agent](https://help.salesforce.com/s/articleView?id=ai.copilot_setup_activate_deactivate.htm&release=264.0.0&type=5 "Activate your agent to make it available to your customers or employees. When an agent is deployed to one or more channels, including the Agentforce panel, activating the agent makes it immediately available to your users.").

By default, Service agents include a Messaging Session variable that’s mapped to a MessagingSession record. Agents can use the information stored in the Messaging Session ID, Messaging User ID, and other included fields. They can also update the Messaging Session record as they chat with customers.

Context variables let you map Messaging Session object fields to messaging channels. For example, to save your agent from having to ask for common information conversationally, you can configure your agent to reference any Messaging Session object field, including the ones populated via a pre-chat form. This data can even be used as an input for actions. We don't recommend using context variables for authentication.

You can’t test context variable use cases in Agentforce Builder because context variables require a Messaging Session record. To test context variables, chat with your agent on a connected channel.

1. [Add context variables to your agent in Agentforce Builder](https://help.salesforce.com/s/articleView?id=ai.agent_builder_variables_create.htm&release=264.0.0&type=5 "Use variables to store and reuse values in your agent’s reasoning and control how an agent makes decisions. For example, when you assign a variable to an action input, your agent can use only the assigned variable to fill the value of the input."). To make more Messaging Session fields available as context variables, [add custom fields to the Messaging Session object](https://help.salesforce.com/s/articleView?id=platform.adding_fields.htm&type=5&language=en_US)
2. To use a context variable field during agent conversations, add the field API name to instructions and use the fields in action inputs.

#### See Also

- [_Object Reference:_ Messaging Session](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_messagingsession.htm)