

# 도구 정의
<a name="tool-use-definition"></a>

도구 직접 호출 워크플로에서 중요한 단계는 도구를 정의하는 것입니다. 도구 정의에는 모델이 도구를 간접적으로 호출하기에 적절한 경우를 안내하는 데 필요한 모든 컨텍스트가 포함되어야 합니다.

도구를 정의하려면 도구 구성을 생성하고 사용자 메시지와 함께 API에 전달합니다. [도구 구성](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ToolConfiguration.html) 스키마에는 도구 배열과 도구 선택 파라미터(선택 사항)가 필요합니다.

**참고**  
Amazon Nova는 `toolChoice`에 대해 `auto`, `any`, `tool` 옵션을 지원합니다. 자세한 내용은 Amazon Bedrock API 설명서의 [ToolChoice](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ToolChoice.html)와 [Use a tool to complete an Amazon Bedrock model response](https://docs.aws.amazon.com/bedrock/latest/userguide/tool-use.html)를 참조하세요.

다음은 도구를 정의하는 방법의 예제입니다.

```
tool_config = {
    "tools": [
        {
            "toolSpec": {
                "name": "top_song",
                "description": "Get the most popular song played on a radio station.",
                "inputSchema": {
                    "json": {
                        "type": "object",
                        "properties": {
                            "sign": {
                                "type": "string",
                                "description": "The call sign for the radio station for which you want the most popular song. Example calls signs are WZPZ, and WKRP."
                            }
                        },
                        "required": [
                            "sign"
                        ]
                    }
                }
            }
        }
    ],
}
```

이름, 설명 및 입력 스키마는 도구의 정확한 기능과 함께 명시적이어야 합니다. 도구 사용 시기에 대한 주요 차별화 요소가 도구 구성에 반영되어 있는지 확인하세요.

**참고**  
Amazon Nova 이해 모델은 현재 Converse API에서 [ToolInputSchema](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ToolInputSchema.html)를 정의하는 데 사용될 때 JsonSchema 기능의 하위 집합만 지원합니다.  
최상위 스키마는 [객체](https://json-schema.org/understanding-json-schema/reference/object) 유형이어야 합니다.
최상위 객체에서는 유형(‘object’로 설정해야 함), [https://json-schema.org/understanding-json-schema/reference/object#properties](https://json-schema.org/understanding-json-schema/reference/object#properties), [https://json-schema.org/understanding-json-schema/reference/object#required](https://json-schema.org/understanding-json-schema/reference/object#required)의 세 가지 필드만 지원됩니다.

도구 직접 호출의 경우, 온도를 0으로 설정하여 그리디 디코딩을 사용하는 것이 좋습니다.

다음은 Converse API를 사용하여 도구를 직접적으로 호출하는 예제입니다.

```
import json
import boto3

client = boto3.client("bedrock-runtime", region_name="us-east-1")

input_text = "What is the most popular song on WZPZ?"

messages = [{
    "role": "user",
    "content": [{"text": input_text}]
}]

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

response = client.converse(
    modelId="us.amazon.nova-lite-v1:0",
    messages=messages,
    toolConfig=tool_config,
    inferenceConfig=inf_params
)

messages.append(response["output"]["message"])

# Pretty print the response JSON.
print("[Full Response]")
print(json.dumps(response, indent=2))

# Print the tool content for easy readability.
tool = next(
    block["toolUse"]
    for block in response["output"]["message"]["content"]
    if "toolUse" in block
)
print("\n[Tool Response]")
print(tool)
```