Rest-API-Agent


标题: “Rest-API-Agent” 权重: 52


在本节中,我们将创建一个名为 Rest-API-Agent 的 Bedrock Agent,它管理外部 API 通信并处理有关狗狗品种信息的 API 响应。我们可以从以下页面了解更多关于 API 的信息: https://dog.ceo/dog-api/documentation/

说明

  1. 导航到 Bedrock Agents 页面:

  2. 为 Agent 提供名称和可选描述

    • 对于名称,输入: :code[Rest-API-Agent]{showCopyAction=true}
    • 对于描述,输入:
    管理外部 API 通信、狗狗品种、处理 API 响应
    
    • 单击 创建 继续,这将带我们进入 Agent 详细信息 页面。
  3. Agent 详细信息

    • 在 Agent 资源角色下,选择 使用现有服务角色
    • 从下拉列表中选择 AmazonBedrockExecutionRoleForAgents
    • 单击 选择模型 并从弹出页面中选择 Claude 3 Haiku,然后单击 应用
    • 对于 Agent 说明:
    我们是一个自动化代理,拥有丰富的 RESTful API 知识,能够与之无缝交互。
    我们可以分析用户请求,将其映射到适当的 API 端点,构建必要的参数,调用 API,
    并处理响应以提供准确和相关的信息。
    
    • 单击 保存
  4. 创建操作组:

    • 在操作组部分单击 添加
    • 将操作组命名为: :code[action-group-rest-api]{showCopyAction=true}
    • 选择 通过 API 架构定义 选项
    • 操作组调用 中选择 选择现有 Lambda 函数, 然后从下拉列表中选择 AgenticAI-rest-api-action
    • 操作组架构, 选择 通过内联架构编辑器定义
    • 输入以下 OpenAPI 架构:
openapi: 3.0.0
info:
  title: Dog API
  description: A public API providing a list of all dog breeds.
  version: 1.0.0
servers:
  - url: https://dog.ceo/api
    description: Dog CEO API Server
paths:
  /breeds/list/all:
    get:
      description: A public API providing a list of all dog breeds.
      summary: Get a list of all dog breeds
      operationId: getAllBreeds
      tags:
        - Breeds
      responses:
        '200':
          description: A list of all breeds
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: object
                    additionalProperties:
                      type: array
                      items:
                        type: string
                    description: A key-value list of breeds and their sub-breeds (if any).
                  status:
                    type: string
                    description: The status of the response (should be "success").
              example:
                message:
                  affenpinscher: []
                  african: []
                  airedale: []
                  akita: []
                  beagle: []
                  retriever:
                    - golden
                    - labrador
                status: success
        '500':
          description: Server error
components:
  schemas:
    BreedListResponse:
      type: object
      properties:
        message:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
          description: A list of breeds and sub-breeds
        status:
          type: string
          description: The status of the response
      example:
        message:
          affenpinscher: []
          african: []
          airedale: []
          akita: []
        status: success
tags:
  - name: Breeds
    description: Operations related to dog breeds
  • 单击 创建
  1. 保存和准备:

    • 再次单击页面右上角的 保存 按钮保存 agent。
    • 单击页面右上角的 准备 按钮准备 agent。
        请务必在每次编辑后准备 agent
      
  2. 测试 Agent:

    • 单击顶部导航栏中的 测试
    • 尝试以下示例问题:
    我们能给我列出前 10 大狗狗品种吗?
    
    • 单击 运行 测试 agent 的响应

恭喜我们! 我们已成功创建了 Rest-API-Agent,它可以与外部 API 交互并处理有关狗狗品种的响应。请继续进入下一节。