Manage variables (AB-620 Exam Prep)

This post is a part of the AB-620: Designing and Building Integrated AI Agent Solutions in Copilot Studio Exam Prep Hub.
This topic falls under these sections:
Plan and configure agent solutions (30–35%)
   --> Configure topics
      --> Manage variables


Note that there are 10 practice questions (with answers) at the end of each section to help you solidify your knowledge of the material. Also, there are 4 practice tests with 30 questions each available from the hub's main page below the exam topics section.

Introduction

Variables are one of the most important concepts in Microsoft Copilot Studio. Nearly every conversational agent uses variables to remember information, make decisions, personalize responses, and exchange data with external systems.

Without variables, an agent would treat every interaction independently and would be unable to:

  • Remember a user’s name
  • Store selections from menus
  • Save outputs from connectors
  • Track conversation progress
  • Pass information between topics
  • Personalize responses
  • Send data to APIs
  • Process results from external systems

For the AB-620 exam, you should understand not only how to create variables, but also when to use different variable types, how variable scope works, and how variables interact with agent flows, topics, tools, and generative AI capabilities.


What Are Variables?

A variable is a named container that temporarily stores information while an agent is running.

Examples include:

  • Customer ID
  • Product number
  • Employee name
  • Order status
  • Current date
  • Selected department
  • API response
  • User’s preferred language

Instead of repeatedly asking the user for the same information, the agent stores the value in a variable.

Example:

User:

My name is Sarah.

The agent stores:

UserName = Sarah

Later:

Agent:

Welcome back Sarah.

The user only had to provide the information once.


Why Variables Matter

Variables enable agents to:

  • Remember information
  • Personalize conversations
  • Drive conditional logic
  • Control branching
  • Pass data to tools
  • Receive results from tools
  • Populate Adaptive Cards
  • Send API requests
  • Display API results
  • Maintain conversation state

Without variables:

  • Every question must be repeated
  • Personalization disappears
  • API integration becomes impossible
  • Automation cannot function

Variable Types in Copilot Studio

Several categories of variables exist.

1. Topic Variables

Topic variables exist only while a topic is executing.

Example:

OrderNumber

Used only inside:

Track Order Topic

When the topic ends, the variable is no longer available unless it is explicitly passed elsewhere.

Typical uses:

  • Temporary calculations
  • User responses
  • Branch decisions
  • Intermediate results

2. Global Variables

Global variables remain available throughout the entire conversation.

Example:

CustomerName

Captured once:

"What is your name?"

Available later in any topic.

Example:

Welcome back John.

Global variables are ideal for:

  • Customer information
  • Language preferences
  • Account type
  • Authentication status
  • User profile information

3. System Variables

System variables are automatically maintained by Copilot Studio.

Examples include information such as:

  • Conversation identifiers
  • Channel information
  • Locale
  • User context
  • Current activity metadata

These variables are generally read-only and provide information about the current conversation or environment.

Common uses include:

  • Detecting the communication channel
  • Language detection
  • Auditing
  • Logging
  • Conditional behavior

4. Custom Variables

Developers create custom variables whenever business-specific data must be stored.

Examples:

ReservationDate
PreferredHotel
CurrentDepartment
ShippingMethod

These represent business information unique to the application.


5. Environment Variables

Environment variables store configuration rather than conversation data.

Examples:

API URL
Database Name
Service Endpoint
Tenant ID

Benefits include:

  • Easier deployment
  • Different settings for Development/Test/Production
  • No hardcoded URLs
  • Easier maintenance

Creating Variables

Variables are commonly created automatically when:

  • Asking a question
  • Capturing user input
  • Calling a connector
  • Receiving API results
  • Executing Power Automate flows
  • Running prompts
  • Using generative nodes

Example:

Question:

Enter your employee number.

Save response as:

EmployeeID

The variable is automatically populated.


Initializing Variables

Sometimes a variable needs an initial value before it is used.

Examples:

RetryCount = 0
TotalCost = 0
ApprovalStatus = Pending

Initialization helps avoid errors caused by empty or undefined values.


Variable Scope

Scope determines where a variable can be accessed.

Two variables may have identical names but exist in different scopes.

Example:

Topic Variable:

OrderID

Available only within:

Track Order Topic

Global Variable:

CustomerName

Available everywhere.

Understanding scope is essential because it prevents accidental overwriting and ensures the correct data is available where needed.


Variable Lifetime

Variable lifetime refers to how long the variable exists.

Typical lifetimes include:

Temporary

Exists only during a single topic.

Example:

SelectedProduct

Conversation Lifetime

Exists throughout the conversation.

Example:

CustomerName

Persistent Configuration

Exists independently of conversations.

Example:

Environment Variable

Using Variables in Questions

A common workflow is:

Ask Question

Store Response

Use Variable

Example:

Agent:

