在 Google Cloud Platform (GCP) 中构建一个部署的 Agent 365 代理

重要

你需要是边境预览计划的一部分,才能提前访问 Microsoft Agent 365。 边界将你直接与Microsoft最新的 AI 创新联系起来。 边境预览版受客户协议现有预览条款的约束。 由于这些功能仍在开发中,其可用性和功能可能会随时间而变化。

学习如何使用 Agent 365 CLIGoogle Cloud Run 上构建、托管、注册和发布运行的 Agent 365 代理。 Microsoft Entra & Graph 提供代理身份、权限和蓝图,而 Google Cloud Run 则提供运行时。

如果你只是想让你的代理指向托管在 AWS 端点后的代码,你只需要这个额外步骤: 配置非 Azure 托管 ,然后按照 Agent 365 开发生命周期中的其他步骤作。

目标

学习如何使用 Agent 365 和 Microsoft 365 作为“控制平面”,并:

  • Deploy agent runtime on Google Cloud Run
  • Configure a365.config.json for non-Azure hosting
  • 在Entra ID中创建代理蓝图
  • 配置 OAuth2 + 继承权限
  • 指向GCP的注册机器人框架消息终端
  • 创建代理身份 + 代理用户
  • 发布到 Microsoft 365 应用表面
  • 端到端测试交互

先决条件

开始之前,确保满足以下Azure / Microsoft 365、Google Cloud Platform(GCP)及本地环境的先决条件。

Azure / Microsoft 365 prerequisites

确认您的 Microsoft Entra 租户访问权限,并安装以下工具以创建身份、蓝图并注册您的代理。

GCP先修条件

  • 创建了GCP项目

  • 启用Cloud Run API

  • gcloud SDK 已安装并认证:

    gcloud auth login
    gcloud config set project <GCP_PROJECT_ID>
    gcloud config set run/region us-central1   # or your preferred region
    

本地发展环境的前提条件

创建并部署代理365 Agent到云运行

本例使用了一个最小示例代理,满足:

  • 响应GET /
  • 接受POST上的机器人框架活动 /api/messages

创建项目

按照这些步骤搭建一个最小 Node.js 代理,运行在Cloud Run上并接受机器人框架活动。

  1. 创建项目目录

    mkdir gcp-a365-agent
    cd gcp-a365-agent
    
  2. 初始化节点项目

    npm init -y
    npm install express body-parser
    
  3. 创造 index.js

    const express = require("express");
    const bodyParser = require("body-parser");
    
    const app = express();
    app.use(bodyParser.json());
    
    app.get("/", (req, res) => {
    res.status(200).send("GCP Agent is running.");
    });
    
    // Bot Framework Activity Handler
    app.post("/api/messages", (req, res) => {
    console.log("Received activity:", JSON.stringify(req.body, null, 2));
    
    // Echo activity
    const reply = {
       type: "message",
       text: `You said: ${req.body?.text}`
    };
    
    res.status(200).send(reply);
    });
    
    const port = process.env.PORT || 8080;
    app.listen(port, () => console.log("Server listening on port " + port));
    

部署到 Google Cloud Run

用 在 gcloud run deploy Cloud Run 上构建和运行服务,然后记录你的 messagingEndpoint.

  1. 请使用以下命令将您的项目部署到 Google Cloud Run:

    gcloud run deploy gcp-a365-agent `
    --source . `
    --region us-central1 `
    --platform managed `
    --allow-unauthenticated
    
  2. 完成后,记下你的终点:

    https://gcp-a365-agent-XXXX-uc.run.app
    

    该 URL 是 messagingEndpoint Agent 365 开发工具 CLI 在下一步中使用的。

Configure for Non-Azure Hosting

在你的Cloud Run项目文件夹中通过运行:a365.config.jsona365 config init

{
  "tenantId": "YOUR_TENANT_ID",
  "subscriptionId": "YOUR_AZURE_SUBSCRIPTION_ID",
  "resourceGroup": "a365-gcp-demo",
  "location": "westus",
  "environment": "prod",

  "messagingEndpoint": "https://gcp-a365-agent-XXXX-uc.run.app/api/messages",
  "needDeployment": false,

  "agentIdentityDisplayName": "MyGcpAgent Identity",
  "agentBlueprintDisplayName": "MyGcpAgent Blueprint",
  "agentUserDisplayName": "MyGcpAgent User",
  "agentUserPrincipalName": "mygcpagent@testTenant.onmicrosoft.com",
  "agentUserUsageLocation": "US",
  "managerEmail": "myManager@testTenant.onmicrosoft.com",

  "deploymentProjectPath": ".",
  "agentDescription": "GCP-hosted Agent 365 Agent"
}

下表总结了重要的配置字段及其用途。

领域 Meaning
messagingEndpoint 你的云运行URL + /api/messages
"needDeployment"=false 告诉CLI:“我自己托管服务器;不要部署到 Azure。
deploymentProjectPath 冲压发生的地方.env

构建代理365代理

一旦你的代理代码在 AWS 端点上运行,按照 Agent 365 开发生命周期 中的剩余步骤设置你的 Agent 365。

端到端验证代理

通过这些检查确认您的GCP托管代理可联系,接收机器人框架活动,并在Agent 365表面上正确响应。

验证云运行连接情况

发送GET请求到messagingEndpoint你的:a365.config.json

curl https://gcp-a365-agent-XXXX.run.app/

响应机构应包括:

GCP Agent is running.

查看云运行日志中的机器人框架消息

你可以查看 Google Cloud 日志资源管理器或运行:

gcloud run services logs read gcp-a365-agent --region <your region> --limit 50

消息发送到您的代理后,您应该会看到:

POST 200 /api/messages
Received activity: { ... }

365号试剂表面的测试剂

根据你的环境:

  • 代理操场
  • Teams(如已发布)
  • 特工壳牌

你现在可以发送消息并验证你的云运行日志。 你还可以 学习如何使用 Microsoft Agent 365 SDK 测试代理,并用 Agents Playground 测试工具验证代理的功能

开发者工作流程

设置完成后,按照以下工作流程进行迭代开发:

  1. 更改你的代理代码

    先修改代码,保存并在本地测试,然后再部署。

  2. 重新部署到 Google Cloud Run

    gcloud run deploy gcp-a365-agent --source .
    
  3. 测试和监视

    通过Agent 365测试表面并监控Google Cloud Run日志。

    注释

    你的身份、蓝图、机器人端点和权限不需要重新创建。

Troubleshooting

请使用本节诊断在 Google Cloud Run 部署和运行 Agent 365 代理时的常见问题,并快速修复连接、配置和许可问题。

消息终端没有受到影响

请查看以下详情:

  • 端点恰好是:
    https://<cloud-run-url>/api/messages
  • Cloud Run 允许无需认证的访问
  • 没有防火墙规则

许可证转让失败

手动分配有效的 Microsoft 365 frontier 许可证,或者如果支持,可以使用无许可的用户路径。

获取帮助

更多帮助选项

请考虑以下几点以寻求帮助: