15.3 Create and Use Environment Variables

Key Takeaways

  • Environment variables separate environment-specific values (URLs, keys, flags, data sources) from agent logic so the same solution can move across Dev, Test, and Prod.
  • In Copilot Studio, environment variables are read-only for makers; create and change values in Power Apps / solution experiences, then republish agents when non-secret values change.
  • Pair environment variables with connection references: connections hold credentials; environment variables hold parameters those connections and agents consume.
  • Include environment variables in the agent solution via Add existing or Add required objects; keep them in the same solution as the agent when features depend on them at deploy time.
  • Secret-type variables are retrieved at runtime and do not require republish on value change; other types bake published values until you republish.
Last updated: August 2026

Configuration that travels with ALM—not hard-coded values

When the same agent solution is promoted from Development to Test to Production, most logic should stay identical. What changes is where systems live: SharePoint site URLs, API base addresses, feature flags, Dataverse environment-specific parameters, and sometimes human-readable labels. Environment variables store those parameters as first-class solution components so you do not hard-code https://dev-api.contoso.com inside topics and then forget to change it in production.

AB-620 skill create and use environment variables sits beside solutions and pipelines: solutions move definitions; environment variables supply per-environment values; pipelines can prompt for or apply those values during deployment.

Four variable scopes—only one is ALM configuration

Copilot Studio makers use several variable families. Do not confuse them on the exam:

ScopeWho sets itPurpose
Topic variablesTopic authorTemporary values inside one topic
Global variablesAgent authorValues shared across topics in a conversation
System variablesPlatformConversation, user, channel, bot metadata
Environment variablesPower Platform admin/maker in solutionALM parameters shared by apps, flows, and agents

Environment variables are Power Platform concepts. Agents consume them like other variables in conditions, messages, and flow inputs, but authors cannot edit their values inside Copilot Studio. The Variables panel shows information and links to Power Apps for authoring. That read-only boundary is a frequent exam discriminator.

Types you should recognize

Environment variable types in Copilot Studio map to Power Apps types roughly as follows:

Copilot Studio viewPower Apps typeTypical agent use
TextStringAPI base URL, site path, display suffix, tenant label
Decimal numberNumberThresholds, limits
Yes/NoBooleanFeature flags (enable experimental tool)
JSONJSON / detectedStructured config blobs
Data sourceString-like data source parameterParameters for connector actions
SecretString (secret)Keys retrieved carefully at runtime

Connection references are related but not identical. A connection is the authenticated credential to a connector. A connection reference is the solution-aware pointer that apps/flows/agents use so each environment can bind its own connection. Data source environment variables often store parameters actions need (for example a SharePoint site), while the connection supplies who is calling. Exam stems that mention “wrong SharePoint site after import” usually want environment variables (or data source parameters), not rewriting the whole topic.

Create and package environment variables

Recommended workflow:

  1. In the same unmanaged solution as the agent, Add existingMoreEnvironment variable, or create new environment variables in the solution from Power Apps / solution explorer.
  2. Define schema name, display name, type, optional default value, and documentation for makers.
  3. For secrets, use secret type and store values in the secure store patterns Power Platform supports—never paste production keys into topic messages or knowledge documents.
  4. Reference the variable from topics, agent flows, HTTP actions, generative answer configuration, or channel settings that accept environment variables.
  5. Before export, Add required objects so dependencies include the variables.
  6. On import or pipeline deploy, set current values for the target environment.

If a feature requires the variable to exist in the target (for example channel display name suffix), Microsoft guidance stresses keeping the variable in the same solution as the agent. Variables that only exist in other solutions may appear in pickers in Dev but fail after deploy.

Using environment variables in agents and flows

In topics, pick environment variables from the variable browser similarly to globals—except you will not assign new values mid-conversation. Common patterns:

  • Build an HTTP URL: concatenate env var base URL + path.
  • Pass site ID or list name into a SharePoint/Power Platform connector action.
  • Toggle a branch: if EnableReturnsTool is false, skip a tool topic.
  • Supply a Teams / Microsoft 365 Copilot channel display name suffix so users see (Development) or (Test) while production stays clean.

In agent flows, environment variables keep flow actions portable: the flow definition is solution-aware; the URL or data source parameter changes per environment without editing the flow graph after every promote.

Publish rules (critical)

When an agent is published, it captures the environment variable values in effect for most types. If an administrator later changes a non-secret environment variable value, you must republish agents that depend on it for runtime to pick up the change. Secret environment variables are different: they are retrieved at runtime, so updating the secret does not require republish.

ChangeRepublish agent?
Text / number / boolean / JSON current value changedYes (typical)
Secret value rotatedNo (runtime retrieval)
Topic logic changedYes (normal publish)
Only connection re-authenticatedConnection binding; still validate agent behavior

Connection references + environment variables together

A robust agent package usually includes both:

  1. Connection references for ServiceNow, Dataverse, SharePoint, custom connectors, etc.
  2. Environment variables for site collections, API hosts, environment labels, optional secrets.

During Power Platform Pipelines deployment, makers or admins are prompted to supply connections and environment variable values up front so the deployment does not land half-configured. That pre-validation is a major reason pipelines beat manual zip import for teams.

Scenario — Contoso order-status agent

Contoso’s order agent calls https://orders-dev.contoso.com in Dev and https://orders.contoso.com in production. The team creates string environment variable ctso_OrdersApiBaseUrl with Dev default, references it from a REST/HTTP tool and an agent flow, and includes it in CTSO Order Agents solution. Pipeline deploy to Test sets the Test URL; production deploy sets the production URL. No topic edit is required between environments. A separate secret variable holds a non-user key for a backend if delegated auth is not used; rotating that secret does not force republish, but changing the base URL does.

Troubleshooting environment variables

ProblemCheck
Variable missing in Copilot StudioNot in solution / not created; open Variables panel; confirm type support
Errors in test chat after admin changeRepublish after non-secret value change
Import OK but wrong site dataCurrent value still points at Dev; update env var in target
Suffix not applied on Teams channelEnv var not in same solution; wrong type (must be String for documented suffix feature); blank production value intentional
Flow works in Dev onlyFlow missing required objects or connection reference rebound incorrectly

Environment variable validation errors can appear in test chat and publish, but they may not show as ordinary topic errors in the topic list because they are not topic variables.

Anti-patterns

  • Hard-coding production URLs in instructions “just for now.”
  • Storing passwords in knowledge files or adaptive card payloads.
  • Creating env vars only in Default solution while the agent lives elsewhere.
  • Expecting makers to edit env vars inside Copilot Studio topic nodes as if they were globals.
  • Forgetting that pipelines and import wizards are the right moment to set target values—not a week after users report wrong data.

AB-620 takeaway

Environment variables make agent solutions environment-agnostic. Create typed variables in the agent’s solution, consume them as read-only configuration in Copilot Studio, pair them with connection references, set values per environment during deploy, and republish when non-secret values change. That is the configuration half of ALM; pipelines are the automation half.

Test Your Knowledge

How do environment variables behave for makers working inside Microsoft Copilot Studio?

A
B
C
D
Test Your Knowledge

An administrator updates a non-secret string environment variable that a published agent uses for its API base URL. What is required for the running agent to use the new value?

A
B
C
D
Test Your Knowledge

Which packaging approach best supports promoting an agent that must call different SharePoint sites in Dev and Prod?

A
B
C
D