主题
将 Teams 与 agent 集成
通过自带你的 Azure Bot,将 LangSmith Fleet 连接到 Microsoft Teams,让 agent 能够在 Teams 中与用户通信。
借助 LangSmith Fleet,你可以通过注册一个自定义 Azure Bot 将你的 agent 连接到 Microsoft Teams。一旦连接,你的 agent 就能:
- 接收来自 Teams 用户的消息,用该消息内容启动一次新运行。
- 使用 Bot Framework 直接在 Teams 对话中回应。
- 通过 Microsoft Graph API 工具访问 Teams 频道和消息。
NOTE
在频道对话中,bot 只有在被明确提及时才回应。在直接消息和群聊中,bot 会对所有消息作出回应。
前置条件
创建一个 Azure Bot
在 Fleet 中注册之前,你需要创建一个 Azure Bot 资源并获取其凭据。
Create an Azure Bot resource
- 前往 Azure Portal。
- 搜索 Azure Bot 并点击 Create。
- 填写必填字段:
- Bot handle:你的 bot 的唯一标识符。
- Subscription:选择你的 Azure 订阅。
- Resource group:创建一个新的或选择一个现有的。
- Type of App:选择 Multi Tenant。
- Creation type:选择 Create new Microsoft App ID。
- 点击 Review + create,然后 Create。
Get your app credentials
资源创建后:
- 导航到你的 bot 资源,并在左侧边栏点击 Configuration。
- 复制 Microsoft App ID。你稍后会需要它。
- 点击 App ID 旁边的 Manage Password。
- 点击 New client secret,添加一个描述,并点击 Add。
- 立即复制新密钥的 Value——它只显示一次。
WARNING
在创建后立即复制该客户端密钥值。你之后无法再取回它。如果你丢失了它,必须创建一个新的。
Configure the messaging endpoint
你将在 Fleet 中注册 bot 之后再设置消息端点。暂时跳过此字段——你稍后会回到这一步。
在 Fleet 中注册 bot
Open the integrations page
- 在 LangSmith UI中导航到 Fleet。
- 前往 Integrations 页面。
- 点击 Add Teams App。
Enter your credentials
填写以下字段:
- App Name:bot 在 Fleet 中的一个显示名称。
- Azure App ID:来自 Azure Bot 资源的 Microsoft App ID。
- Azure App Password:你先前复制的客户端密钥值。
- Azure Tenant ID(可选):你的 Azure AD 租户 ID。对于多租户 bot 保持默认。
点击 Create 以注册 bot。
Copy the webhook URL
注册后,Fleet 会显示一个 webhook URL。复制这个 URL——你需要它来完成 Azure Bot 配置。
Set the messaging endpoint in Azure
- 在 Azure Portal中返回你的 Azure Bot 资源。
- 前往 Configuration。
- 将来自 Fleet 的 webhook URL 粘贴到 Messaging endpoint 字段中。
- 点击 Apply。
将 bot 添加到 Teams
Open the Teams channel
- 在 Azure Portal 中,前往你的 bot 资源。
- 在左侧边栏点击 Channels。
- 选择 Microsoft Teams 并点击 Apply。
- 同意服务条款。
Install the bot in Teams
- 在 Teams 中,在左侧边栏点击 Apps。
- 点击 Manage your apps,然后 Upload an app。
- 上传一个引用你 Azure App ID 的 Teams 应用清单,或使用来自 Azure Bot Channels 页面的 Open in Teams 链接。
- 将 bot 添加到所需的团队或聊天。
将 bot 链接到一个 agent
你可以从集成页面或从 agent 侧边栏将一个 Teams bot 链接到一个 agent。
从集成页面链接
- 导航到 Fleet 中 Integrations 页面上的 Teams Apps 部分。
- 选择你要链接的 bot。
- 从下拉菜单中,选择你要链接到的 agent。
从 agent 侧边栏链接
- 在左侧导航中从 My Agents 选择你的 agent。
- 在侧边栏中,展开 Channels 抽屉。
- 选择 Teams。
- 从下拉菜单中,选择你要链接的 Teams 应用。
添加 Teams 工具
工具让你的 agent 能够在 Teams 中采取行动。要响应消息并与 Teams 交互,添加相关的工具。
TIP
你也可以要求你的 agent 自己添加这些工具。在 agent 聊天中,试试:"Add the Teams tools so you can respond to messages."
- 在侧边栏中,展开 Connections 抽屉并点击 Add connection。
- 搜索 "Teams" 并添加你需要的工具:
- teams_bot_send_proactive_message:将消息发回 Teams 对话
- microsoft_teams_list_my_teams:列出已认证用户所属的团队
- microsoft_teams_list_channels:列出团队中的频道
- microsoft_teams_post_channel_message:向频道发布一条消息
- microsoft_teams_read_channel_messages:读取频道中最近的消息
- 如果提示,点击 Connect 以授权 Microsoft Graph 工具。
NOTE
teams_bot_send_proactive_message 工具使用 Bot Framework 凭据,不需要单独的 OAuth 授权。其他 Teams 工具使用 Microsoft Graph API,可能需要 OAuth 同意。
配置 agent 行为(可选)
你的 agent 需要知道如何处理传入的 Teams 消息。通过直接在 agent 聊天中提示它来更新其指令:
Update your instructions to handle the Teams Trigger and Teams Tools
for bidirectional communication根据你的使用场景调整这些指令——例如,你可能希望 agent 只回应某些类型的问题,或在回复前从特定来源拉取信息。
故障排查
agent 不回应
- 检查 Fleet 中的线程,看是否有任何需要人工输入的批准。
- 在频道对话中,确保你 @提及 了 bot。未带提及的频道消息会被忽略。
- 检查 Feed 标签中的错误。
- 核实 Azure Bot 资源中的消息端点与来自 Fleet 的 webhook URL 相匹配。
- 确保 bot 注册在 Fleet 中未被暂停。
注册期间出现无效凭据错误
- 核实 Azure App ID 和 App Password(客户端密钥)是否正确。
- 确保客户端密钥尚未过期。如有需要,在 Azure 中创建一个新的密钥。
- 检查 bot 类型在 Azure 中是否设为 Multi Tenant。
bot 在直接消息中可用但在频道中不可用
- bot 必须在频道对话中被明确 @提及。
- 确保该 bot 已被添加到团队,并有权读取频道中的消息。