This Azure Function serves as a bridge between synchronous HTTP requests from Power Platform and the asynchronous Microsoft Copilot Studio Agents SDK. It enables Power Apps and Power Automate to call Copilot Studio agents and wait for responses in a single operation.
The function:
- Receives synchronous HTTP POST requests with agent call parameters
- Uses the Microsoft Agents SDK to initiate asynchronous conversations with Copilot Studio agents
- Waits for the agent's response
- Returns the response synchronously to the caller
- Node.js 20.x (LTS)
- Azure Functions Core Tools v4
- Azure subscription (for deployment)
- Visual Studio Code with Azure Functions extension (recommended)
- Azure CLI (for deployment)
# Clone the repository
git clone https://github.com/microsoft/CopilotStudioSamples.git
# Navigate to the SyncToAsyncService directory
cd CopilotStudioSamples/CallAgentConnector/SyncToAsyncServicenpm installCreate a local.settings.json file in the root directory:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "node"
}
}# Check your Node.js version
node -v
# Should output v20.x.x or higher
# If not, install Node.js 20.x from https://nodejs.org/npm startOr using Azure Functions Core Tools directly:
func startThe function will be available at http://localhost:7071/api/SyncToAsyncService
To test the function with external services (like Power Platform), you can use Visual Studio Code Dev Tunnels to create a public URL.
See the Dev Tunnels documentation for setup and usage instructions.
Once configured, your function will be accessible at a URL like: https://[tunnel-name].devtunnels.ms/api/SyncToAsyncService
Run the included deployment script:
# Make the script executable (Mac/Linux)
chmod +x deploy.sh
# Run the deployment
./deploy.shFor Windows PowerShell:
# Run the deployment
bash deploy.shThe script will:
- Login to Azure
- Create a resource group, storage account, and function app
- Build and deploy the function
- Output the function URL
- Open the project in VS Code with Azure Functions extension
- Sign in to Azure (F1 → "Azure: Sign In")
- Right-click on the Azure Functions icon and select "Deploy to Function App"
- Follow the prompts to create a new Function App or select an existing one
Once deployed, test your function with curl:
curl -X POST https://[your-function-app].azurewebsites.net/api/SyncToAsyncService \
-H "Content-Type: application/json" \
-d '{
"environmentId": "your-environment-id",
"agentIdentifier": "your-agent-id",
"message": "Hello, agent!"
}'Expected response:
{"error":"Unauthorized: Bearer token required in Authorization header"}This error is expected and confirms your function is deployed correctly. Authentication will be handled by the Power Platform connector in the next step.
After deploying this function, proceed to set up the Power Platform custom connector that will use this function as its backend. See ../Connector/README.md for instructions.