m365-agents-py 是什么?
此 Skill 指导用 Microsoft 365 Agents Python SDK 与 aiohttp 建 Agent 服务,处理活动路由、MSAL身份、OAuth Graph handler、流式 Azure OpenAI 响应及 Copilot Studio direct client。代码以异步请求处理为主。
中文说明由本站依据来源整理;英文原文保留在页面下方。
怎么接入你的 Agent?
- 定位完整 Skill 目录
打开本项目来源,核对
SKILL.md及其引用的脚本和资料。 - 交给你正在用的 Agent
在下面选择客户端,展开并复制安装指令,让 Agent 读取来源后选择安装方式。
- 确认识别,再做具体任务
让 Agent 回报安装目录和识别到的名称
m365-agents-py,然后按本页使用示例提供材料。
展开并复制给 Codex 的安装指令
安装并检查 m365-agents-py
请在 Codex 的当前工作环境中安装并检查 m365-agents-py 这个 Skill。
项目身份:microsoft/skills / m365-agents-py
来源:https://github.com/microsoft/skills/blob/f03ec5392f7a0f3aca12af47477e92f1edf7b44c/.github/plugins/azure-sdk-python/skills/m365-agents-py/SKILL.md
已定位的源文件:.github/plugins/azure-sdk-python/skills/m365-agents-py/SKILL.md
1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。展开并复制给 Claude Code 的安装指令
安装并检查 m365-agents-py
请在 Claude Code 的当前工作环境中安装并检查 m365-agents-py 这个 Skill。
项目身份:microsoft/skills / m365-agents-py
来源:https://github.com/microsoft/skills/blob/f03ec5392f7a0f3aca12af47477e92f1edf7b44c/.github/plugins/azure-sdk-python/skills/m365-agents-py/SKILL.md
已定位的源文件:.github/plugins/azure-sdk-python/skills/m365-agents-py/SKILL.md
1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。展开并复制给 Cursor 的安装指令
安装并检查 m365-agents-py
请在 Cursor Agent 的当前工作环境中安装并检查 m365-agents-py 这个 Skill。
项目身份:microsoft/skills / m365-agents-py
来源:https://github.com/microsoft/skills/blob/f03ec5392f7a0f3aca12af47477e92f1edf7b44c/.github/plugins/azure-sdk-python/skills/m365-agents-py/SKILL.md
已定位的源文件:.github/plugins/azure-sdk-python/skills/m365-agents-py/SKILL.md
1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。展开并复制给 当前 Agent 的安装指令
安装并检查 m365-agents-py
请在 当前 Agent 的当前工作环境中安装并检查 m365-agents-py 这个 Skill。
项目身份:microsoft/skills / m365-agents-py
来源:https://github.com/microsoft/skills/blob/f03ec5392f7a0f3aca12af47477e92f1edf7b44c/.github/plugins/azure-sdk-python/skills/m365-agents-py/SKILL.md
已定位的源文件:.github/plugins/azure-sdk-python/skills/m365-agents-py/SKILL.md
1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。装好以后,具体怎么用?
准备哪些材料
- 按源码先在 microsoft-docs 核实 API signature 并在 PyPI 核实包版本;包分为 hosting-core、aiohttp、activity、authentication-msal等。
- Python SDK导入使用 microsoft_agents 前缀;准备连接服务 client ID/secret/tenant和对应通道配置。
- 生产存储不能用 MemoryStorage;用持久化后端并启用 JWT middleware、HTTPS和密钥保管。
实际使用顺序
- load_configuration_from_env 后创建 MsalConnectionManager、CloudAdapter、Authorization 与 AgentApplication。
- 定义 async activity/message/conversation handlers,映射 /api/messages 并使用 jwt_authorization_middleware。
- 接入 Graph OAuth 时用 auth_handlers 取 token,HTTP Session 用 async with;只请求所需权限。
- 流式输出在 finally 调 end_stream;CopilotStudioClient 单独管理 token 获取,并注意其不实现上下文管理器协议。
从一个具体任务开始
本站根据源文件编写的使用示例,未在本站实际运行。示例中的文件由你提供。
复制一个具体任务
请根据此 Skill 给我的 Python 工程写一份只读接入审查清单:核对导入前缀、aiohttp middleware、MSAL配置、持久化storage和流式end_stream。先不要装包或启动服务。得到源码与配置核查项;没有安装依赖、登录或运行服务。
使用条件与边界
- 源文 Copilot Studio 示例将交互登录、token cache 和 client 生命周期示意混在一起,正式服务需重新设计机密凭据或托管身份方式。
- 源文示例用 MemoryStorage,只用于开发;把它直接部署会导致状态丢失。
- Azure OpenAI streaming 示例要另配置 SDK、模型部署、权限及API版本。
常见问题
为什么 ModuleNotFoundError 找不到 microsoft.agents?
源文指出新版包导入前缀变化为 microsoft_agents 下划线形式,并且必须安装对应模块包。
CopilotStudioClient可以直接 async with 吗?
源文明确其不实现 context manager;按该客户端的显式清理/生命周期 API 处理,并避免错误使用 async with。
来源原文与资料状态
- 源文件
- 已保存 SKILL.md,抓取于 2026-11-16T12:36:35.145Z
- 中文使用说明
- 已针对下方源文件版本整理用途、用法和常见问题
- 安装与任务测试
- 本站未执行安装或任务测试
- 来源复核
- 本页中文用法已对照保存版本的完整 SKILL.md 阅读整理
展开 SKILL.md 原文、章节与历史收录资料
.github/plugins/azure-sdk-python/skills/m365-agents-py/SKILL.md · 抓取时间 2026-11-16T12:36:35.145Z
以下保留源文件的 description、章节及摘录,供核对中文说明;完整文件通过上方链接打开。
抓取成功不代表已完成安装或任务测试。
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".
查看源文件章节 / Source sections
- 原文:Microsoft 365 Agents SDK (Python)
- 原文:Before implementation
- 原文:Important Notice - Import Changes
- 安装 / Installation
- 原文:Environment Variables (.env)
- 原文:Authentication & Lifecycle
- 原文:Core Workflow: aiohttp-hosted AgentApplication
- 原文:AgentApplication Routing
- 原文:Streaming Responses with Azure OpenAI
- 原文:OAuth / Auto Sign-In
- 原文:Copilot Studio Client (Direct to Engine)
- 原文:Best Practices
- 原文:Reference Links
- 原文:Reference Files
原文:Microsoft 365 Agents SDK (Python)
Build enterprise agents for Microsoft 365, Teams, and Copilot Studio using the Microsoft Agents SDK with aiohttp hosting, AgentApplication routing, streaming responses, and MSAL-based authentication.
原文:Before implementation
- Use the microsoft-docs MCP to verify the latest API signatures for AgentApplication, start_agent_process, and authentication options. - Confirm package versions on PyPI for the microsoft-agents-\* packages you plan to use.
原文:Important Notice - Import Changes
> **⚠️ Breaking Change**: Recent updates have changed the Python import structure from `microsoft.agents` to `microsoft_agents` (using underscores instead of dots).
安装 / Installation
```bash pip install microsoft-agents-hosting-core pip install microsoft-agents-hosting-aiohttp pip install microsoft-agents-activity pip install microsoft-agents-authentication-msal pip install microsoft-agents-copilotstudio-client pip install python-dotenv aiohttp ```
原文:Environment Variables (.env)
```bash CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTID=<client-id> CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTSECRET=<client-secret> CONNECTIONS__SERVICE_CONNECTION__SETTINGS__TENANTID=<tenant-id> # Optional: OAuth handlers for auto sign-in AGENTAPPLICATION__USERAUTHORIZATION__HANDLERS__GRAPH__SETTINGS__AZUREBOTOAUTHCONNECTIONNAME=<connection-name> # Optional: Azure OpenAI for streaming (AAD auth via DefaultAzureCredential) AZURE_OPENAI_ENDPOINT=<endpoint> AZURE_OPENAI_API_VERSION=<version> # Optional: Copilot Studio client COPILOTSTUDIOAGENT__ENVIRONMENTID=<environment-id> COPILOTSTUDIOAGENT__SCHEMANAME=<schema-name> COPILOTSTUDIOAGENT__TENANTID=<tenant-id> COPILOTSTUDIOAGENT__AGENTAPPID=<app-id> ```
原文:Authentication & Lifecycle
> **🔑 Two rules apply to every code sample below:** > > 1. **This SDK is async-first — use `async def` handlers and `async with` throughout.** > 2. **Use explicit auth managers and context-managed network resources.** Use `MsalConnectionManager` for agent auth, and wrap per-request HTTP resources in `async with` (for example, `aiohttp.ClientSession`). > > Snippets may abbreviate this setup, but production code should always follow both rules.
文件 SHA256:cd3b4a536bab82b795960a3ba728bf74345729a6cb278a50913639d5d77609a0
仓库许可证记录:MIT;skill-declaration-captured-not-interpreted,查看来源。
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".
历史收录数据
| 来源仓库 | microsoft/skills |
|---|---|
| Skill源路径 | .github/plugins/azure-sdk-python/skills/m365-agents-py/SKILL.md |
安装前请让使用的Agent先读取这个SKILL.md及其所在目录,确认依赖和所需权限。此页不生成未经来源验证的安装命令。
