向使用 Microsoft 365 Agents Toolkit 创建的声明式代理添加功能和自定义操作

提示

受到推崇的: 从 Work IQ 开发工具 开始,用于受支持的专业代码声明代理和插件方案。 请参阅 WIQD 快速入门。 基于工具包的说明仍然可用于需要它们的现有项目和工作流。 在选择工具之前,请检查 功能和目标体验支持 : WIQD 不面向自定义引擎代理。

可以通过添加功能或自定义操作来增强代理的能力。 可以通过启用内置功能(如 图像生成器 或 代码解释器)或添加 MCP 或 API 插件 作为自定义操作来增强代理。 本教程将添加一个 API 插件。 若要添加 MCP 服务器,请参阅 构建或重用 MCP 服务器 和从 MCP 服务器构建声明性代理插件。

重要

本指南假定你已完成使用 Microsoft 365 代理工具包和 JSON 创建声明性代理 教程。

将映像生成器添加到代理

图像生成器功能使代理能够根据用户提示生成图像。 要添加图像生成器,请执行以下操作:

  1. 打开文件 appPackage/declarativeAgent.json 并将条 GraphicArt 目添加到数组中 capabilities 。 有关详细信息,请参阅 图形艺术对象。

    {
      "name": "GraphicArt"
    }
    
  2. 在 Microsoft 365 代理工具包的“ 生命周期 ”窗格中,选择 “预配”。

声明性代理可以在重新加载页面后生成图像。

注意

映像生成器不适用于 Microsoft 365 政府社区云高 (GCCH) 环境中的代理。

显示来自包含生成的图形艺术的声明性代理的响应的屏幕截图

向代理添加代码解释器

代码解释器是一种高级工具,旨在通过 Python 代码解决复杂任务。

注意

在 GCCH 环境中,代码解释器仅适用于具有智能 智能 Microsoft 365 Copilot 副驾驶® 副驾驶®加载项许可证的用户。

  1. 打开文件 appPackage/declarativeAgent.json 并将条 CodeInterpreter 目添加到数组中 capabilities 。

    {
      "name": "CodeInterpreter"
    }
    

    有关详细信息,请参阅 代码解释器对象。

  2. 在 Agents Toolkit 的生命周期窗格中选择预配。

声明性代理在重新加载页面后具有代码解释器功能。

显示声明性代理的响应(其中包含生成的图形)的屏幕截图

显示用于生成请求的图形的 Python 代码的屏幕截图

将 API 插件作为自定义操作添加到代理

API 插件允许代理与 REST API 交互,从而为代理添加新功能。

注意

GCCH 环境中不支持自定义操作。

在开始之前,创建一个名为 posts-api.ymlPosts API OpenAPI 说明文档的文件并添加代码。

  1. 在 Agents Toolkit 的“开发”窗格中选择“添加操作”。

  2. 选择“ 开始使用 OpenAPI 说明文档”。

  3. 选择“ 浏览 ”并浏览到文件 posts-api.yml 。

  4. 选择所有可用的 API,然后选择“ 确定”。

    Visual Studio Code 中“API 选择”对话框的屏幕截图

  5. 选择 manifest.json。

  6. 查看对话框中的警告。 准备好继续操作后,选择“ 添加”。

  7. 在 Agents Toolkit 的生命周期窗格中选择预配。

声明性代理有权访问您的插件内容,以便在您重新加载页面后生成其答案。

显示来自包含 API 插件内容的声明性代理的响应的屏幕截图

帖子 API OpenAPI 说明文档

以下 OpenAPI 说明适用于 JSONPlaceHolder API,这是一个免费的在线 REST API,可在需要一些虚假数据时使用。

openapi: '3.0.2'
info:
  title: Posts API
  version: '1.0'
servers:
- url: https://jsonplaceholder.typicode.com/

components:
  schemas:
    post:
      type: object
      properties:
        userId:
          type: integer
          description: The ID of the user that authored the post.
        id:
          type: integer
        title:
          type: string
        body:
          type: string
    user:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        username:
          type: string
        email:
          type: string
        phone:
          type: string
        website:
          type: string
        address:
          $ref: '#/components/schemas/address'
        company:
          $ref: '#/components/schemas/company'
    address:
      type: object
      properties:
        street:
          type: string
        suite:
          type: string
        city:
          type: string
        zipcode:
          type: string
        geo:
          $ref: '#/components/schemas/coordinates'
    coordinates:
      type: object
      properties:
        lat:
          type: string
          description: The latitude of the location
        lng:
          type: string
          description: The longitude of the location
    company:
      type: object
      properties:
        name:
          type: string
        catchPhrase:
          type: string
        bs:
          type: string
  parameters:
    post-id:
      name: post-id
      in: path
      description: 'key: id of post'
      required: true
      style: simple
      schema:
        type: integer
    user-id:
      name: user-id
      in: path
      description: 'key: id of user'
      required: true
      style: simple
      schema:
        type: integer

paths:
  /posts:
    get:
      description: Get posts
      operationId: GetPosts
      parameters:
      - name: userId
        in: query
        description: Filter results by user ID
        required: false
        style: form
        schema:
          type: integer
          maxItems: 1
      - name: title
        in: query
        description: Filter results by title
        required: false
        style: form
        schema:
          type: string
          maxItems: 1
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/post'
    post:
      description: 'Create post'
      operationId: CreatePost
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/post'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/post'
  /posts/{post-id}:
    get:
      description: 'Get post by ID'
      operationId: GetPostById
      parameters:
      - $ref: '#/components/parameters/post-id'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/post'
    patch:
      description: 'Update post'
      operationId: UpdatePost
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/post'
      parameters:
      - $ref: '#/components/parameters/post-id'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/post'
    delete:
      description: 'Delete post'
      operationId: DeletePost
      parameters:
      - $ref: '#/components/parameters/post-id'
      responses:
        '200':
          description: OK
  /users:
    get:
      summary: Get users
      description: Returns details about users
      operationId: GetUsers
      parameters:
      - name: name
        in: query
        description: The user's real name
        schema:
          type: string
      - name: username
        in: query
        description: The user's login name
        schema:
          type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/user'
  /users/{user-id}:
    get:
      description: 'Get user by ID'
      operationId: GetUserById
      parameters:
      - $ref: '#/components/parameters/user-id'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/user'

你已完成智能 智能 Microsoft 365 Copilot 副驾驶® 副驾驶®的声明式代理指南。 熟悉声明式代理的功能后,可以在以下文章中了解有关声明式代理的详细信息。