Skip to content

feat(python): Add Copilot Studio sample agent#314

Open
Yogeshp-MSFT wants to merge 1 commit into
microsoft:mainfrom
Yogeshp-MSFT:Copilot-Studio-Sample-(python)
Open

feat(python): Add Copilot Studio sample agent#314
Yogeshp-MSFT wants to merge 1 commit into
microsoft:mainfrom
Yogeshp-MSFT:Copilot-Studio-Sample-(python)

Conversation

@Yogeshp-MSFT

Copy link
Copy Markdown

Summary

Adds a new Python sample that bridges Microsoft Copilot Studio low-code agents into the Agent 365 managed environment. Messages arriving through Agent 365 channels (Teams, email) are forwarded to a published Copilot Studio agent via CopilotClient, and responses are relayed back — giving low-code agents access to enterprise identity, notifications, and observability.

What's included

python/copilot-studio/sample-agent/
├── main.py                 # Server entry point — CopilotStudioAgentHost, aiohttp, observability
├── agent.py                # MyAgent — message/notification routing
├── client.py               # McsClient — CopilotClient wrapper with InferenceScope
├── .env.template           # Environment variable template
├── .gitignore              # Python + A365 ignores
├── pyproject.toml          # Dependencies (hatchling)
├── requirements.txt        # For Azure Oryx build
├── ToolingManifest.json    # Empty (proxies to Copilot Studio, no direct MCP tools)
├── README.md               # Comprehensive docs
└── docs/
    └── design.md           # Architecture & design document

Patterns demonstrated

Pattern Implementation
Copilot Studio integration microsoft-agents-copilotstudio-clientCopilotClient + ConnectionSettings for Direct Line connectivity
Agentic auth (Power Platform) OBO token exchange for https://api.powerplatform.com/.default via the AGENTIC auth handler
Observability AgenticTokenCache pattern — tokens acquired at runtime from TurnContext, not static env vars. InferenceScope wraps every Copilot Studio call
Notifications Email notification handling via AgentNotification + EmailResponse
Multiple messages Immediate ack + typing indicator loop + final response
User identity Logs activity.from_property fields on every turn
Install/uninstall Handles installationUpdate activity

Key design decisions

  • No A365_AGENT_APP_INSTANCE_ID / A365_AGENTIC_USER_ID env vars — Observability tokens are acquired from the incoming TurnContext using the AgenticTokenCache pattern per the Microsoft OpenTelemetry Distro docs
  • AUTH_HANDLER_NAME=AGENTIC (uppercase) — must match the handler key in AGENTAPPLICATION__USERAUTHORIZATION__HANDLERS__AGENTIC__... (Python dict lookup is case-sensitive)
  • CopilotStudio.Copilots.Invoke permission required on the blueprint — configurable via a365 setup permissions copilotstudio
  • Root-level file layout (no src/ package) — matches the google-adk sample convention and simplifies Azure App Service deployment

How to test

cd python/copilot-studio/sample-agent
uv venv && uv sync
cp .env.template .env
# Fill in Copilot Studio Environment ID + Agent Identifier
# Fill in service connection credentials from a365 setup all
python main.py

Tested end-to-end with:

  • Agents Playground (anonymous mode)
  • Teams via devtunnel (agentic auth)
  • Azure App Service deployment (zip deploy via az webapp deploy)
  • Observability export verified: HTTP 200 success, rejectedSpans: 0

Dependencies

  • microsoft-agents-copilotstudio-client — Copilot Studio connectivity
  • microsoft-agents-hosting-aiohttp / microsoft-agents-hosting-core — M365 Agents SDK hosting
  • microsoft-agents-a365-notifications — Email/Teams notifications
  • microsoft-agents-a365-runtime — Observability token helpers
  • microsoft-opentelemetry — OpenTelemetry distro (InferenceScope, BaggageBuilder, AgenticTokenCache)

Related


Copilot AI review requested due to automatic review settings May 28, 2026 08:43
@Yogeshp-MSFT Yogeshp-MSFT requested a review from a team as a code owner May 28, 2026 08:43
@Yogeshp-MSFT

Copy link
Copy Markdown
Author

Hi @biswapm can you review this pr ?

@Yogeshp-MSFT Yogeshp-MSFT force-pushed the Copilot-Studio-Sample-(python) branch from 8d83717 to 068fefd Compare June 10, 2026 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant