Reuse variables across topics
By default, a variable's value can only be used in the topic where that variable is created. For example, if you create a variable UserCity in a Check Weather topic, you can only include it in items like message nodes within the Check Weather topic. These are referred to as Topic (limited scope) variables. However, there might be scenarios when you want to use the same value across multiple topics. Agents can remember a variable's context when conversations span multiple topics. For example, a Welcome topic could ask for the customer's name and email. When the conversation goes to another topic, such as an Appointment booking topic, you might want the agent to remember the customer's name and email address. In Microsoft Copilot Studio, these variables are referred to as Global variables. They can be accessed by any topic in the agent.
Global variables only apply during the current chat session. They can't be carried over from one customer chat session to another. You can specify which variables should be treated as global variables to distinguish them from topic-level variables.
Create a global variable
To define a variable as global, select the variable directly from a node or in the Variables menu within the top menu bar. Typically you would navigate to the Question node that first references the variable you want to work with.
In the Variable properties pane, under Usage, select Global (any topic can access). The variable name gets a prefix string of Global to differentiate it from the topic-level variables.
For example, the variable UserName is now shown as Global.UserName. When you convert a topic variable to a global variable, make sure that the variable name is unique across all topics. If a name conflict is encountered, you need to rename the variable before saving your change.
For more information, see Use global variables across topics within an agent.
Set global variables
Once a global variable is created, it's available to all topics. While working with a message or question node, select the {x} button and navigate to the Custom tab. This displays a list of all the variables available in the current topic. Variables are sorted in alphabetical order and grouped by their Usage type, i.e. Global and Topic.
When you use a condition node, a flow action node, or a skill node, you can also see global variables available there.
Manage global variables
When you create a global variable for use across multiple topics, it's essential to understand where it is applied. You can easily locate where the variable was initially defined by checking Reference and identify other topics that use it by selecting View all references. This feature is especially helpful when developing a new agent or managing multiple variables within complex topic branches.
The References section provides two main options:
Reference: Shows where the variable is currently defined.
View All References: Lists all topics and nodes where the variable is used, allowing you to navigate directly to each referenced topic and node.
Set a global variable's value from external sources
You can set a global variable to be initialized with an external source. This lets the agent start the conversation with some context.
For example, a customer brings up a chat from your website. If the user is logged in to your website, you already know the customer's name. By passing that information to the agent before starting the conversation, it can have a more intelligent conversation with the customer without having to ask for their name again.
You can specify that a variable can get its values from an external source. Open the Variable properties pane, and in the Usage section, select the External sources can set values box.
For more information on working with global variables, see Reuse variables across topics.