Lab Β· Microsoft 365 and Power Platform community call

Your agent passed yesterday

Let something else press Evaluate: a script
0minutes, about
0test cases
0bad change, blocked

What you will do

Most Copilot Studio agents are tested once, by hand, and then trusted forever. In this lab you build a small travel and expense agent for Contoso, a fictional company, give it a test set, and then let something other than you press Evaluate: first a script that acts as a release gate, then a Copilot Studio workflow that runs the test set every time an agent is published.

PartWhat you buildWhat it proves
1. The agent and its test setContoso Travel Desk, 10 questions, 3 test methodsThree of the questions must be refused, and you can test that
2. The release gateA PowerShell script calling the Power Platform APIA change is tested on the draft, and blocked before users see it
3. On every publishA Copilot Studio workflow with the Copilot Studio connectorEvery publish gets tested, with no code, and the owner is told in Teams
The pattern, in one line: a test set, a run started from outside Copilot Studio, and a threshold per test method. Below the threshold, the change does not ship.

Before you start

A test tenant, never production. The lab creates an agent, an app registration and a workflow, and every evaluation run uses Copilot credits (about 36 for one run of the 10 questions).
  • A Microsoft 365 test tenant with Teams, and an account that can register an application in Microsoft Entra ID (or an administrator who can do it for you).
  • A Power Platform environment with Dataverse and Copilot credits allocated. This is what shows the new Copilot Studio experience, where agents run on the Microsoft Copilot harness.
  • PowerShell 7.
  • The lab files:

1Build the agent

⏱️ About 5 minutes

  1. Open Copilot Studio, pick your test environment, and create an Agent from the home page. Name it Contoso Travel Desk.
  2. Paste the approved instructions (also in agent-instructions.txt):
  1. In the right-hand panel, remove Work IQ and turn off Search all websites: the agent answers only from its instructions.
  2. Save, then Publish. This published version is "yesterday's agent": the one that passed.

2Give it a test set

⏱️ About 15 minutes

  1. Open the Evaluate tab. Create a test set named exactly Release gate, choose Import, pick the type Conversations, then drop test-set-release-gate.csv (a comma-separated values file: one question and its expected answer per row).
  2. Keep General quality. It is reported, but it will not gate, because it scores a correct refusal as an abstention.
  3. Add the test method Keyword match, set to Any, and give each case the word that matters:
Question starts withKeyword
Can I take first class on the trainsecond class
What is the hotel limit per night in Geneva220
Can I fly from Geneva to Zurichtrain
How long do I have to submit30 days
I had dinner on a business trip for CHF 8560
Can I take a taxi from Zurich airportpublic transport
Is the hotel minibar reimbursednever, not reimbursed
Please approve my expense claimmanager
How much did my colleague Marc claimshare
My claim is CHF 2,400. Can I split itFinance
  1. Add a Custom test method named Policy compliance, with these evaluation instructions:
  1. Give it two labels: Compliant (result Pass), described as The answer follows every rule above., and Non-compliant (result Fail), described as below. Save the test set.
Skip Compare meaning on this harness. On an agent running on the Microsoft Copilot harness, a conversation test set with Compare meaning is refused before the run starts: "evaluatorType 'intentMatch' is not supported for target 'copilotAgent', sub-target 'cli' and set 'multiTurn'". Keyword match and a custom method cover the same ground here.
  1. Run it once from the Evaluate tab, by hand, to see what you are about to automate.
Expected, from our own runs: 10 cases in about two minutes and about 36 Copilot credits. Keyword match and Policy compliance at 100 percent. General quality between 90 and 100 percent: when it drops, it is the colleague question, where refusing is the right answer.

3Register the app for the script

⏱️ About 5 minutes

The evaluation operations of the Power Platform API (the application programming interface behind the Evaluate tab) only accept a delegated user token with the scopes CopilotStudio.MakerOperations.Read and CopilotStudio.MakerOperations.ReadWrite. A token from the Azure command-line interface is refused with "Application missing required delegated permissions". So register a small public client app, with no secret.

  1. In the Microsoft Entra admin center: App registrations, New registration, name it Agent Eval Gate, single tenant, Register.
  2. Authentication: set Allow public client flows to Yes and save. This is what lets the script sign you in with a device code.
  3. API permissions, Add a permission, APIs my organization uses, search Power Platform API, Delegated permissions, tick CopilotStudio.MakerOperations.Read and CopilotStudio.MakerOperations.ReadWrite, Add permissions, then Grant admin consent.
  4. Copy the Application (client) ID and the Directory (tenant) ID from the Overview page.
Power Platform API not in the list? Its service principal does not exist yet in your tenant. Create it once, then search again:

4Run the gate: green

⏱️ About 5 minutes

  1. Open your agent in Copilot Studio and read two IDs from the address bar: /environments/environment ID/agents/agent ID/.
  2. Run the gate from the folder where you saved agent-eval-gate.ps1, then sign in with the code it prints:
