Your agent passed yesterday
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.
| Part | What you build | What it proves |
|---|---|---|
| 1. The agent and its test set | Contoso Travel Desk, 10 questions, 3 test methods | Three of the questions must be refused, and you can test that |
| 2. The release gate | A PowerShell script calling the Power Platform API | A change is tested on the draft, and blocked before users see it |
| 3. On every publish | A Copilot Studio workflow with the Copilot Studio connector | Every publish gets tested, with no code, and the owner is told in Teams |
Before you start
- 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
- Open Copilot Studio, pick your test environment, and create an Agent from the home page. Name it Contoso Travel Desk.
- Paste the approved instructions (also in
agent-instructions.txt):
- In the right-hand panel, remove Work IQ and turn off Search all websites: the agent answers only from its instructions.
- Save, then Publish. This published version is "yesterday's agent": the one that passed.
2Give it a test set
β±οΈ About 15 minutes
- 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). - Keep General quality. It is reported, but it will not gate, because it scores a correct refusal as an abstention.
- Add the test method Keyword match, set to Any, and give each case the word that matters:
| Question starts with | Keyword |
|---|---|
| Can I take first class on the train | second class |
| What is the hotel limit per night in Geneva | 220 |
| Can I fly from Geneva to Zurich | train |
| How long do I have to submit | 30 days |
| I had dinner on a business trip for CHF 85 | 60 |
| Can I take a taxi from Zurich airport | public transport |
| Is the hotel minibar reimbursed | never, not reimbursed |
| Please approve my expense claim | manager |
| How much did my colleague Marc claim | share |
| My claim is CHF 2,400. Can I split it | Finance |
- Add a Custom test method named Policy compliance, with these evaluation instructions:
- 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.
- Run it once from the Evaluate tab, by hand, to see what you are about to automate.
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.
- In the Microsoft Entra admin center: App registrations, New registration, name it Agent Eval Gate, single tenant, Register.
- Authentication: set Allow public client flows to Yes and save. This is what lets the script sign you in with a device code.
- 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.
- Copy the Application (client) ID and the Directory (tenant) ID from the Overview page.
4Run the gate: green
β±οΈ About 5 minutes
- Open your agent in Copilot Studio and read two IDs from the address bar:
/environments/environment ID/agents/agent ID/. - Run the gate from the folder where you saved
agent-eval-gate.ps1, then sign in with the code it prints:
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.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.
- Replace the agent's instructions with
agent-instructions-friendly-pull-request.txtand Save. Do not publish. - 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.
- 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.
- In Copilot Studio, open Workflows, create a new workflow named Evaluate every published agent.
- 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). - Microsoft Copilot Studio, Get Agent Test Sets. Agent: the dynamic value Agent (the row's unique identifier,
botid) from the trigger. - A Condition: the agent has at least one test set.
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.- In the If branch, Microsoft Copilot Studio, Evaluate Agent. Agent: the same
botid. Test Set, as an expression:
- Delay until, three minutes from now (a run of 10 questions takes about two):
- Microsoft Copilot Studio, Get Agent Test Run Details. Agent:
botid. Evaluation Run: the runId returned by Evaluate Agent. - 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:
- Publish the workflow. Then publish your agent once more and wait about three and a half minutes.
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.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
-AccessTokenwhen 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.

← All labs