

# ツールの結果を返す
<a name="tool-use-results"></a>

ツールがアプリケーションによって呼び出されたら、最後のステップはツールの結果をモデルに返すことです。これは、ツール呼び出しの ID とレスポンスコンテンツのツール結果を返すことによって行われます。このコンテンツは [ToolResultBlock](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ToolResultBlock.html) スキーマに従います。

```
{
    "toolResult": {
        "toolUseId": tool['toolUseId'],
        "content": [{"json": {"song": song, "artist": artist}}],
        "status": "success"
    }
}
```

`ToolResultBlock` の内容は、単一の JSON またはテキストとイメージの組み合わせである必要があります。

ステータスフィールドを使用して、ツール実行のステータスをモデルに指定できます。ツールの実行が失敗した場合、失敗を示すことができ、Amazon Nova は元のツール呼び出しの変更を試みます。

スキーマの詳細については、[ToolResultContentBlock](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ToolResultContentBlock.html) のドキュメントを参照してください。

Converse API を使用してツール結果を返す方法の例を次に示します。

```
messages.append({
    "role": "user",
    "content": [
        {
            "toolResult": {
                "toolUseId": tool['toolUseId'],
                "content": [{"json": {"song": song, "artist": artist}}],
                "status": "success"
            }
        }
    ]
})

inf_params = {"maxTokens": 1000, "temperature": 0}

# Send the tool result to the model.
response = client.converse(
    modelId="us.amazon.nova-lite-v1:0",
    messages=messages,
    toolConfig=tool_config,
    inferenceConfig=inf_params
)

print(response['output']['message'])
```

ツールの活用方法の詳細については、「[Amazon Bedrock ツールの使用](https://docs.aws.amazon.com/bedrock/latest/userguide/tool-use.html)」ドキュメントを参照するか、Amazon Nova サンプルリポジトリの[ツール使用のサンプル](https://github.com/aws-samples/amazon-nova-samples/blob/main/multimodal-understanding/repeatable-patterns/10-tool-calling-with-converse/10_tool_calling_with_converse.ipynb)を参照してください。