Connect Copilot Studio Agents to Microsoft Agent Framework

Learn how to integrate Microsoft Copilot Studio agents with Agent Framework. Combine low-code agents with custom code, automate testing, and build hybrid multi-agent systems.

What I love about Microsoft Agent Framework is how it integrates with the Microsoft ecosystem. You can seamlessly combine Copilot Studio agents with Microsoft Foundry agents, custom code, and third-party systems — all through a unified API.

This opens up powerful scenarios: orchestrate low-code Copilot Studio agents alongside custom Python agents, automate testing for your bots, and build hybrid workflows that leverage the best of both platforms.

Why This Matters

Integration benefits:

  • Automated testing — Run regression tests against Copilot Studio agents programmatically
  • Multi-agent orchestration — Combine conversational AI with specialized agents for data analysis, document processing, etc.
  • Hybrid architectures — Low-code for business users, code-first for developers
  • Batch processing — Process customer inquiries from queues or CSV files

Technical advantages:

  • Native Azure AD authentication with device code flow
  • Direct Power Platform API integration
  • Streaming and non-streaming support
  • Same SDK experience across all agent types

Demo Repository

Repository: github.com/iLoveAgents/agent-framework-copilot-studio

Includes automated Azure setup, basic and advanced examples, streaming support, and production patterns.

Quick Start

Prerequisites

  • Python 3.10 or higher
  • uv package manager (or use pip)
  • Azure subscription with Copilot Studio access
  • Azure CLI installed and authenticated

One-Time Setup

1. Run the automated setup script:

./setup_azure_app.sh

This script creates an Azure AD app registration, enables public client flows, adds Power Platform API permissions, and grants admin consent. It saves the configuration to your .env file automatically.

2. Find your environment ID:

Go to Power Platform Admin Center and copy your environment ID (format: Default-<guid>).

3. Configure your .env file:

.env
COPILOTSTUDIOAGENT__ENVIRONMENTID=Default-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx COPILOTSTUDIOAGENT__SCHEMANAME=<your-agent-schema-name> COPILOTSTUDIOAGENT__AGENTAPPID=<set-by-setup-script> COPILOTSTUDIOAGENT__TENANTID=<set-by-setup-script>

Running the Basic Example

uv sync uv run main.py

The basic example (main.py) shows:

  • Creating a CopilotStudioAgent() with environment variables
  • Both streaming and non-streaming responses
  • Automatic authentication with device code flow (opens browser once, caches tokens)

Advanced Configuration

For production scenarios, the advanced example (copilotstudio_explicit.py) shows explicit configuration:

  • Custom token acquisition (service principals, managed identities)
  • Explicit ConnectionSettings for multi-environment setups
  • Direct CopilotClient instantiation for connection pooling
  • Granular error handling

Use Cases

Automated Testing

Run pytest regression tests against your agents — test greetings, FAQs, intents. Catch regressions before production.

Multi-Agent Orchestration

Route customer queries between Copilot Studio (conversational UI) and Microsoft Foundry agents (specialized data analysis). Extend with planner-executor patterns or intent-based routing.

Batch Processing

Process CSV files or queue messages programmatically — customer inquiries, support tickets, data migrations.

Troubleshooting

Authentication Fails

rm -f .msal_token_cache.json uv run main.py

Can’t Connect to Environment

  • Verify your environment ID format: Default-<guid> (capital D, with hyphen)
  • Make sure your agent is published in Copilot Studio
  • Check you have access in Power Platform Admin Center

Permission Errors

# Create the Power Platform service principal if missing az ad sp create --id 8578e004-a5c6-46e7-913e-12f58912df43 # Re-grant consent az ad app permission admin-consent --id <YOUR_APP_ID>

What I Love

Zero custom auth logic, identical API surface across agent types, production-ready patterns out of the box, and fast iteration with automated setup. The Microsoft ecosystem bridges are built, tested, and ready.

Let’s Build Together

Using Copilot Studio in production? Building hybrid agent systems? Share your experience on iLoveAgents or connect on LinkedIn.

Resources

Demo Repository:

Microsoft Documentation:

Related Posts: