Power Automate Flow Setup

This guide walks you through setting up a Power Automate flow that lets Calibrant test, optimize, and update your Copilot Studio agents — even agents that require Microsoft authentication. One flow handles all your agents.

Prerequisites: Power Automate Premium license (for the HTTP trigger), at least one published Copilot Studio agent, and a Microsoft Dataverse connection (required for the apply and sync features).

What the flow does

The flow supports three actions, controlled by the action field in each request:

  • chat (default) — sends a test question to your agent and returns the response
  • get — fetches the current instructions from Copilot Studio (via Dataverse) so Calibrant stays in sync
  • apply — pushes optimized instructions back to Copilot Studio (via Dataverse), replacing only the instructions field

A single Switch action routes each request to the correct branch. The get and apply actions use the Microsoft Dataverse connector to read/write the agent's botcomponent record directly, while chat uses the Copilot Studio connector to execute the agent.

Option 1 — Download the pre-built template (recommended)

Skip the manual setup. Import the Calibrant Agent Tester flow directly into your Power Automate tenant.

  1. Download the flow template — either from the Agent Optimizer (Register Agent → Power Automate → Download CalibrantAgentTester.zip) or directly here: CalibrantAgentTester.zip.
  2. Go to make.powerautomate.com My flowsImportImport Package (.zip).
  3. Upload the zip and follow the import wizard. When prompted, connect both:
    • Microsoft Copilot Studio — using an account that has access to your agents
    • Microsoft Dataverse — using an account with access to the Copilot Studio environment
  4. Once imported, open the flow → Edit → find the Evaluate API Key condition → replace the placeholder PASTE_YOUR_CALIBRANT_API_KEY_HERE with the API key shown in Calibrant when you register your agent.
  5. Still in Edit mode, click the When an HTTP request is received trigger to expand it → copy the HTTP POST URL. Paste this URL into Calibrant when registering.
Where to find your API key and flow URL in Calibrant: Agent Optimizer → Register Agent → Simple Mode → Power Automate. The API key is pre-generated for you — copy it and paste it into the flow's Condition step.

Option 2 — Build the flow manually

If you prefer to build the flow from scratch, follow the steps below.

Step 1: Create the flow

  1. Go to make.powerautomate.com.
  2. Click CreateInstant cloud flow.
  3. Name it Calibrant Agent Tester.
  4. Select trigger: "When an HTTP request is received".
  5. Click Create.

Step 2: Configure the HTTP trigger

In the trigger step, paste this JSON schema into the Request Body JSON Schema field:

{
  "type": "object",
  "properties": {
    "action": {
      "type": "string",
      "description": "The action to perform: chat, apply, or get"
    },
    "query": {
      "type": "string",
      "description": "The test question to send to the agent (chat action)"
    },
    "agentId": {
      "type": "string",
      "description": "The Copilot Studio agent identifier"
    },
    "schemaName": {
      "type": "string",
      "description": "The agent schema name (e.g., copilots_header_d3197) used to select the agent"
    },
    "instructions": {
      "type": "string",
      "description": "New instructions to apply (apply action only)"
    },
    "callbackId": {
      "type": "string",
      "description": "Unique ID for tracking this request"
    }
  },
  "required": ["agentId"]
}

Step 3: Add API key validation

This prevents unauthorized calls to your flow.

  1. Add a Condition action after the trigger.
  2. Set the condition to:
    triggerOutputs()?['headers']?['x-calibrant-key']
    is equal to the API key generated by Calibrant (copy it from the Register Agent dialog → Power Automate).
  3. In the If no branch, add a Response action:
    • Status code: 401
    • Body: {"success": false, "error": "Invalid API key"}
  4. Continue building the rest of the flow in the If yes branch.

Step 4: Add a Switch on action

In the If yes branch, add a Switch action on the expression:

triggerBody()?['action']

Create three cases: chat (default), get, and apply.

Step 5: Default case — Chat (test the agent)

  1. In the default case, add "Execute Agent and Wait" (Microsoft Copilot Studio connector).
  2. For the Agent field, switch to the expression editor (fx) and enter:
    triggerBody()?['schemaName']
  3. For the Message field, use the dynamic content query from the trigger.
  4. Add a Response action returning the agent's responses:
    @outputs('Execute_Agent_and_Wait')?['body/responses']

Step 6: Get case — Fetch current instructions

This reads the agent's instructions from Dataverse so Calibrant can stay in sync.

  1. Add a List rows action (Microsoft Dataverse connector) for entity botcomponents:
    • Filter: startswith(schemaname, '@{triggerBody()?['schemaName']}') and componenttype eq 15
    • Select columns: botcomponentid,data
    • Row count: 1
  2. Add a Compose action to extract the instructions value from the YAML data field:
    first(split(last(split(first(outputs('List_rows_Get')?['body/value'])?['data'], 'instructions: "')), concat('"', decodeUriComponent('%0A'))))
  3. Add a Response action:
    { "instructions": "@{outputs('Compose_Extract')}" }

Step 7: Apply case — Push optimized instructions

This writes new instructions to the agent in Copilot Studio via Dataverse.

  1. Add a List rows action (same filter as the Get case) to find the agent's botcomponent record.
  2. Add a Compose to extract the YAML before the instructions value:
    first(split(first(outputs('List_rows')?['body/value'])?['data'], 'instructions: "'))
  3. Add a Compose to extract the YAML after the instructions value:
    last(split(last(split(first(outputs('List_rows')?['body/value'])?['data'], 'instructions: "')), concat('"', decodeUriComponent('%0A'))))
  4. Add a Compose to reconstruct the full YAML with only the instructions replaced:
    concat(
      outputs('Compose_before'),
      'instructions: "',
      replace(replace(triggerBody()?['instructions'], '"', '\"'), decodeUriComponent('%0A'), '\n'),
      '"',
      decodeUriComponent('%0A'),
      outputs('Compose_after')
    )
  5. Add an Update a row action (Dataverse) to write the new data back:
    • Row ID: the botcomponentid from the List rows result
    • Data field: the composed new YAML
  6. Add a Response action: {"success": true}
Where to find the schema name: In Copilot Studio, open your agent → Settings → Advanced. The schema name looks like copilots_header_d3197. You enter this when registering the agent in Calibrant.

Step 8: Save and copy the URL

  1. Save the flow.
  2. Go back to the HTTP trigger step — it now displays an HTTP POST URL.
  3. Copy this URL.

Step 9: Register in Calibrant

  1. In Calibrant, go to Agent OptimizerRegister Agent.
  2. Select Simple Mode → choose the Power Automate card.
  3. Copy the pre-generated API Key and paste it into your flow's Condition step (Step 3 above).
  4. Paste the Flow URL from Step 8.
  5. Fill in the agent name, Agent ID, and Schema Name.
  6. Click Fetch from Copilot Studio to pull the current instructions automatically.
  7. Click Register Agent.

Testing

Once registered, go to the agent detail page and use the Test Chat panel. Type a query — Calibrant sends it to your flow, which executes the agent and returns the response.

You can also test each action directly with curl:

Test chat

curl -X POST "YOUR_FLOW_URL" \
  -H "Content-Type: application/json" \
  -H "x-calibrant-key: YOUR_API_KEY" \
  -d '{
    "action": "chat",
    "query": "What is our PTO policy?",
    "agentId": "your-agent-guid",
    "schemaName": "copilots_header_d3197"
  }'

Fetch instructions

curl -X POST "YOUR_FLOW_URL" \
  -H "Content-Type: application/json" \
  -H "x-calibrant-key: YOUR_API_KEY" \
  -d '{
    "action": "get",
    "agentId": "your-agent-guid",
    "schemaName": "copilots_header_d3197"
  }'

Apply instructions

curl -X POST "YOUR_FLOW_URL" \
  -H "Content-Type: application/json" \
  -H "x-calibrant-key: YOUR_API_KEY" \
  -d '{
    "action": "apply",
    "agentId": "your-agent-guid",
    "schemaName": "copilots_header_d3197",
    "instructions": "Your new optimized instructions here..."
  }'

Multiple agents

Because the flow uses triggerBody()?['schemaName'] to dynamically select the agent,one flow handles all your agents automatically. Each agent registered in Calibrant has its own schema name, and the flow routes to the correct agent based on that.

No per-agent configuration needed — just register each agent in Calibrant with its schema name from Copilot Studio → Settings → Advanced.

Troubleshooting

Flow returns 401

The API key in Calibrant doesn't match the one in your flow's Condition step. Verify both match exactly.

Flow times out

The "Execute Agent and Wait" action has a default timeout. If your agent takes a long time to respond (e.g., it calls external APIs), increase the timeout in the action settings.

Agent requires auth but flow doesn't work

Ensure the Copilot Studio connector connection in Power Automate is signed in with an account that has access to the agent. The flow runs as that account's identity.

Get/Apply returns empty or fails

The Dataverse connector needs access to the Copilot Studio environment. Ensure the Dataverse connection is signed in with an account that has the System Customizer or Environment Maker role in the environment where your agents live. Also verify the schema name matches exactly (Copilot Studio → Settings → Advanced).


Next steps