Reuse variables across topics

Completed

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 context when a conversation spans 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 agent variables. They can be accessed by any topic in the agent.

Agent variables 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 agent variables to distinguish them from topic-level variables.

Create an agent variable

To define a variable as an agent variable, open it in the authoring canvas. Open the Ask a question node that stores the variable that you want to work with. On the Variable Properties pane, under Usage, select Global (any topic can access). The variable name gets a prefix string of agent to differentiate it from the topic-level variables.

Screenshot of the agent variable properties.

For example, the variable UserName is now shown as Global.UserName. When you convert a variable to an agent 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 agent variables

Once an agent variable is created, it's available to all topics. While working with a message or question node, select the {x} button. This displays a list of all the variables available in this topic. Variables are sorted in alphabetical order, so all agent variables are grouped together in the variable menu because they all begin with agent.

Screenshot of the agent variable settings.

When you use a condition node, a flow action node, or a skill node, you can also see agent variables available there.

Manage agent variables

After you create an agent variable to use across multiple topics, you should understand where it's being used. You can easily see where the variable was first defined (Source) and the other topics that are using it. This can be useful if you're working on a new agent, or if you have multiple variables and complex topic branching.

There are two primary items that are available from the Variable Properties pane.

  • Reference: Goes to the node where the variable was initially created.

  • Used by: Displays all topics where the variable is used, so you can go straight to that topic and node.

Screenshot of the source and used by details for the agent variables.

Set an agent variable's value from external sources

You can set an agent 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 into 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.

Screenshot of the external sources can set values setting.

For more information on working with agent variables, see Reuse variables across topics.