What city are you visiting?

Store:

DestinationCity

Later:

Hotels in {DestinationCity}

This creates a personalized interaction.


Using Variables in Messages

Variables can personalize responses.

Example:

Instead of:

Welcome.

Use:

Welcome back {CustomerName}

Instead of:

Your order is ready.

Use:

Order {OrderNumber} is ready.

This significantly improves the user experience.


Variables in Conditions

Variables frequently control branching logic.

Example:

If MembershipLevel = Gold

Offer Premium Support

Else

Standard Support

Almost every decision node relies on variable values.


Passing Variables Between Topics

Large agents often contain multiple topics.

Example:

Authentication Topic

Stores

EmployeeID

Calls:

Benefits Topic

Instead of asking again, the EmployeeID variable is passed to the next topic.

Benefits include:

  • Better user experience
  • Less repetitive questioning
  • Consistent conversation flow
  • Faster interactions

Variables and Agent Flows

Agent flows frequently use variables as both inputs and outputs.

Example:

Input:

CustomerID

Agent Flow

Queries CRM

Output:

CustomerStatus

The topic then continues using the returned value.

This enables modular, reusable workflows.


Variables with Connectors

Connectors almost always require variables.

Example:

Input Variable:

TicketNumber

Connector:

Get Ticket

Output Variables:

Status
AssignedEngineer
Priority
ResolutionDate

These outputs can then drive the rest of the conversation.


Best Practices

Use meaningful names

Good:

CustomerID

Poor:

Var1

Initialize variables

Avoid null values by assigning defaults where appropriate.


Limit scope

Use topic variables when information does not need to persist beyond the current topic.


Reuse existing variables

Avoid asking users the same question multiple times if the information has already been collected.


Keep variable names consistent

Examples:

OrderNumber
CustomerID
ReservationDate

Avoid inconsistent naming conventions.


Validate user input

Before storing values:

  • Check format
  • Check range
  • Check required fields
  • Handle missing or invalid input

This reduces downstream errors.


Common Mistakes

Candidates should recognize these frequent pitfalls:

  • Using a topic variable when a global variable is needed.
  • Assuming variables persist after a topic ends.
  • Forgetting to initialize variables before use.
  • Overwriting important values accidentally.
  • Using unclear variable names.
  • Passing incorrect variables to connectors or APIs.
  • Not validating user input before storing it.
  • Creating unnecessary duplicate variables.

AB-620 Exam Tips

Remember these key points:

  • Variables enable personalization and conversation state.
  • Topic variables have limited scope.
  • Global variables persist across the conversation.
  • System variables provide built-in conversation metadata.
  • Environment variables are used for configuration rather than user conversation data.
  • Variables are commonly used with topics, agent flows, connectors, Adaptive Cards, prompts, and APIs.
  • Proper scope management improves maintainability and reduces errors.
  • Variables are fundamental to conditions, branching, automation, and integrations.

Quick Orientation Summary

In the topics above, you learned the fundamentals of variables, including variable types, scope, lifetime, initialization, and best practices.

In the topics below, we’ll explore advanced scenarios that are frequently tested on the AB-620 certification exam.


Variables in Conditional Logic

Variables are most commonly used to control the path of a conversation. Decision nodes evaluate variable values and determine which actions the agent should perform.

Example

The agent asks:

“What type of account do you have?”

The user’s response is stored in:

AccountType

Decision:

If AccountType = Premium

Then:

  • Display premium support options

Else:

  • Display standard support options

Conditions can evaluate:

  • Equality
  • Inequality
  • Greater than / less than
  • Contains
  • Begins with
  • Ends with
  • Is empty
  • Is not empty
  • Boolean values
  • Multiple combined conditions

Using Variables in Branching

Variables enable dynamic conversation paths.

Example:

OrderStatus

Possible values:

  • Pending
  • Processing
  • Shipped
  • Delivered
  • Cancelled

Each value sends the conversation to a different branch.

Without variables, every user would receive identical responses regardless of their order status.


Variables in Loops

Loops repeat actions until a condition changes.

Common scenarios include:

  • Re-prompting for invalid input
  • Asking multiple questions
  • Processing collections
  • Reviewing lists of items
  • Retry logic

Example:

RetryCount = RetryCount + 1

Continue looping while:

RetryCount < 3

After three failed attempts:

  • Escalate to a human agent
  • End the conversation
  • Offer alternative support

Variables in Generative AI Prompt Nodes

Variables frequently personalize AI-generated responses.

Instead of using a static prompt:

Summarize today's weather.

Use:

Summarize today's weather for {City}.

If:

City = Orlando

The prompt automatically becomes:

Summarize today's weather for Orlando.

This produces highly personalized AI responses.


Variables in Custom Prompts

Custom prompts often include multiple variables.

Example:

CustomerName
SubscriptionType
LastPurchase
OpenSupportTickets

