翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
Amazon Bedrock でエージェントのアクショングループの OpenAPI スキーマを定義する
Amazon Bedrock でアクショングループを作成するときは、エージェントがユーザーから呼び出す必要があるパラメータを定義する必要があります。これらのパラメータを使用してエージェントが呼び出すことができる API オペレーションを定義することもできます。API オペレーションを定義するには、JSON または YAML 形式で OpenAPI スキーマを作成します。作成した OpenAPI スキーマファイルは、Amazon Simple Storage Service (Amazon S3) にアップロードできます。または、コンソールで OpenAPI テキストエディタを使用して、スキーマを検証することもできます。エージェントを作成したら、エージェントにアクショングループを追加するときや、既存のアクショングループを編集するときに、テキストエディタを使用できます。詳細については、「エージェントを変更する」を参照してください。
エージェントはスキーマを使用して、呼び出す必要がある API オペレーションと、API リクエストの実行に必要なパラメータを決定します。その後、これらの詳細は、アクションを実行するために定義した Lambda 関数を介して送信されるか、エージェントの呼び出しのレスポンスで返されます。
API スキーマの詳細については、以下の関連リソースを参照してください。
-
OpenAPI スキーマの詳細については、Swagger ウェブサイトの「OpenAPI Specification
」を参照してください。 -
API スキーマを作成するときのベストプラクティスについては、Swagger ウェブサイトの「Best Practices in API Design
」を参照してください。
アクショングループの 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 内のオペレーションを識別する一意の文字列。これは、Anthropic Claude 3.5 Sonnet や Meta Llama など、すべての新しい toolUse 対応モデルにおいて必須フィールドです。指定した識別子 (ID) がすべてのオペレーションで一意であり、ハイフンまたはアンダースコアのみを区切り文字として単純な英数字パターンに従っていることを確認します。 -
responses
– API レスポンスでエージェントが返すプロパティが含まれます。エージェントは、レスポンスプロパティを使用してプロンプトを作成し、API コールの結果を正確に処理して、タスクを実行するための正しい一連のステップを決定します。エージェントは、1 つのオペレーションからのレスポンス値を、オーケストレーションでの後続のステップの入力として使用できます。
次の 2 つのオブジェクト内のフィールドは、エージェントがアクショングループを効果的に活用するためのより多くの情報を提供します。フィールドごとに、必須の場合は required
フィールドの値を true
に設定し、オプションの場合は 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 オペレーションのグループを定義しています。3 つの API は次のように定義されます。
-
getAllOpenClaims
— エージェントはdescription
フィールドを使用して、未解決の請求のリストが必要な場合にこの API オペレーションを呼び出す必要があるかどうかを判断できます。responses
のproperties
には、ID、保険契約者、請求のステータスを返すよう指定されています。エージェントはこの情報をエージェントユーザーに返すか、レスポンスの一部または全部を後続の API コールの入力として使用します。 -
identifyMissingDocuments
— エージェントはdescription
フィールドを使用して、保険金請求に関して不足しているドキュメントを特定する必要がある場合にこの API オペレーションを呼び出す必要があるかどうかを判断できます。name
、description
、およびrequired
フィールドは、未解決請求の固有識別子をカスタマーから引き出す必要があることをエージェントに伝えます。responses
のproperties
には、未解決の保険金請求の ID を返すよう指定します。エージェントはこの情報をエンドユーザーに返すか、レスポンスの一部または全部を後続の API コールの入力として使用します。 -
sendReminders
— エージェントはdescription
フィールドを使用して、顧客にリマインダーを送信する必要がある場合にこの API を呼び出す必要があるかどうかを判断できます。例えば、未解決の請求に関する保留中のドキュメントについてのリマインダーなどです。requestBody
のproperties
は、請求 ID と保留中のドキュメントを見つける必要があることをエージェントに伝えます。responses
のproperties
は、リマインダーの 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 の説明の例