

# 返回工具结果
<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)。