Prompt:

Write a friendly support response for {CustomerName}. They have a {SubscriptionType} subscription. Their last purchase was {LastPurchase}. They currently have {OpenSupportTickets} open support tickets.

The AI response is tailored using the supplied variables.


Variables in Generative Answers

Generative Answers may also leverage variables to refine searches.

Example:

Instead of searching:

Vacation policy

Search:

Vacation policy for {Department}

If:

Department = Finance

The search becomes more specific, increasing the likelihood of returning relevant information.


Variables in Adaptive Cards

Adaptive Cards often display variable values.

Example:

Customer Name
Order Number
Balance Due
Delivery Date

The card dynamically renders current variable values.

Example:

FieldVariable
CustomerCustomerName
OrderOrderNumber
BalanceBalanceDue

As the variables change, the displayed information updates automatically.


Capturing Values from Adaptive Cards

Adaptive Cards are not limited to displaying information—they also collect user input.

Common inputs include:

  • Text
  • Dates
  • Numbers
  • Dropdown selections
  • Toggle switches
  • Choice sets

When submitted, each field is stored in a variable.

Example:

PreferredDate
DeliveryTime
PickupLocation

These variables become available to subsequent nodes in the topic.


Variables in Power Automate Flows

Agent flows frequently call Power Automate.

Variables are used as both inputs and outputs.

Example:

Input variables:

EmployeeID
Department

Flow:

Lookup Employee

Output variables:

ManagerName
VacationBalance
OfficeLocation

The conversation continues using the returned values.


Variables with Connectors

Most connectors require variable mapping.

Example:

Input:

CustomerID

Connector:

Dynamics 365 Customer Lookup

Output:

CustomerName
AccountStatus
SupportTier

Each output becomes a variable that can be referenced later.


Variables in HTTP Requests

Variables commonly populate REST API requests.

Example URL:

https://api.contoso.com/orders/{OrderNumber}

Instead of hardcoding:

12345

The agent inserts:

OrderNumber

making the request dynamic.


Variables in Request Headers

Variables can populate authentication headers.

Example:

Authorization:
Bearer {AccessToken}

This allows tokens obtained earlier in the conversation to authenticate later requests.


Variables in JSON Request Bodies

Example:

{
"customerId": "{CustomerID}",
"priority": "{Priority}",
"description": "{IssueDescription}"
}

Dynamic JSON payloads are common in enterprise integrations.


Variables from HTTP Responses

Responses often populate multiple variables.

Example response:

{
"status":"Processing",
"trackingNumber":"87456",
"estimatedDelivery":"Friday"
}

Mapped variables:

OrderStatus
TrackingNumber
EstimatedDelivery

The conversation can immediately use these values.


Variables in Child Agents

Child agents accept input variables.

Parent agent:

EmployeeID

Child agent:

Benefits Lookup

Output:

RemainingVacation

This approach promotes modular design and reuse.


Variables in Connected Agents

Connected agents exchange variables across agent boundaries.

Typical information exchanged:

  • Customer identifiers
  • Authentication status
  • Product IDs
  • Support ticket numbers
  • Appointment information

Passing variables eliminates unnecessary repeated questions.


Variable Naming Best Practices

Good examples:

CustomerID
EmployeeName
OrderStatus
SupportTicketNumber
PreferredLanguage

Poor examples:

Data1
Value
Temp
MyVariable
ABC

Meaningful names make debugging and maintenance easier.


Avoid Variable Duplication

Avoid creating multiple variables representing the same information.

Poor design:

CustID
Customer_ID
CustomerNumber
CID

Better:

CustomerID

Consistency improves readability and reduces errors.


Secure Handling of Variables

Variables may contain sensitive information.

Examples include:

  • Email addresses
  • Phone numbers
  • Employee IDs
  • Customer records
  • Authentication tokens
  • Financial information

Best practices include:

  • Store only necessary data.
  • Avoid exposing sensitive variables in messages.
  • Protect access tokens.
  • Limit variable scope whenever possible.
  • Follow organizational security policies.
  • Respect Microsoft Power Platform security controls.

Common Troubleshooting Scenarios

Variable is Empty

Possible causes:

  • User skipped the question.
  • Variable was never initialized.
  • API returned no value.
  • Incorrect mapping.

Solution:

  • Validate the variable before use.

Wrong Variable Used

Example:

Expected:

CustomerID

Used:

OrderID

Result:

Connector returns incorrect data.

Always verify mappings carefully.


Variable Lost Between Topics

Possible cause:

A topic variable was used when a global variable was required.

Solution:

Use a conversation-level variable or explicitly pass the value between topics.


Null API Responses

If an external API returns:

null

The variable should be checked before it is displayed.

Example:

Instead of:

Order shipped on {ShipDate}

Use:

