Was this page helpful?
ツール検索ツールにより、Claudeは数百または数千のツールを動的に検出し、オンデマンドで読み込むことで、それらと連携できます。すべてのツール定義をコンテキストウィンドウに事前に読み込む代わりに、Claudeはツールカタログ(ツール名、説明、引数名、引数説明を含む)を検索し、必要なツールのみを読み込みます。
このアプローチは、ツールライブラリのスケーリングに伴い急速に複合する2つの問題を解決します:
ツール検索が解決するスケーリングの課題の背景については、Advanced tool useを参照してください。ツール検索のオンデマンド読み込みは、Effective context engineeringで説明されているより広いジャストインタイム検索原則の一例でもあります。
これはサーバー側のツールとして提供されていますが、独自のクライアント側ツール検索機能を実装することもできます。詳細については、カスタムツール検索実装を参照してください。
このフィーチャーに関するフィードバックは、フィードバックフォームを通じて共有してください。
This feature qualifies for Zero Data Retention (ZDR) with limited technical retention. See the Data retention section for details on what is retained and why.
Amazon Bedrockでは、サーバー側のツール検索はinvoke API経由でのみ利用可能で、converse APIではありません。
独自の検索実装からtool_referenceブロックを返すことで、クライアント側ツール検索を実装することもできます。
ツール検索には2つのバリアントがあります:
tool_search_tool_regex_20251119):Claudeはツールを検索するための正規表現パターンを構築しますtool_search_tool_bm25_20251119):Claudeは自然言語クエリを使用してツールを検索しますツール検索ツールを有効にすると:
tool_search_tool_regex_20251119またはtool_search_tool_bm25_20251119)をツールリストに含めますdefer_loading: trueを指定してすべてのツール定義を提供しますtool_referenceブロックを返しますこれにより、コンテキストウィンドウを効率的に保ちながら、高いツール選択精度を維持します。
遅延されたツールを使用した簡単な例を以下に示します:
ツール検索ツールには2つのバリアントがあります:
{
"type": "tool_search_tool_regex_20251119",
"name": "tool_search_tool_regex"
}{
"type": "tool_search_tool_bm25_20251119",
"name": "tool_search_tool_bm25"
}Regexバリアントクエリ形式:自然言語ではなくPython正規表現
tool_search_tool_regex_20251119を使用する場合、Claudeは自然言語クエリではなく、Pythonのre.search()構文を使用して正規表現パターンを構築します。一般的なパターン:
"weather" - 「weather」を含むツール名/説明にマッチします"get_.*_data" - get_user_data、get_weather_dataなどのツールにマッチします"database.*query|query.*database" - 柔軟性のためのORパターン"(?i)slack" - 大文字小文字を区別しない検索最大クエリ長:200文字
BM25バリアントクエリ形式:自然言語
tool_search_tool_bm25_20251119を使用する場合、Claudeは自然言語クエリを使用してツールを検索します。
defer_loading: trueを追加することで、オンデマンド読み込み用にツールをマークします:
{
"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
}重要なポイント:
defer_loadingのないツールはコンテキストに即座に読み込まれますdefer_loading: trueのツールは、Claudeが検索経由で検出した場合のみ読み込まれますdefer_loading: trueを持つべきではありません両方のツール検索バリアント(regexとbm25)は、ツール名、説明、引数名、および引数説明を検索します。
遅延の内部的な仕組み: 遅延されたツールはシステムプロンプトプレフィックスに含まれていません。モデルがツール検索を通じて遅延されたツールを検出すると、ツール定義は会話内にtool_referenceブロックとしてインラインで追加されます。プレフィックスは変更されないため、プロンプトキャッシングが保持されます。厳密モードの文法は完全なツールセットから構築されるため、defer_loadingと厳密モードは文法の再コンパイルなしで構成されます。
Claudeがツール検索ツールを使用する場合、レスポンスには新しいブロックタイプが含まれます:
{
"role": "assistant",
"content": [
{
"type": "text",
"text": "I'll search for tools to help with the weather information."
},
{
"type": "server_tool_use",
"id": "srvtoolu_01ABC123",
"name": "tool_search_tool_regex",
"input": {
"query": "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": "I found a weather tool. Let me get the weather for San Francisco."
},
{
"type": "tool_use",
"id": "toolu_01XYZ789",
"name": "get_weather",
"input": { "location": "San Francisco", "unit": "fahrenheit" }
}
],
"stop_reason": "tool_use"
}server_tool_use: Claudeがツール検索ツールを呼び出していることを示しますtool_search_tool_result: ネストされたtool_search_tool_search_resultオブジェクトを含む検索結果を含みますtool_references: 検出されたツールを指すtool_referenceオブジェクトの配列tool_use: Claudeが検出されたツールを呼び出していますtool_referenceブロックは、Claudeに表示される前に自動的に完全なツール定義に展開されます。この展開を自分で処理する必要はありません。toolsパラメータにすべての一致するツール定義を提供する限り、APIで自動的に発生します。
defer_loadingでmcp_toolsetを構成する場合は、MCP connectorを参照してください。
独自のツール検索ロジック(例:埋め込みやセマンティック検索を使用)を実装し、カスタムツールからtool_referenceブロックを返すことができます。Claudeがカスタム検索ツールを呼び出すと、コンテンツ配列にtool_referenceブロックを含む標準的なtool_resultを返します:
{
"type": "tool_result",
"tool_use_id": "toolu_your_tool_id",
"content": [{ "type": "tool_reference", "tool_name": "discovered_tool_name" }]
}参照されるすべてのツールは、トップレベルのtoolsパラメータにdefer_loading: trueを指定した対応するツール定義を持つ必要があります。このアプローチにより、ツール検索システムとの互換性を維持しながら、より洗練された検索アルゴリズムを使用できます。
レスポンス形式セクションに示されているtool_search_tool_result形式は、Anthropicの組み込みツール検索によって内部的に使用されるサーバー側の形式です。カスタムクライアント側の実装では、上記に示すように、常にtool_referenceコンテンツブロックを含む標準的なtool_result形式を使用してください。
埋め込みを使用した完全な例については、tool search with embeddings cookbookを参照してください。
ツール検索ツールはツール使用例と互換性がありません。 ツール使用の例を提供する必要がある場合は、ツール検索なしで標準的なツール呼び出しを使用してください。
これらのエラーはリクエストが処理されるのを防ぎます:
すべてのツールが遅延されている:
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "All tools have defer_loading set. At least one tool must be non-deferred."
}
}ツール定義が見つからない:
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "Tool reference 'unknown_tool' has no corresponding tool definition"
}
}ツール実行中のエラーは、200レスポンスとボディ内のエラー情報を返します:
{
"type": "tool_result",
"tool_use_id": "srvtoolu_01ABC123",
"content": {
"type": "tool_search_tool_result_error",
"error_code": "invalid_pattern"
}
}エラーコード:
too_many_requests:ツール検索操作のレート制限を超過しましたinvalid_pattern:不正な形式の正規表現パターンpattern_too_long:パターンが200文字制限を超えていますunavailable:ツール検索サービスが一時的に利用不可ですdefer_loadingがプロンプトキャッシングを保持する方法については、Tool use with prompt cachingを参照してください。
システムは会話履歴全体を通じてtool_referenceブロックを自動的に展開するため、Claudeは再検索なしで後続のターンで検出されたツールを再利用できます。
ストリーミングが有効な場合、ツール検索イベントはストリームの一部として受け取ります:
event: content_block_start
data: {"type": "content_block_start", "index": 1, "content_block": {"type": "server_tool_use", "id": "srvtoolu_xyz789", "name": "tool_search_tool_regex"}}
// Search query streamed
event: content_block_delta
data: {"type": "content_block_delta", "index": 1, "delta": {"type": "input_json_delta", "partial_json": "{\"query\":\"weather\"}"}}
// Pause while search executes
// Search results streamed
event: content_block_start
data: {"type": "content_block_start", "index": 2, "content_block": {"type": "tool_search_tool_result", "tool_use_id": "srvtoolu_xyz789", "content": {"type": "tool_search_tool_search_result", "tool_references": [{"type": "tool_reference", "tool_name": "get_weather"}]}}}
// Claude continues with discovered toolsMessages Batches APIにツール検索ツールを含めることができます。Messages Batches API経由のツール検索操作は、通常のMessages APIリクエストと同じ価格です。
サーバー側のツール検索(tool_searchツール)はツールカタログデータ(ツール名、説明、引数メタデータ)をAPIレスポンスを超えてインデックスおよび保存します。このカタログデータはAnthropicの標準保持ポリシーに従って保持されます。標準Messages APIを使用するカスタムクライアント側ツール検索実装は、完全にZDR対応です。
すべてのフィーチャー全体のZDR対応については、API and data retentionを参照してください。
良いユースケース:
従来のツール呼び出しがより良い場合:
github_、slack_)。これにより、検索クエリが自然に正しいツールグループを表示しますツール検索ツールの使用はレスポンス使用オブジェクトで追跡されます:
{
"usage": {
"input_tokens": 1024,
"output_tokens": 256,
"server_tool_use": {
"tool_search_requests": 2
}
}
}client = anthropic.Anthropic()
response = client.messages.create(
model="claude-opus-4-7",
max_tokens=2048,
messages=[{"role": "user", "content": "What is the weather in San Francisco?"}],
tools=[
{"type": "tool_search_tool_regex_20251119", "name": "tool_search_tool_regex"},
{
"name": "get_weather",
"description": "Get the weather at a specific 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,
},
],
)
print(response)ツール定義のステップバイステップガイド。