

# ツールの使用方法
<a name="speech-tools-use"></a>

**注記**  
このドキュメントは Amazon Nova バージョン 1 を対象としています。Amazon Nova 2 Sonic ガイドについては、「[ツールの設定](https://docs.aws.amazon.com/nova/latest/nova2-userguide/sonic-tool-configuration.html)」を参照してください。

ツールを使用するには、セッション設定の `promptStart` イベントの一部として定義する必要があります。次の例で示します。

```
{
  "event": {
    "promptStart": {
      "promptName": "string",
      "textOutputConfiguration": {
        "mediaType": "text/plain"
      },
      "audioOutputConfiguration": {
        "mediaType": "audio/lpcm",
        "sampleRateHertz": 8000 | 16000 | 24000,
        "sampleSizeBits": 16,
        "channelCount": 1,
        "voiceId": "matthew" | "tiffany" | "amy",
        "encoding": "base64",
        "audioType": "SPEECH"
      },
      "toolUseOutputConfiguration": {
        "mediaType": "application/json"
      },
      "toolConfiguration": {
        "tools": [
          {
            "toolSpec": {
              "name": "string",
              "description": "string",
              "inputSchema": {
                "json": "{}"
              }
            }
          }
        ]
      }
    }
  }
}
```

## ツール定義コンポーネント
<a name="speech-tools-definition"></a>

各ツール仕様には、次の要素が必要です。
+ **名前** – ツールの一意の識別子。
+ **説明** – ツールの動作と使用するタイミングについての説明。
+ **入力スキーマ** – 必要なパラメータを定義する JSON スキーマ。

## 基本的なツールの例
<a name="speech-tools-example"></a>

現在の日付に関する情報を取得するシンプルなツールの例を次に示します。ツールの定義方法の詳細については、「[ツールの定義](https://docs.aws.amazon.com/nova/latest/userguide/tool-use-definition.html)」を参照してください。

```
// A simple tool with no required parameters
const dateTool = {
  toolSpec: {
    name: "getDateTool",
    description: "Get information about the current date",
    inputSchema: {
      json: JSON.stringify({
        type: "object",
        properties: {},
        required: []
      })
    }
  }
};
```

`promptStart` イベントは次のようになります。

```
{
  event: {
    promptStart: {
      promptName: "string",
      textOutputConfiguration: {
        mediaType: "text/plain"
      },
      audioOutputConfiguration: {
        mediaType: "audio/lpcm",
        sampleRateHertz: 24000,
        sampleSizeBits: 16,
        channelCount: 1,
        voiceId: "tiffany",
        encoding: "base64",
        audioType: "SPEECH"
      },
      toolUseOutputConfiguration: {
        mediaType: "application/json"
      },
      toolConfiguration: {
        tools: [
          {
            toolSpec: {
              name: "getDateTool",
              description: "get information about the current date",
              inputSchema: {
                json: JSON.stringify({
                  type: "object",
                  properties: {},
                  required: []
                })
              }
            }
          }
        ]
      }
    }
  }
}
```