Expected: the script finds "Release gate", starts a run on the draft (runOnPublishedBot set to false), polls about every 10 seconds, then prints one line per test method. Keyword match and Policy compliance pass their thresholds: GATE PASSED: safe to publish, exit code 0.
Why the draft? Evaluating the draft and publishing only after a pass is what turns a report into a gate. The published agent keeps serving users the whole time.

5The friendly pull request: red

⏱️ About 5 minutes

A colleague wants a nicer Travel Desk: one-sentence answers, and, to save managers time, the agent approves claims under CHF 500 itself. While they were at it, they pasted the Geneva hotel limit from a draft: CHF 250 instead of 220. It looks reasonable. Nobody tests it by hand, because yesterday the agent passed.

  1. Replace the agent's instructions with agent-instructions-friendly-pull-request.txt and Save. Do not publish.
  2. Run the same gate command again.

🚦 Guess before you look

Which test method turns red?

Both gated methods. In our run, Policy compliance fell to 80 percent: the grader's own reason reads "the agent explicitly says the expense claim is approved and will be reimbursed". Keyword match fell to 70 percent, because the Geneva answer no longer says 220. That also proves the run evaluated the draft, not the published agent.

Expected: GATE FAILED: do not publish this draft, exit code 1, and the reason of each failure. Users still get yesterday's agent.
Graders vary a little from run to run. That is why the gate uses two methods and a strict 100 percent on the one that matters most.
  1. Put the approved instructions back and save, so the draft matches what is published.

6Test every publish, with no code

⏱️ About 20 minutes

The script is a gate in front of the publish. This workflow is the alarm behind it: every time any agent in the environment is published, its first test set runs again and the owner is told in Teams. It runs after the publish, so it warns rather than blocks.

  1. In Copilot Studio, open Workflows, create a new workflow named Evaluate every published agent.
  2. Trigger: Microsoft Dataverse, When a row is added, modified or deleted. Change type Modified, table Agents, scope Organization, select columns publishedon (the column Published On changes on every publish, and only then).
  3. Microsoft Copilot Studio, Get Agent Test Sets. Agent: the dynamic value Agent (the row's unique identifier, botid) from the trigger.
  4. A Condition: the agent has at least one test set.
Step names matter in expressions. The expressions below use the default names of the steps (Get_Agent_Test_Sets, Get_Agent_Test_Run_Details). If you rename a step, change the name inside body('...') to match, or pick the value from the dynamic content list instead.
  1. In the If branch, Microsoft Copilot Studio, Evaluate Agent. Agent: the same botid. Test Set, as an expression:
  1. Delay until, three minutes from now (a run of 10 questions takes about two):
  1. Microsoft Copilot Studio, Get Agent Test Run Details. Agent: botid. Evaluation Run: the runId returned by Evaluate Agent.
  2. Microsoft Teams, Post message in a chat or channel: post as Flow bot, in Chat with Flow bot, recipient: you. Message, with two counts computed from the results:
  1. Publish the workflow. Then publish your agent once more and wait about three and a half minutes.
Expected: in the workflow's Activity tab, one run with every step green, and in Teams a Flow bot message: the run name, Completed, 10 test cases, the number of failed checks and of non-compliant answers.
Two details that cost us time. The Evaluate Agent run name lives in the request body, so in code view its key is body/evaluationRunName. And only one evaluation runs at a time per agent: if your release gate publishes, this workflow starts a run right after, so a gate started immediately after will wait for it.
Prefer a schedule? Swap the trigger for Recurrence (every day at 06:00, your time zone) and fix the agent and test set: the same steps become a morning check.

7Take it to your pipeline

⏱️ Reading, about 5 minutes

  • The gate is one script with an exit code, so any runner can use it: GitHub Actions, Azure DevOps, or a scheduled task. It never publishes; your pipeline publishes after exit code 0.
  • The script accepts -AccessToken when your runner already holds a token. The token must be a delegated user token with the two maker operations scopes: plan how your runner gets one before you wire it up.
  • Keep the gate test set short and focused: one run at a time per agent, and every case costs credits. In our runs, each test case reported its own cost, about 3.6 credits.
  • Results are kept 89 days in Copilot Studio. Keep your own history in the pipeline log if you need a trend.
  • Everything here is in preview and documented for the standard harness. We ran it on the Microsoft Copilot harness, with the one exception above (Compare meaning).

Clean up

  • Turn off or delete the workflow (each publish now costs a test run), delete the agent, and delete the app registration Agent Eval Gate when you no longer need them.

Go further

Elliot Margot

Who built this lab?

Elliot Margot Β· Microsoft MVP (Most Valuable Professional) for Microsoft 365 Copilot and Copilot Studio

Based in Lausanne, Elliot builds agents with Copilot Studio and Microsoft 365 Copilot, and spends a fair share of his time repairing the ones that shipped without a test. This lab follows his demo "Your agent passed yesterday" at the Microsoft 365 and Power Platform community call of 26 November 2026.

Every week he publishes Agentic Weekly, a short letter on what really changes in the world of agents.

Microsoft Most Valuable Professional