本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
OpenAPI 在 Amazon Bedrock 中為您的代理程式動作群組定義結構描述
當您在 Amazon Bedrock 中建立動作群組時,您必須定義代理程式需要從使用者叫用的參數。您也可以定義代理程式可以使用這些參數叫用的 API 操作。若要定義 API OpenAPI 操作,請以 JSON 或 YAML 格式建立結構描述。您可以建立結構描述檔案,並將其上傳至 Amazon Simple Storage Service OpenAPI (Amazon S3)。或者,您可以使用 主控台中的OpenAPI文字編輯器,以驗證您的結構描述。建立代理程式之後,您可以在將動作群組新增至代理程式或編輯現有動作群組時使用文字編輯器。如需詳細資訊,請參閱修改代理程式。
代理程式使用 結構描述來判斷其需要調用的 API 操作,以及提出 API 請求所需的參數。然後,這些詳細資訊會透過您定義的 Lambda 函數傳送,以執行動作或在客服人員呼叫的回應中傳回。
如需 API 結構描述的詳細資訊,請參閱下列資源:
-
如需OpenAPI結構描述的詳細資訊,請參閱 Swagger 網站上的OpenAPI規格
。 -
如需撰寫 API 結構描述的最佳實務,請參閱 Swagger 網站上的 API 設計最佳實務
。
以下是動作群組OpenAPI結構描述的一般格式。
{ "openapi": "3.0.0", "paths": { "/
path
": { "method
": { "description": "string
", "operationId": "string
", "parameters": [ ... ], "requestBody": { ... }, "responses": { ... }, "x-requireConfirmation": ENABLED | DISABLED } } } }
下列清單說明OpenAPI結構描述中的欄位
-
openapi
– (必要) 正在使用OpenAPI的 版本。此值必須是"3.0.0"
,動作群組才能運作。 -
paths
— (必要) 包含個別端點的相對路徑。每個路徑必須以正斜線 () 開頭/
。 -
method
— (必要) 定義要使用的方法。 -
x-requireConfirmation
– (選用) 指定在叫用動作之前是否需要使用者確認。啟用此欄位,以在叫用動作之前請求使用者確認。在叫用動作之前請求使用者確認,可能會保護您的應用程式不會因為惡意的提示注入而採取動作。根據預設,DISABLED
如果未指定此欄位,使用者確認即為 。
每個方法至少需要下列欄位:
-
description
– API 的描述。使用此欄位通知客服人員何時呼叫此 API 操作以及操作的功能。 -
operationId
– 可識別 API 中操作的唯一字串,例如函數名稱。這是所有新toolUse已啟用 的模型,例如 Anthropic Meta Llama、 Claude 3.5 Sonnet等。請確定您提供的識別符 (Id) 在所有操作中都是唯一的,並遵循簡單的英數字元模式,只有連字號或底線做為分隔符號。 -
responses
– 包含代理程式在 API 回應中傳回的屬性。代理程式使用 回應屬性來建構提示、準確處理 API 呼叫的結果,以及判斷執行任務的一組正確步驟。代理程式可以使用來自一個操作的回應值作為協調中後續步驟的輸入。
下列兩個物件中的欄位為您的代理提供更多資訊,使他們能有效利用您的動作群組。對於每個欄位,true
如果需要,請將required
欄位的值設定為 ,false
如果是選用,則設定為 。
-
parameters
— 包含可納入請求中之參數的相關資訊。 -
requestBody
— 包含操作請求內文中的欄位。請勿在GET
和DELETE
方法中包含此欄位。
若要進一步了解結構,請從下列索引標籤中選取 。
若要了解如何新增您在建立動作群組時建立的OpenAPI結構描述,請參閱 在 Amazon Bedrock 中將動作群組新增至您的代理程式。
API 結構描述範例
下列範例提供 YAML 格式的簡單OpenAPI結構描述,以取得以攝氏為單位指定位置的天氣。
openapi: 3.0.0 info: title: GetWeather API version: 1.0.0 description: gets weather paths: /getWeather/{location}/: get: summary: gets weather in Celsius description: gets weather in Celsius operationId: getWeather parameters: - name: location in: path description: location name required: true schema: type: string responses: "200": description: weather in Celsius content: application/json: schema: type: string
下列範例 API 結構描述會定義一組 API 操作,以協助處理保險索賠。三個 APIs定義如下:
-
getAllOpenClaims
– 如果需要開啟的宣告清單,您的客服人員可以使用description
欄位來判斷是否應呼叫此 API 操作。properties
在responses
中指定傳回 ID 和保單持有人和理賠的狀態。代理會將此資訊傳回給代理使用者,或使用部分或全部回應,以當做後續 API 呼叫的輸入。 -
identifyMissingDocuments
– 如果必須為保險索賠識別缺少的文件,您的代理可以使用description
欄位來判斷是否應呼叫此 API 操作。name
、description
和required
欄位會告訴代理,必須向客戶取得未結索賠的唯一識別碼。properties
在responses
中指定傳回未結保險理賠的 ID。代理程式會傳回此資訊給最終使用者,或使用部分或全部回應做為後續 API 呼叫的輸入。 -
sendReminders
– 您的客服人員可以使用description
欄位,判斷如果需要向客戶傳送提醒,應該呼叫此 API 操作。例如,有關待處理文件的提醒,這些文件具有開放的宣告。properties
中的 會requestBody
告知客服人員,其必須找到宣告 IDs和待定文件。properties
中的 會responses
指定 傳回提醒的 ID 及其狀態。代理程式會傳回此資訊給最終使用者,或使用部分或全部回應做為後續 API 呼叫的輸入。
{ "openapi": "3.0.0", "info": { "title": "Insurance Claims Automation API", "version": "1.0.0", "description": "APIs for managing insurance claims by pulling a list of open claims, identifying outstanding paperwork for each claim, and sending reminders to policy holders." }, "paths": { "/claims": { "get": { "summary": "Get a list of all open claims", "description": "Get the list of all open insurance claims. Return all the open claimIds.", "operationId": "getAllOpenClaims", "responses": { "200": { "description": "Gets the list of all open insurance claims for policy holders", "content": { "application/json": { "schema": { "type": "array", "items": { "type": "object", "properties": { "claimId": { "type": "string", "description": "Unique ID of the claim." }, "policyHolderId": { "type": "string", "description": "Unique ID of the policy holder who has filed the claim." }, "claimStatus": { "type": "string", "description": "The status of the claim. Claim can be in Open or Closed state" } } } } } } } } } }, "/claims/{claimId}/identify-missing-documents": { "get": { "summary": "Identify missing documents for a specific claim", "description": "Get the list of pending documents that need to be uploaded by policy holder before the claim can be processed. The API takes in only one claim id and returns the list of documents that are pending to be uploaded by policy holder for that claim. This API should be called for each claim id", "operationId": "identifyMissingDocuments", "parameters": [{ "name": "claimId", "in": "path", "description": "Unique ID of the open insurance claim", "required": true, "schema": { "type": "string" } }], "responses": { "200": { "description": "List of documents that are pending to be uploaded by policy holder for insurance claim", "content": { "application/json": { "schema": { "type": "object", "properties": { "pendingDocuments": { "type": "string", "description": "The list of pending documents for the claim." } } } } } } } } }, "/send-reminders": { "post": { "summary": "API to send reminder to the customer about pending documents for open claim", "description": "Send reminder to the customer about pending documents for open claim. The API takes in only one claim id and its pending documents at a time, sends the reminder and returns the tracking details for the reminder. This API should be called for each claim id you want to send reminders for.", "operationId": "sendReminders", "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "claimId": { "type": "string", "description": "Unique ID of open claims to send reminders for." }, "pendingDocuments": { "type": "string", "description": "The list of pending documents for the claim." } }, "required": [ "claimId", "pendingDocuments" ] } } } }, "responses": { "200": { "description": "Reminders sent successfully", "content": { "application/json": { "schema": { "type": "object", "properties": { "sendReminderTrackingId": { "type": "string", "description": "Unique Id to track the status of the send reminder Call" }, "sendReminderStatus": { "type": "string", "description": "Status of send reminder notifications" } } } } } }, "400": { "description": "Bad request. One or more required fields are missing or invalid." } } } } } }
如需OpenAPI結構描述的更多範例,請參閱 OpenAPI 網站上的 API 描述範例