

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# ツールの使用
<a name="model-parameters-anthropic-claude-messages-tool-use"></a>

**警告**  
以下のいくつかの関数は、表示されているようにベータ版で提供されています。これらの機能は、 AWS サービス条件で定義されている「ベータサービス」として利用できます。本ライセンス条項には、 AWS および AWS サービス条件、および該当するモデル EULA とのお客様の契約が適用されます。

Anthropic Claude モデルを使用すると、モデルがメッセージの応答に使用できるツールを指定できます。例えば、ラジオ局で最も人気のある曲を取得するツールを指定できます。ユーザーが、「*WZPZ で最も人気の曲は何か?*」というメッセージを送信すると、モデルは、指定したツールが質疑応答に役立つと判断します。レスポンスでは、モデルがユーザーに代わってツールを実行することをリクエストします。次に、ツールを実行し、ツール結果をモデルに渡します。これにより、元のメッセージのレスポンスが生成されます。詳細については、「Anthropic Claude ドキュメント」の「[ツールの使用 (関数呼び出し)](https://docs.anthropic.com/en/docs/tool-use)」を参照してください。

**ヒント**  
Converse API を使用してツールの使用をアプリケーションに統合することが推奨されます。詳細については、「[ツールを使用して Amazon Bedrock のモデルレスポンスを完成させる](tool-use.md)」を参照してください。

**重要**  
Claude Sonnet 4.5 では、ツール呼び出し文字列パラメータの意図されたフォーマットが保持されるようになりました。以前は、文字列パラメータの末尾の改行が誤って削除されていました。この修正により、正確なフォーマットを必要とするツール (テキストエディタなど) が意図したとおりにパラメータを受信できるようになります。これは、API の変更を必要としない、舞台裏の改善です。ただし、文字列パラメータを持つツールは、以前は削除されていた末尾の改行がついた値を受け取ることができるようになりました。

**注記**  
Claude Sonnet 4.5 には、モデルのパフォーマンスを向上させるための自動最適化が含まれています。この最適化により、リクエストに少量のトークンが追加される場合がありますが、システムが追加したこれらのトークンには課金されません。

`tools` フィールドでモデルに使用できるようにしたいツールを指定します。次の例は、ラジオ局で最も人気のある曲を取得するツールを示しています。

```
[
    {
        "name": "top_song",
        "description": "Get the most popular song played on a radio station.",
        "input_schema": {
            "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"
            ]
        }
    }
]
```

モデルがメッセージへのレスポンスを生成するツールを必要とする場合、リクエストされたツールに関する情報と、ツールへの入力がメッセージ `content` フィールドに表示されます。また、`tool_use` へのレスポンスの停止理由も設定されます。

```
{
    "id": "msg_bdrk_01USsY5m3XRUF4FCppHP8KBx",
    "type": "message",
    "role": "assistant",
    "model": "claude-3-sonnet-20240229",
    "stop_sequence": null,
    "usage": {
        "input_tokens": 375,
        "output_tokens": 36
    },
    "content": [
        {
            "type": "tool_use",
            "id": "toolu_bdrk_01SnXQc6YVWD8Dom5jz7KhHy",
            "name": "top_song",
            "input": {
                "sign": "WZPZ"
            }
        }
    ],
    "stop_reason": "tool_use"
}
```

コードでは、ツールの代わりにツールを呼び出します。次に、ユーザーメッセージのツール結果 (`tool_result`) をモデルに渡します。

```
{
    "role": "user",
    "content": [
        {
            "type": "tool_result",
            "tool_use_id": "toolu_bdrk_01SnXQc6YVWD8Dom5jz7KhHy",
            "content": "Elemental Hotel"
        }
    ]
}
```

レスポンスでは、モデルはツール結果を使用して元のメッセージのレスポンスを生成します。

```
{
    "id": "msg_bdrk_012AaqvTiKuUSc6WadhUkDLP",
    "type": "message",
    "role": "assistant",
    "model": "claude-3-sonnet-20240229",
    "content": [
        {
            "type": "text",
            "text": "According to the tool, the most popular song played on radio station WZPZ is \"Elemental Hotel\"."
        }
    ],
    "stop_reason": "end_turn"
}
```

## きめ細かなツールストリーミング
<a name="model-parameters-anthropic-claude-messages-fine-grained-tool-streaming"></a>

きめ細かなツールストリーミングは、Claude Sonnet 4.5、Claude Haiku 4.5、Claude Sonnet 4、Claude Opus 4 で使用できる Anthropic Claude モデル機能です。きめ細かなツールストリーミングを使用すると、Claude デベロッパーはバッファリングや JSON 検証なしでツール使用パラメータをストリーミングできるため、大きなパラメータの受信が開始されるまでのレイテンシーが短縮されます。

**注記**  
きめ細かなツールストリーミングを使用する場合、無効な JSON 入力または部分的な JSON 入力を受け取る可能性があります。コードでこうしたエッジケースを考慮するようにしてください。

ツール使用リクエストに ヘッダー `fine-grained-tool-streaming-2025-05-14` を追加するだけで、この機能を使用できます。

きめ細かなツールストリーミングヘッダーを指定する方法の例を次に示します。

```
{
  "anthropic_version": "bedrock-2023-05-31",
  "max_tokens": 1024,
  "anthropic_beta": ["fine-grained-tool-streaming-2025-05-14"],
  "messages": [
    {
      "role": "user",
      "content": "Can you write a long poem and make a file called poem.txt?"
    }
  ],
  "tools": [
    {
      "name": "make_file",
      "description": "Write text to a file",
      "input_schema": {
        "type": "object",
        "properties": {
          "filename": {
            "type": "string",
            "description": "The filename to write text to"
          },
          "lines_of_text": {
            "type": "array",
            "description": "An array of lines of text to write to the file"
          }
        },
        "required": [
          "filename",
          "lines_of_text"
        ]
      }
    }
  ]
}
```

この例では、きめ細かなツールストリーミングにより、Claude はバッファリングなしで長い詩の行をツール呼び出し `make_file` にストリーミングし、`lines_of_text` パラメータが有効な JSON であるかどうかを検証できます。つまり、パラメータストリームは到着時に表示でき、パラメータ全体がバッファリングされて検証されるのを待つ必要がありません。

きめ細かなツールストリーミングでは、ツール使用チャンクのストリーミングがより速く開始され、多くの場合、チャンクが長くなり、単語の区切りが少なくなります。これは、チャンキング動作の違いによるものです。

例えば、きめ細かなストリーミングなしの場合 (15 秒の遅延):

```
Chunk 1: '{"'
Chunk 2: 'query": "Ty'
Chunk 3: 'peScri'
Chunk 4: 'pt 5.0 5.1 '
Chunk 5: '5.2 5'
Chunk 6: '.3'
Chunk 8: ' new f'
Chunk 9: 'eatur'
...
```

きめ細かなストリーミングの場合 (3 秒の遅延):

```
Chunk 1: '{"query": "TypeScript 5.0 5.1 5.2 5.3'
Chunk 2: ' new features comparison'
```

**注記**  
きめ細かなストリーミングはバッファリングや JSON 検証なしでパラメータを送信するため、結果のストリームが有効な JSON 文字列で完了するという保証はありません。特に、停止理由の `max_tokens` に達した場合、ストリームはパラメータの途中で終了し、不完全になる可能性があります。通常、`max_tokens` に達したときに処理するには、特定のサポートを記述する必要があります。

## Computer Use (ベータ版)
<a name="model-parameters-anthropic-claude-messages-computer-use"></a>

Computer Use は、Claude 3.5 Sonnet v2、Claude Sonnet 4.5、Claude Haiku 4.5、Claude 3.7 Sonnet、Claude Sonnet 4、Claude Opus 4 でのみ利用可能な新しい Anthropic Claude モデル機能 (ベータ版) です。Computer Use を使用すると、Claude は基本的な GUI アクションを通じてタスクを自動化するのに役立ちます。

**警告**  
コンピュータ使用機能は、 AWS サービス条件に定義されている「ベータサービス」として利用できます。本ライセンス条項には、 AWS および AWS サービス条件、および該当するモデル EULA とのお客様の契約が適用されます。Computer Use API には、標準の API 機能やチャットインターフェイスとは異なる固有のリスクがあることに注意してください。これらのリスクは、Computer Use API を使用してインターネットと通信するときに高くなります。リスクを最小限に抑えるには、次のような予防策を検討します。  
Computer Use 機能は、システムへの直接攻撃や事故を防ぐために、最小限の権限で専用の仮想マシンまたはコンテナで操作します。
情報の盗難を防ぐため、Computer Use API に機密アカウントまたはデータへのアクセスを許可しないでください。
Computer Use API のインターネットアクセスを必要なドメインに制限すると、悪意のあるコンテンツにさらされる状況を軽減できます。
適切な監視を行うには、機密タスク (現実の世界に重大な結果を与える意思決定など) や、肯定的合意が必要なもの (Cookie の承諾、金融取引の実行または利用規約への同意など) のループに人間を関与させます。
Claude が閲覧またはアクセスできるようにしたコンテンツは、指示をオーバーライドしたり、Claude による間違いを招いたり、意図しない動作を引き起こす場合があります。Claude を機密事項から隔離するなど、適切な予防措置を講じることは、プロンプトインジェクション関連のリスクを回避するためにも不可欠です。独自の製品で Computer Use 機能に必要なアクセス許可を有効化またはリクエストする前に、エンドユーザーに関連するリスクを通知したり、必要に応じて、エンドユーザーから合意を得ます。

Computer Use API には、事前定義されたいくつかの Computer Use ツールが用意されています。その後、「前回の会議メモを含む E メールを Ben に送信する」やスクリーンショット (必要な場合) などのリクエストを含むプロンプトを作成できます。レスポンスには、JSON 形式の `tool_use` アクションのリストが含まれます (例: scroll\$1down、left\$1button\$1press、スクリーンショット)。コードはコンピュータアクションを実行し、出力を示すスクリーンショットとともに Claude を提供します (リクエストされた場合)。

Claude 3.5 v2 のリリース以降、ツールパラメータはポリモーフィックツールタイプを承認するように更新され、これらを区別するために新しい `tool.type` プロパティが追加されました。`type` は、オプションですが、省略された場合、ツールは、カスタムツールとみなされます (以前唯一サポートされていたツールタイプ)。Computer Use にアクセスするには、対応する列挙型とともに`anthropic_beta` パラメータを使用する必要があります。パラメータ値は使用中のモデルバージョンによって異なります。詳細については、以下のテーブルを参照してください。

このパラメータと列挙型で行われたリクエストのみが、Computer Use ツールを使用できます。`"anthropic_beta": ["computer-use-2025-01-24"]` のように指定できます。


| モデル | ベータヘッダー | 
| --- | --- | 
|  Claude Opus 4.5 Claude Opus 4.1 Claude Opus 4 Claude Sonnet 4.5 Claude Haiku 4.5 Claude Sonnet 4 Claude 3.7 Sonnet  | computer-use-2025-01-24 | 
| Claude 3.5 Sonnet v2 | computer-use-2024-10-22 | 

詳細については、「Anthropic ドキュメント」の「[Computer Use (ベータ版)](https://docs.anthropic.com/en/docs/build-with-claude/computer-use)」を参照してください。

以下は、リクエストにデスクトップのスクリーンショットと Firefox アイコンが含まれていると仮定するレスポンスの例です。

```
{
    "id": "msg_123",
    "type": "message",
    "role": "assistant",
    "model": "anthropic.claude-3-5-sonnet-20241022-v2:0",
    "content": [
        {
            "type": "text",
            "text": "I see the Firefox icon. Let me click on it and then navigate to a weather website."
        },
        {
            "type": "tool_use",
            "id": "toolu_123",
            "name": "computer",
            "input": {
                "action": "mouse_move",
                "coordinate": [
                    708,
                    736
                ]
            }
        },
        {
            "type": "tool_use",
            "id": "toolu_234",
            "name": "computer",
            "input": {
                "action": "left_click"
            }
        }
    ],
    "stop_reason": "tool_use",
    "stop_sequence": null,
    "usage": {
        "input_tokens": 3391,
        "output_tokens": 132
    }
}
```

## Anthropic 定義ツール
<a name="model-parameters-anthropic-anthropic-defined-tools"></a>

Anthropic には、特定の Claude モデルがコンピュータを効果的に使用できるようになる一連のツールが用意されています。Anthropic 定義済みツールを指定する場合、`description` フィールドと `tool_schema` フィールドは必須ではなく許可されません。 Anthropic 定義済みツールは Anthropic によって定義されますが、ツールの結果を明示的に評価し、`tool_results` を Claude に返す必要があります。他のツールと同様に、モデルがツールを自動的に実行することはありません。Anthropic 定義済みの各ツールには、特定のモデル Claude 3.5 Sonnet (新規) と Claude 3.7 Sonnet 用に最適化されたバージョンがあります。


| モデル | ツール | 注意事項 | 
| --- | --- | --- | 
|  Claude Claude Opus 4.1 Claude Claude Opus 4 Claude Sonnet 4.5 Claude Haiku 4.5 Claude Sonnet 4  |  <pre>{ <br />    "type": "text_editor_20250124", <br />    "name": "str_replace_based_edit_tool" <br />}</pre>  | 既存の `str_replace_editor` ツールの更新 | 
|  Claude 3.7 Sonnet  |  <pre>{ <br />    "type": "computer_20250124", <br />    "name": "computer" <br />}</pre>  |  より正確な制御のための新しいアクションを含む  | 
|  Claude 3.7 Sonnet  |  <pre>{ <br />    "type": "text_editor_20250124", <br />    "name": "str_replace_editor"<br />}</pre>  | 20241022 バージョンと同じ機能 | 
|  Claude 3.5 Sonnet v2  |  <pre>{ <br />    "type": "bash_20250124", <br />    "name": "bash" <br />}</pre>  |  20241022 バージョンと同じ機能  | 
|  Claude 3.5 Sonnet v2  |  <pre>{ <br />    "type": "text_editor_20241022", <br />    "name": "str_replace_editor"<br />}</pre>  | 
|  Claude 3.5 Sonnet v2  |  <pre>{ <br />    "type": "bash_20241022", <br />    "name": "bash"<br />}</pre>  | 
|  Claude 3.5 Sonnet v2  |  <pre>{ <br />    "type": "computer_20241022", <br />    "name": "computer"<br />}</pre>  | 

`type` フィールドは検証目的でツールとそのパラメータを識別し、`name` フィールドはモデルに公開されるツール名です。

これらのツールのいずれかを使用するようにモデルに指示する場合は、`name` フィールドでツールを明示的に参照できます。`name` フィールドはツールリスト内で一意である必要があります。同じ API コールで Anthropic 定義済みツールと同じ `name` のツールを定義することはできません。

## 自動ツールコールクリア (ベータ版)
<a name="model-parameters-anthropic-claude-automatic-tool-call-clearing"></a>

**警告**  
自動ツールコールクリアは、 AWS サービス条件で定義されている「ベータサービス」として利用できます。

**注記**  
この機能は、現在 Claude Sonnet 4/4.5、Claude Haiku 4.5、および Claude Opus 4/4.1/4.5 でサポートされています。

自動ツールコールクリアは、Anthropic Claude モデル機能 (ベータ) です。この機能を使用すると、Claude はトークンの制限に近づいたときに古いツールの使用結果を自動的にクリアできるため、マルチターンツールの使用シナリオでより効率的なコンテキスト管理が可能になります。ツール使用クリアを使用するには、anthropic\$1beta リクエストパラメータのベータヘッダーのリストに `context-management-2025-06-27` を追加する必要があります。また、 の使用を指定`clear_tool_uses_20250919`し、次の設定オプションから選択する必要があります。

`clear_tool_uses_20250919` コンテキスト管理戦略で使用できるコントロールは次のとおりです。すべてにオプションまたはデフォルトがあります。


| **設定オプション** | **説明** | 
| --- | --- | 
|  `trigger` デフォルト: 100,000 入力トークン  |  コンテキスト編集戦略がいつアクティブ化されるかを定義します。プロンプトがこのしきい値を超えると、クリアが開始されます。この値は input\$1tokens または tool\$1uses のいずれかで指定できます。  | 
|  `keep` デフォルト: 3 つのツール使用  |  クリア後に保持する最近のツールの使用/結果ペアの数を定義します。API は、最も古いツールインタラクションから先に削除し、最新のツールインタラクションを保持します。モデルが会話を効果的に継続するために最近のツールインタラクションにアクセスする必要がある場合に役立ちます。  | 
|  `clear_at_least` (オプション)  |  戦略がアクティブ化されるたびに、最小数のトークンがクリアされるようにします。API が少なくとも指定された量をクリアできない場合、戦略は適用されません。これは、コンテキストクリアが、プロンプトキャッシュを破棄する価値があるかどうかを判断するのに役立ちます。  | 
|  `exclude_tools` (オプション)  |  ツールの使用と結果をクリアしてはならないツール名のリスト。重要なコンテキストの保存に役立ちます。  | 
|  `clear_tool_inputs` (オプション、デフォルトの False)  |  ツールコールパラメータをツールの結果とともにクリアするかどうかを制御します。デフォルトでは、Claude の元のツールコールを表示したままツールの結果のみがクリアされるため、Claude は結果が削除された後でも実行されたオペレーションを確認できます。  | 

**注記**  
プレフィックスにツールが含まれている場合、ツールをクリアするとキャッシュが無効になります。

------
#### [ Request ]

```
response = client.beta.messages.create(
    betas=["context-management-2025-06-27"],
    model="claude-sonnet-4-20250514",
    max_tokens=4096,
    messages=[
        {
            "role": "user",
            "content": "Create a simple command line calculator app using Python"
       }
    ],
    tools=[
        {
            "type": "text_editor_20250728",
            "name": "str_replace_based_edit_tool",
            "max_characters": 10000
        },
       {
            "type": "web_search_20250305",
            "name": "web_search",
            "max_uses": 3
       }
    ],
    extra_body={
        "context_management": {
            "edits": [
                {
                    "type": "clear_tool_uses_20250919",
                # The below parameters are OPTIONAL:
                    # Trigger clearing when threshold is exceeded
                    "trigger": {
                        "type": "input_tokens",
                        "value": 30000
                    },
                    # Number of tool uses to keep after clearing
                    "keep": {
                        "type": "tool_uses",
                        "value": 3
                    },
                    # Optional: Clear at least this many tokens
                    "clear_at_least": {
                        "type": "input_tokens",
                        "value": 5000
                    },
                    # Exclude these tools uses from being cleared
                    "exclude_tools": ["web_search"]
                }
            ]
       }
    }
 )
```

------
#### [ Response ]

```
{
    "id": "msg_123",
    "type": "message",
    "role": "assistant",
    "content": [
        {
            "type": "tool_use",
            "id": "toolu_456",
            "name": "data_analyzer",
            "input": {
                "data": "sample data"
            }
        }
    ],
    "context_management": {
        "applied_edits": [
            {
                "type": "clear_tool_uses_20250919",
                "cleared_tool_uses": 8,  # Number of tool use/result pairs that were cleared
                "cleared_input_tokens": 50000  # Total number of input tokens removed from the prompt
            }
        ]
    }
    "stop_reason": "tool_use",
    "usage": {
        "input_tokens": 150,
        "output_tokens": 50
    }
}
```

------
#### [ Streaming Response ]

```
data: {"type": "message_start", "message": {"id": "msg_123", "type": "message", "role": "assistant"}}

data: {"type": "content_block_start", "index": 0, "content_block": {"type": "tool_use", "id": "toolu_456", "name": "data_analyzer", "input": {}}}

data: {"type": "content_block_delta", "index": 0, "delta": {"type": "input_json_delta", "partial_json": "{\"data\": \"sample"}}

data: {"type": "content_block_delta", "index": 0, "delta": {"type": "input_json_delta", "partial_json": " data\"}"}}

data: {"type": "content_block_stop", "index": 0}

data: {"type": "message_delta", "delta": {"stop_reason": "tool_use"}}

data: {"type": "message_stop"}

{
  "type": "message_delta",
  "delta": {
    "stop_reason": "end_turn",
    "stop_sequence": null,
  },
  "usage": {
    "output_tokens": 1024
  },
  "context_management": {
    "applied_edits": [...],
  }
}
```

------

**注記**  
Bedrock は現在、CountTokens API での `clear_tool_uses_20250919` コンテキスト管理をサポートしていません。

## メモリツール (ベータ版)
<a name="model-parameters-anthropic-claude-memory-tool"></a>

**警告**  
Memory Tool は、 サービス条件で定義されている「ベータ AWS サービス」として利用できます。

Claude Sonnet 4.5 には、会話全体でメモリを管理する方法を提供する新しいメモリツールが含まれています。この機能を使用すると、Claude にローカルディレクトリへのアクセスを与えてコンテキストウィンドウ外の情報を取得できるようにすることができます。これはベータ機能として利用できます。この機能を使用するには、`context-management-2025-06-27` ベータヘッダーを使用する必要があります。

ツール定義:

```
{
  "type": "memory_20250818",
  "name": "memory"
}
```

リクエストの例:

```
{
    "max_tokens": 2048,
    "anthropic_version": "bedrock-2023-05-31",
    "anthropic_beta": ["context-management-2025-06-27"],
    "tools": [{
        "type": "memory_20250818",
        "name": "memory"
    }],
    "messages": [
        {
            "role": "user",
            "content": [{"type": "text", "text": "Remember that my favorite color is blue and I work at Amazon?"}]
        }
    ]
}
```

レスポンスの例:

```
{
    "id": "msg_vrtx_014mQ5ficCRB6PEa5k5sKqHd",
    "type": "message",
    "role": "assistant",
    "model": "claude-sonnet-4-20250514",
    "content": [
        {
            "type": "text",
            "text": "I'll start by checking your memory directory and then record this important information about you."
        },
        {
            "type": "tool_use",
            "id": "toolu_vrtx_01EU1UrCDigyPMRntr3VYvUB",
            "name": "memory",
            "input": {
                "command": "view",
                "path": "/memories"
            }
        }
    ],
    "stop_reason": "tool_use",
    "stop_sequence": null,
    "usage": {
        "input_tokens": 1403,
        "cache_creation_input_tokens": 0,
        "cache_read_input_tokens": 0,
        "output_tokens": 87
    },
    "context_management": {
        "applied_edits": []
    }
}
```

## ツール使用のコストに関する考慮事項
<a name="model-parameters-anthropic-claude-tool-use-cost"></a>

ツール使用リクエストは、次の要因に基づいて料金が設定されます。

1. モデルに送信された入力トークンの合計数 (ツールパラメータを含む)

1. 生成された出力トークンの数

ツールの料金は他のすべての Claude API リクエストと同じですが、リクエストごとに追加のトークンが含まれています。ツールの使用による追加のトークンは、以下により取得されます。
+ API リクエストの `tools` パラメータ。例えば、ツール名、説明、スキーマなどです。
+ API リクエストとレスポンスのすべての `tool_use` コンテンツブロック。
+ API リクエストのすべての `tool_result` コンテンツブロック。

ツールを使用すると、Anthropic モデルにはツールの使用を可能にする特別なシステムプロンプトが自動的に含まれます。次の表は各モデルに必要なツール使用トークンの数です。この表には、前述の追加のトークンは含まれていません。この表は、ツールが少なくとも 1 つ提供されていることを前提としていることに注意してください。ツールが提供されていない場合、ツール選択なしで使用される追加のシステムプロンプトトークンは 0 個となります。


| モデル | ツールの選択 | ツール使用システムプロンプトトークン数 | 
| --- | --- | --- | 
|  Claude Opus 4.5 Claude Opus 4.1 Claude Opus 4 Claude Sonnet 4.5 Claude Haiku 4.5 Claude Sonnet 4 Claude 3.7 Sonnet Claude 3.5 Sonnet v2  | auto、または none | 346 | 
|  Claude Opus 4.5 Claude Opus 4.1 Claude Opus 4 Claude Sonnet 4.5 Claude Haiku 4.5 Claude Sonnet 4 Claude 3.7 Sonnet Claude 3.5 Sonnet v2  | any、または tool | 313 | 
|  Claude 3.5 Sonnet  | auto、または none | 294 | 
|  Claude 3.5 Sonnet  | any、または tool | 261 | 
|  Claude 3 Opus  | auto、または none | 530 | 
|  Claude 3 Opus  | any、または tool | 281 | 
|  Claude 3 Sonnet  | auto、または none | 159 | 
|  Claude 3 Sonnet  | any、または tool | 235 | 
|  Claude 3 Haiku  | auto、または none | 264 | 
|  Claude 3 Haiku  | any、または tool | 340 | 

## ツール検索ツール (ベータ)
<a name="model-parameters-anthropic-claude-tool-search-tool"></a>

ツール検索ツールを使用するとClaude、コンテキストウィンドウにすべての定義を事前にロードすることなく、数百または数千のツールを操作できます。すべてのツールをすぐに宣言する代わりに、 でマークし`defer_loading: true`、ツール検索メカニズムを通じて必要なツールのみClaudeを検索してロードできます。

この機能にアクセスするには、ベータヘッダー を使用する必要があります`tool-search-tool-2025-10-19`。この機能は現在、[InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html) API と [InvokeModelWithResponseStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModelWithResponseStream.html) API でのみ使用できます。 APIs

ツール定義:

```
{
    "type": "tool_search_tool_regex",
    "name": "tool_search_tool_regex"
}
```

リクエストの例:

```
{
    "anthropic_version": "bedrock-2023-05-31",
    "anthropic_beta": [
        "tool-search-tool-2025-10-19"
    ],
    "max_tokens": 4096,
    "tools": [{
            "type": "tool_search_tool_regex",
            "name": "tool_search_tool_regex"
        },
        {
            "name": "get_weather",
            "description": "Get current weather for a location",
            "input_schema": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string"
                    },
                    "unit": {
                        "type": "string",
                        "enum": ["celsius", "fahrenheit"]
                    }
                },
                "required": ["location"]
            },
            "defer_loading": true
        },
        {
            "name": "search_files",
            "description": "Search through files in the workspace",
            "input_schema": {
                "type": "object",
                "properties": {
                    "query": {
                        "type": "string"
                    },
                    "file_types": {
                        "type": "array",
                        "items": {
                            "type": "string"
                        }
                    }
                },
                "required": ["query"]
            },
            "defer_loading": true
        }
    ],
    "messages": [{
        "role": "user",
        "content": "What's the weather in Seattle?"
    }]
}
```

レスポンスの例

```
{
    "role": "assistant",
    "content": [{
            "type": "text",
            "text": "I'll search for the appropriate tools to help with this task."
        },
        {
            "type": "server_tool_use",
            "id": "srvtoolu_01ABC123",
            "name": "tool_search_tool_regex",
            "input": {
                "pattern": "weather"
            }
        },
        {
            "type": "tool_search_tool_result",
            "tool_use_id": "srvtoolu_01ABC123",
            "content": {
                "type": "tool_search_tool_search_result",
                "tool_references": [{
                    "type": "tool_reference",
                    "tool_name": "get_weather"
                }]
            }
        },
        {
            "type": "text",
            "text": "Now I can check the weather."
        },
        {
            "type": "tool_use",
            "id": "toolu_01XYZ789",
            "name": "get_weather",
            "input": {
                "location": "Seattle",
                "unit": "fahrenheit"
            }
        }
    ],
    "stop_reason": "tool_use"
}
```

ストリーミングの例

```
# Event 1: content_block_start(with complete server_tool_use block) {
    "type": "content_block_start",
    "index": 0,
    "content_block": {
        "type": "server_tool_use",
        "id": "srvtoolu_01ABC123",
        "name": "tool_search_tool_regex"
    }
}

# Event 2: content_block_delta(input JSON streamed) {
    "type": "content_block_delta",
    "index": 0,
    "delta": {
        "type": "input_json_delta",
        "partial_json": "{\"regex\": \".*weather.*\"}"
    }
}

# Event 3: content_block_stop(tool_use complete) {
    "type": "content_block_stop",
    "index": 0
}

# Event 4: content_block_start(COMPLETE result in single chunk) {
    "type": "content_block_start",
    "index": 1,
    "content_block": {
        "type": "tool_search_tool_result",
        "tool_use_id": "srvtoolu_01ABC123",
        "content": {
            "type": "tool_search_tool_search_result",
            "tool_references": [{
                "type": "tool_reference",
                "tool_name": "get_weather"
            }]
        }
    }
}

# Event 5: content_block_stop(result complete) {
    "type": "content_block_stop",
    "index": 1
}
```

**カスタムツール検索ツール**  
`tool_reference` ブロックを返すツールを定義することで、カスタムツール検索ツールを実装できます (埋め込みの使用など）。カスタムツールには が必要です`defer_loading: false`が、他のツールには が必要です`defer_loading: true`。独自のツール検索ツールを定義すると、Claude使用するツールを指す`tool_reference`コンテンツブロックを含むツールの結果が返されます。

カスタマー定義のツール検索ツールの結果レスポンス形式:

```
{
    "type": "tool_result",
    "tool_use_id": "toolu_01ABC123",
    "content": [{
            "type": "tool_reference",
            "tool_name": "get_weather"
        },
        {
            "type": "tool_reference",
            "tool_name": "weather_forecast"
        }
    ]
}
```

は、 のリクエストで定義されたツールと一致する`tool_name`必要があります`defer_loading: true`。Claude は、これらのツールの完全なスキーマにアクセスできます。

**カスタム検索ツール - 詳細な例**  
`tool_reference` ブロックを返すツールを定義することで、カスタムツール検索ツールを実装できます (埋め込みやセマンティック検索など）。これにより、正規表現マッチングを超えた高度なツール検出メカニズムが可能になります。

カスタム TST を使用したリクエストの例:

```
{
    "model": "claude-sonnet-4-5-20250929",
    "anthropic_version": "bedrock-2023-05-31",
    "anthropic_beta": ["tool-search-tool-2025-10-19"],
    "max_tokens": 4096,
    "tools": [{
            "name": "semantic_tool_search",
            "description": "Search for available tools using semantic similarity. Returns the most relevant tools for the given query.",
            "input_schema": {
                "type": "object",
                "properties": {
                    "query": {
                        "type": "string",
                        "description": "Natural language description of what kind of tool is needed"
                    },
                    "top_k": {
                        "type": "integer",
                        "description": "Number of tools to return (default: 5)"
                    }
                },
                "required": ["query"]
            },
            "defer_loading": false
        },
        {
            "name": "get_weather",
            "description": "Get current weather for a location",
            "input_schema": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string"
                    },
                    "unit": {
                        "type": "string",
                        "enum": ["celsius", "fahrenheit"]
                    }
                },
                "required": ["location"]
            },
            "defer_loading": true
        },
        {
            "name": "search_flights",
            "description": "Search for available flights between locations",
            "input_schema": {
                "type": "object",
                "properties": {
                    "origin": {
                        "type": "string"
                    },
                    "destination": {
                        "type": "string"
                    },
                    "date": {
                        "type": "string"
                    }
                },
                "required": ["origin", "destination", "date"]
            },
            "defer_loading": true
        }
    ],
    "messages": [{
        "role": "user",
        "content": "What's the weather forecast in Seattle for the next 3 days?"
    }]
}
```

Claudeのレスポンス (カスタム TST を呼び出す):

```
{
    "role": "assistant",
    "content": [{
            "type": "text",
            "text": "I'll search for the appropriate tools to help with weather information."
        },
        {
            "type": "tool_use",
            "id": "toolu_01ABC123",
            "name": "semantic_tool_search",
            "input": {
                "query": "weather forecast multiple days",
                "top_k": 3
            }
        }
    ],
    "stop_reason": "tool_use"
}
```

**お客様が提供したツールの結果**  
ツールライブラリでセマンティック検索を実行すると、顧客は一致するツールリファレンスを返します。

```
{
    "role": "user",
    "content": [{
        "type": "tool_search_tool_result",
        "tool_use_id": "toolu_01ABC123",
        "content": {
            "type": "tool_search_tool_search_result",
            "tool_references": [{
                "type": "tool_reference",
                "tool_name": "get_weather"
            }]
        }
    }]
}
```

Claudeのフォローアップ (検出されたツールを使用)

```
{
    "role": "assistant",
    "content": [{
            "type": "text",
            "text": "I found the forecast tool. Let me get the weather forecast for Seattle."
        },
        {
            "type": "tool_use",
            "id": "toolu_01DEF456",
            "name": "get_weather",
            "input": {
                "location": "Seattle, WA"
            }
        }
    ],
    "stop_reason": "tool_use"
}
```

**エラー処理**
+ すべてのツール (ツール検索ツールを含む) `defer_loading: true`に対して を設定すると、400 エラーがスローされます。
+ 対応するツール定義`tool_reference`なしで を渡すと、400 エラーがスローされます

## ツールの使用例 (ベータ)
<a name="model-parameters-anthropic-claude-tool-use-examples"></a>

Claude Opus 4.5 は、 Claudeのツール使用パフォーマンスを向上させるために、ツール定義でユーザーが提供する例をサポートしています。別の形式に変換することなく、実際の LLM 出力とまったく同じ形式で完全な関数呼び出しとして例を提供できます。この機能を使用するには、ベータヘッダー を渡す必要があります`tool-examples-2025-10-29`。

ツール定義の例:

```
{
    "name": "get_weather",
    "description": "Get the current weather in a given location",
    "input_schema": {
        "type": "object",
        "properties": {
            "location": {
                "type": "string",
                "description": "The city and state, e.g. San Francisco, CA"
            },
            "unit": {
                "type": "string",
                "enum": ["celsius", "fahrenheit"],
                "description": "Temperature unit"
            }
        },
        "required": ["location"]
    },
    "input_examples": [{
            "location": "San Francisco, CA",
            "unit": "fahrenheit"
        },
        {
            "location": "Tokyo, Japan",
            "unit": "celsius"
        },
        {
            "location": "New York, NY"
        }
    ]
}
```

**検証ルール**
+ スキーマの適合: の各例は、ツールの に従って有効`input_examples`である必要があります`input_schema`。
  + 必須フィールドは、少なくとも 1 つの例に存在する必要があります。
  + フィールドタイプはスキーマと一致する必要があります。
  + 列挙値は、許可されたセットのものである必要があります。
  + 検証が失敗した場合は、検証に失敗した例の詳細を含む 400 エラーを返します。
+ 配列の要件: は配列`input_examples`である必要があります (空にすることができます）。
  + 空の配列`[]`は有効であり、 フィールドを省略することと同等です。
  + 1 つの例を配列でラップする必要があります。 `[{...}]`
  + 長さの制限: ツール定義ごとに 20 個の例の制限から始めます。

エラーの例:

```
// Invalid: Example doesn't match schema (missing required field)
{
    "type": "invalid_request_error",
    "message": "Tool 'get_weather' input_examples[0] is invalid: Missing required property 'location'"
}

// Invalid: Example has wrong type for field
{
    "type": "invalid_request_error",
    "message": "Tool 'search_products' input_examples[1] is invalid: Property 'filters.price_range.min' must be a number, got string"
}

// Invalid: input_examples on server-side tool
{
    "type": "invalid_request_error",
    "message": "input_examples is not supported for server-side tool"
}
```