Add global variable

From microsoft/skills-for-copilot-studio · View interactive version

Add global variable is an AI agent skill from the GitHub repository microsoft/skills-for-copilot-studio. Add a global variable to a Copilot Studio agent. Use when the user needs a variable that persists across topics in the same conversation and can optionally be visible to the AI orchestrator.

How to use this skill

Skill file

Add Global Variable

Create a global variable that persists across all topics within a conversation.

Instructions

  1. Auto-discover the agent directory:

```

Glob: **/agent.mcs.yml

```

Use the top-level agent. NEVER hardcode an agent name.

  1. Read settings.mcs.yml to get the schemaName prefix:

```

Read: <agent-dir>/settings.mcs.yml

```

Extract the root-level schemaName value (e.g., copilots_header_cre3c_fullagent).

  1. Determine from the user:
  1. Create the variable file at <agent-dir>/variables/<VariableName>.mcs.yml:
# Name: <Human-readable Name>
# <Description>
name: <VariableName>
aIVisibility: <UseInAIContext or HideFromAIContext>
scope: Conversation
description: <Description of what the variable stores>
schemaName: <prefix>.globalvariable.<VariableName>
kind: GlobalVariableComponent
defaultValue: <DEFAULT or specific value>
  1. Key fields explained:

How Topics Use Global Variables

Topics reference global variables with the Global. prefix:

# Reading a global variable in a condition
- kind: ConditionGroup
  id: conditionGroup_Xk9mPq
  conditions:
    - id: conditionItem_Lw3nRs
      condition: =!IsBlank(Global.LastDiscussedCity)
      actions:
        - kind: SendActivity
          id: sendMessage_Yt7vBw
          activity:
            text:
              - "Last time we discussed {Global.LastDiscussedCity}."

# Setting a global variable from a topic
- kind: SetTextVariable
  id: setTextVariable_Qp4kMn
  variable: Global.LastDiscussedCity
  value: =Topic.CityName

When to Use Global Variables

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.