将技能添加到使用 Microsoft 365 代理工具包创建的声明性代理

可以通过添加技能来增强代理的能力。 可以通过启用内置功能(如 图像生成器代码解释器)或添加 API 插件 作为自定义作来添加技能。

重要

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

将映像生成器添加到代理

映像生成器功能使代理能够根据用户提示生成图像。

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

    {
      "name": "GraphicArt"
    }
    

    有关详细信息,请参阅 图形艺术对象

  2. 在代理工具包的“生命周期”窗格中选择“预配”。

声明性代理将能够在重新加载页面后生成图像。

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

将代码解释器添加到代理

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

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

    {
      "name": "CodeInterpreter"
    }
    

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

  2. 在代理工具包的“生命周期”窗格中选择“预配”。

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

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

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

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

API 插件通过允许代理与 REST API 交互,将新功能添加到代理。

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

  1. 在“代理工具包”的“开发”窗格中选择“添加作”。

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

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

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

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

  5. 选择 “manifest.json”。

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

  7. 在代理工具包的“生命周期”窗格中选择“预配”。

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

显示包含 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 副驾驶®的声明性代理指南。 熟悉声明性代理的功能后,可以在以下文章中详细了解声明性代理。