Configure context variables for agents

Important

Power Virtual Agents capabilities and features are now part of Microsoft Copilot Studio following significant investments in generative AI and enhanced integrations across Microsoft Copilot.

Some articles and screenshots might refer to Power Virtual Agents while we update documentation and training content.

Note

Copilot Studio bot is being renamed as Copilot agent (agent). Human agent is now renamed as customer service representative (service representative or representative). You'll come across references to the old and new terms while we update the product UI, documentation, and training content.

Applies to: Dynamics 365 Contact Center—standalone and Dynamics 365 Customer Service only

This article lists the context variables for Azure and Copilot Studio agents, and how you can configure them in Omnichannel for Customer Service. To understand how to create context variables, see Manage context variables.

Context variables for Azure agents

The following table contains the list of context variables in Omnichannel for Customer Service that you can use for configuring Azure agents.

Context variable type Context variable name Description How to map in Azure
Pre-conversation survey Use the pre-conversation survey question name that you create in Omnichannel for Customer Service. The system stores responses from the pre-conversation survey as context variables. Use the following information to map the question name in Omnichannel for Customer Service with the variable type in Azure:
  • Single line: String
  • Multiple lines: String
  • Option set: String
  • User Consent: Boolean
Custom context Use the variable name that you create in Omnichannel for Customer Service or pass using the setContextProvider API. The custom context variables that you create can be passed through the live chat SDK. Map the user's response as a JSON to use custom context variable in Omnichannel for Customer Service.
Conversation msdyn_ConversationId Use the context variable that contains the conversation ID for the ongoing conversation and can fetch and perform operations on the record in Microsoft Dataverse. String: String
Contact msdyn_contact_msdyn_ocliveworkitem_Customer Use this context variable that contains the record ID for the customer (contact) record that is linked to the conversation. Parse JSON to extract record ID
Account msdyn_account_msdyn_ocliveworkitem_Customer Use this context variable that contains the record ID for the account record linked to the conversation. Parse JSON to extract record ID
Case msdyn_incident_msdyn_ocliveworkitem Use this context variable that contains the record ID for the case record linked to the conversation. Parse JSON to extract record ID

Note

Use the context variable names as defined and don't change them when you author flows in Azure or Copilot Studio agents. Also, be sure to use exact match to pass the value to the context variable because it is case-sensitive. If there's a mismatch, the record won't get automatically identified. More information: Identify records automatically

Context variables for Copilot Studio agents

The following table contains the list of context variables available in Omnichannel for Customer Service that you can use for configuring Copilot Studio agents.

Important

To use the messaging and voice variables, ensure that you first install the extension solutions.

Context variable type Context variable name Description How to map in Copilot Studio
Pre-conversation survey Use the pre-conversation survey question name that you create in Omnichannel for Customer Service. The system stores responses from the pre-conversation survey as context variables. Use the following information to map the question name in Omnichannel for Customer Service with the variable type in Copilot Studio:
  • Single line: User’s entire response
  • Multiple lines: User's entire response
  • Option set: User's entire response
  • User Consent: Boolean
Custom context Use the variable name that you create in Omnichannel for Customer Service or pass using the setContextProvider API. The custom context variables that you create can be passed through the live chat SDK. Use the following information to map the custom context variable in Omnichannel for Customer Service with the variable type in Copilot Studio:
  • String: User's entire response
  • Boolean: Boolean
  • Number, Floating Number: Number
Conversation msdyn_ConversationId Use the context variable that contains the conversation ID for the ongoing conversation and can fetch and perform operations on the record in Microsoft Dataverse. String: User's entire response.
Messaging-only variables msdyn_CustomerType Use this context variable that contains the customer type for the account or contact record linked to the conversation. Select the Omnichannel for Customer Service extension solution variable.
msdyn_CustomerName Use this context variable that contains the customer name for the account or contact record linked to the conversation. Select the Omnichannel for Customer Service extension solution variable.
msdyn_CustomerId Use this context variable that contains the customer ID for the account or contact record linked to the conversation. Select the Omnichannel for Customer Service extension solution variable.
msdyn_CaseId Use this context variable that contains the ID of the case record linked to the conversation. Select the Omnichannel for Customer Service extension solution variable.
msdyn_CaseTitle Use this context variable that contains the title of the case record linked to the conversation. Select the Omnichannel for Customer Service extension solution variable.
Voice-only variables 1 CustomerPhoneNumber Use this context variable for the customer's phone number in the Telephony activity. Select the Omnichannel for Customer Service extension solution variable.
OrganizationPhoneNumber Use this context variable for the organization's phone number in the Telephony activity. Select the Omnichannel for Customer Service extension solution variable.
Extension method name va_SurveyConsent Use this dialog to determine if a customer has agreed to participate in surveys during the conversation. Use this method to escalate conversation details to Omnichannel for Customer Service.
va_CustomerLocale Use this dialog to transfer the user currently talking to the agent to another agent that can speak in a different language. Set the code by selecting the input variable and using the correct locale code.

1 To use other context variables for voice, you will need to get the values from Dataverse directly. Learn more in Configure a sample voice agent template.

Configure context variables for Copilot Studio agent

To have your Copilot Studio agent read context variables from Omnichannel, do the following steps:

  1. On the Topics page, select Add a topic and from blank.

  2. Enter a name for your topic (for example, "Set context variables") and save it.

  3. Add a new node to the topic, and select Variable management > Set a variable value

  4. In your new node, under Set variable select Create a new variable.

  5. Open the Variable properties pane by clicking the new variable name. In the pane, set the Variable name to match the Omnichannel context variable's name exactly (it's case sensitive).

  6. In the Reference section, select the ellipses (...) and select Get value from this node if empty. The Copilot Studio agent retrieves the variable value from this node at runtime.

  7. In the Usage section, select Global (any topic can access) and External sources can set values. Copilot Studio accepts data from Omnichannel. Close the Variable properties pane.

  8. In your node, enter a value in To value that matches the data type your agent expects. For example, if your agent expects a string, set Text(""). Copilot Studio falls back to the value that you set here if the data doesn't arrive in the conversation.

    Configure context variable in a topic.

  9. Save and publish the changes.

During a conversation, the data from the Omnichannel context variable is set in the Copilot Studio variables and can be used in the agent's logic.

The agent can also set Omnichannel context variables during a conversation. To set an Omnichannel variable from your Copilot Studio logic, make sure that your agent is using the correct variable name and set the value in the "To value" property in your variable management node. Copilot Studio hands off the variable to Omnichannel during transfer to a customer service representative. This is often used to link the conversation to a case when the agent escalates the conversation to a service representative. More information on how to link records in Omnichannel from this data: Link customer and case to a conversation

The global variables that are created in Copilot Studio can be passed to Omnichannel for Customer Service when a conversation is escalated. For the complete list, see Contextual variables available upon hand off.

Parse JSON object to extract record ID

Make sure that you have the following details:

  • The Omnichannel for Customer Service context variable, such as msdyn_contact_msdyn_ocliveworkitem_Customer.
  • The schema details

A copy of the sample schema details is as follows:

        Schema: 
        {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "RecordId": {
                        "type": "string"
                    },
                    "PrimaryDisplayValue": {
                        "type": "string"
                    }
                },
                "required": [
                    "RecordId",
                    "PrimaryDisplayValue"
                ]
            }
        }

PrimaryDisplayValue contains the value from the attribute in the Dataverse entities. The mapping for the entity attributes is as follows:

  • Cases: Case title
  • Contacts: Full name
  • Accounts: Name

Here's a sample context record.

{
    "msdyn_contact_msdyn_ocliveworkitem_Customer": [
        {
            "RecordId": "<GUID>",
            "PrimaryDisplayValue": "<FullName>"
        }
    ],
    "msdyn_liveworkitemid": "<GUID>"
}

Integrate a Copilot Studio agent
Integrate an Azure agent
Configure agents to escalate and end conversations
Live chat SDK reference