

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 傳回工具結果
<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)。