If ShipDate is empty
Display:
Shipping information is not yet available.

Performance Considerations

Well-designed variable management improves performance.

Recommendations:

  • Minimize unnecessary variables.
  • Remove unused variables.
  • Avoid repeated API calls when values are already available.
  • Reuse previously retrieved information.
  • Keep conversations efficient.

Exam Tips

Remember these important concepts for the AB-620 exam:

  • Variables drive nearly every dynamic conversation.
  • Decision nodes depend on variable values.
  • Loops often update variables during execution.
  • Adaptive Cards both display and collect variables.
  • Power Automate flows receive and return variables.
  • REST APIs consume variables in URLs, headers, and JSON bodies.
  • Child agents exchange information through input and output variables.
  • Variables should have meaningful names.
  • Scope determines where variables are available.
  • Secure handling of sensitive variables is essential.

Practice Exam Questions

Question 1

An agent collects a customer’s account number and needs to use it throughout several topics during the same conversation. Which type of variable is most appropriate?

A. Topic variable

B. Environment variable

C. Global (conversation) variable

D. System variable

Correct Answer: C

Explanation: Conversation-level (global) variables remain available across multiple topics during a conversation, making them ideal for information that must be reused.


Question 2

A developer needs to repeatedly ask a user for a valid email address until the format is correct. Which feature relies on variables to accomplish this?

A. Loop with a retry counter

B. Adaptive Card image

C. Environment variable

D. Knowledge source

Correct Answer: A

Explanation: Retry loops typically use a counter variable and validation logic to determine whether another attempt should occur.


Question 3

Which scenario is the best example of using variables inside a custom AI prompt?

A. Displaying a static welcome message

B. Showing the agent logo

C. Sending a prompt that includes the customer’s purchase history

D. Changing the conversation language manually

Correct Answer: C

Explanation: Variables personalize AI prompts by injecting dynamic business information into the prompt.


Question 4

An HTTP request needs to retrieve order information for whichever order the user specifies. What should be placed in the request URL?

A. A hardcoded order number

B. The API documentation

C. An environment variable containing the API version

D. A variable containing the selected order number

Correct Answer: D

Explanation: Dynamic API requests use variables to insert values collected during the conversation.


Question 5

An Adaptive Card contains text boxes for Name, Phone Number, and Email Address. What happens after the user submits the card?

A. The values automatically become available as variables.

B. The conversation immediately ends.

C. The variables become environment variables.

D. The card is deleted permanently.

Correct Answer: A

Explanation: Adaptive Card input controls capture user responses, which are stored as variables for later use.


Question 6

Why should developers avoid creating multiple variables for the same piece of information?

A. It increases API speed.

B. It reduces storage costs.

C. It improves maintainability and reduces confusion.

D. It encrypts the data automatically.

Correct Answer: C

Explanation: Consistent variable naming reduces errors and simplifies maintenance.


Question 7

Which information should generally receive additional protection when stored in variables?

A. Conversation greeting

B. Authentication tokens

C. Agent display name

D. Static instructions

Correct Answer: B

Explanation: Access tokens and other credentials are sensitive information and should be handled securely.


Question 8

A connector returns a customer’s membership level. What is the primary purpose of storing this value in a variable?

A. To reduce the size of the connector

B. To replace system variables

C. To personalize future conversation decisions

D. To generate environment variables

Correct Answer: C

Explanation: Connector outputs are commonly stored in variables so they can be used in conditions, messages, and subsequent actions.


Question 9

A developer notices that a variable is unavailable after switching to another topic. What is the most likely cause?

A. The variable exceeded its maximum length.

B. The variable was encrypted.

C. The connector failed.

D. The variable was created with topic scope instead of conversation scope.

Correct Answer: D

Explanation: Topic variables exist only within their originating topic unless their values are explicitly passed or stored in conversation-level variables.


Question 10

What is one of the primary benefits of passing variables to child agents?

A. Child agents become system variables.

B. Variables are automatically persisted forever.

C. Child agents can perform specialized work without asking the user for the same information again.

D. Variables are converted into knowledge sources.

Correct Answer: C

Explanation: Passing variables between parent and child agents improves modularity and creates a smoother user experience by avoiding duplicate prompts.


Key Takeaways

For the AB-620 exam, remember that variables are the foundation of dynamic, intelligent conversations in Copilot Studio. You should be comfortable with:

  • Creating, initializing, and managing variables.
  • Understanding topic, conversation, system, and environment variable scopes.
  • Using variables in conditions, loops, Adaptive Cards, prompts, connectors, agent flows, and REST APIs.
  • Passing variables between topics, parent agents, and child agents.
  • Applying naming conventions, security practices, and troubleshooting techniques.
  • Recognizing when conversation-level variables are more appropriate than topic-level variables in multi-topic agent solutions.

Go to the AB-620 Exam Prep Hub main page