将 API 工具添加到代理

重要

本文中的某些信息与预发行的产品有关,该产品在商业发布之前可能有重大修改。 Microsoft 对此处所提供的信息不作任何明示或默示的保证。

代理开发人员通常需要发出 HTTP 请求来生成完整的用例。

此示例创建一个代理,该代理连接到 REST API,该 API 使用名为 freeipapi.com 的服务,该服务提供异地 IP 查找服务。 如果运行此代理,请确保使用测试数据而不是敏感数据。

整个过程如下:

  • 步骤 1:创建并发布定义 API 的 OpenAPI 规范
  • 步骤 2:创建清单文件并将其上传到Security Copilot
  • 步骤 3:创建并上传使用该插件的代理

步骤 1:创建和发布 OpenAPI 规范

该示例与免费 IP REST API 集成以执行 IP 地址地理位置查找。 必须在线发布此规范 (GitHub gist) 运行良好。 请参阅以下示例来创建和托管规范。

openapi: 3.0.0

info:
    title: Free IP API
    description: A free IP lookup API
    version: "v1"

servers:
    - url: https://freeipapi.com/api/

paths:
    /json/{ipaddress}:
        get: 
            operationId: lookupIpAddressGeolocation
            summary: Lookup IP Address Geolocation information
            parameters:
                - in: path
                  name: ipaddress
                  schema:
                      type: string
                  required: true
                  description: The ip address to lookup
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: "#/components/schemas/lookupIpAddressGeolocationResponse"

components:
    schemas:
        lookupIpAddressGeolocationResponse:
            type: object
            properties:
                ipVersion:
                    type: integer
                    description: The IP address version
                ipAddress:
                    type: string
                    description: The IP address
                latitude:
                    type: number
                    description: The latutude
                longitude:
                    type: number
                    description: The longitude
                countryName:
                    type: string
                    description: The country
                zipCode:
                    type: string
                    description: The zip code
                cityName:
                    type: string
                    description: The city
                regionName:
                    type: string
                    description: The region
                continent:
                    type: string
                    description: The continent

步骤 2: (插件) 创建并上传 API 清单

  1. 创建名为 http_manifest.yaml 的文件,该文件采用工具格式 API

    Descriptor:
      Name: DCA_SampleAPIPlugin
      DisplayName: TESTDCA_Free IP API
      Description: Skills for looking up geolocation information for an IP address using the Free IP API
    
    SkillGroups:
      - Format: API
        Settings:
          OpenApiSpecUrl: <Reference to your openapi.yaml schema created in Step 1>
    
  2. 将 yaml 上传到 Security Copilot。 有关上传 YAML 的说明,请参阅 生成代理清单

    注意

    需要完成插件的安装步骤才能使用并显示在 “自定义 ”部分中。 仅当清单 YAML 具有代理定义 () AgentDefinitions 定义时,上传的 YAML 或清单才会作为代理发布到 Active 代理。

  3. 可以通过导航到 提示 中的“系统功能”来测试此工具或插件,然后搜索 lookupIpAddressGeolocation,这是operationId步骤 1 中定义的 API 规范中的值。

    Security Copilot中的工具查找图像

    显示执行该工具后的响应。

    Security Copilot中的工具运行响应的图像

步骤 3:创建并上传使用 API 插件的代理

现在,上传使用 API 插件的代理。

  1. 上传代理时,请确保在“添加插件”屏幕中选择“此工作区中的任何人”。
  2. 将代理 YAML 上传到Security Copilot。

有关使用 API 工具的 YAML 示例,请参阅 使用多个工具生成代理。 此示例提供有关如何上传代理、在活动代理中设置和运行代理的说明。