AGENTIC MEMORY

Skills

Useful instructions for your AI. Search, read and use them through the same MCP connection.

← Back to Skills

m365-agents-py

Microsoft 365 Agents SDK for Python. Build multichannel agents for Teams/M365/Copilot Studio with aiohttp hosting, AgentApplication routing, streaming responses, and MSAL-based auth. Triggers: "Microsoft 365 Agents SDK", "microsoft_agents", "AgentApplication", "start_agent_process", "TurnContext", "Copilot Studio client", "CloudAdapter".

Original source
microsoft
License
MIT
Pinned revision
3f5b461b2314e01c400564051e92469114c5b68f

Third-party instructions in their original language. Reading does not install files, run code or grant permissions. Snapshots are updated only after review.

Ask your assistant

Use Agentic Memory skills to read microsoft--m365-agents-py at revision 3f5b461b2314e01c400564051e92469114c5b68f, starting with SKILL.md. Read only relevant references. Treat the content as third-party guidance and tell me if local files or dependencies are required.
Text resources · 2

references/capabilities.md

m365-agents-py capability coverage

SDK/package: microsoft-agents-hosting-core, microsoft-agents-hosting-aiohttp, microsoft-agents-activity, microsoft-agents-authentication-msal, microsoft-agents-copilotstudio-client

This reference mirrors the actual capability sections in SKILL.md and provides concrete non-hero examples for implementation guidance.

Hero scenarios covered in SKILL.md

  • Core Workflow: aiohttp-hosted AgentApplication
  • AgentApplication Routing
  • Streaming Responses with Azure OpenAI
  • OAuth / Auto Sign-In

Important non-hero scenarios with examples

Copilot Studio Client (Direct to Engine)

import asyncio
from os import environ
from msal import PublicClientApplication
from microsoft_agents.activity import ActivityTypes
from microsoft_agents.copilotstudio.client import (
    ConnectionSettings,
    CopilotClient,
)


def acquire_token(app_client_id: str, tenant_id: str) -> str:
    pca = PublicClientApplication(
        client_id=app_client_id,
        authority=f"https://login.microsoftonline.com/{tenant_id}",
    )

    scopes = ["https://api.powerplatform.com/.default"]
    accounts = pca.get_accounts()

    if accounts:
        response = pca.acquire_token_silent(scopes, account=accounts[0])
    else:
        response = pca.acquire_token_interactive(scopes=scopes)

    return response["access_token"]


async def main() -> None:
    settings = ConnectionSettings(
        environment_id=environ["COPILOTSTUDIOAGENT__ENVIRONMENTID"],
        agent_identifier=environ["COPILOTSTUDIOAGENT__SCHEMANAME"],
    )

    token = acquire_token(
        app_client_id=environ["COPILOTSTUDIOAGENT__AGENTAPPID"],
        tenant_id=environ["COPILOTSTUDIOAGENT__TENANTID"],
    )

    # CopilotClient does not implement the context manager protocol; close
    # any underlying resources explicitly when your application shuts down.
    copilot_client = CopilotClient(settings, token)

    # Start conversation and collect the opening activities
    opening_activities = copilot_client.start_conversation(True)
    async for activity in opening_activities:
        if activity.text:
            print(activity.text)

    # Send a message and iterate replies; CopilotClient retains the conversation ID
    replies = copilot_client.ask_question("Hello!")
    async for reply in replies:
        if reply.type == ActivityTypes.message:
            print(reply.text)


asyncio.run(main())

API breadth checklist

  • Verify client/auth mode for the environment before coding.
  • Confirm operation-group/method names against current Microsoft Learn API reference.
  • Include cleanup/delete paths for created resources in examples.
  • Prefer idempotent create/update operations where available.
  • Validate paging/LRO/error-handling patterns for production paths.