View a markdown version of this page

ツール - Amazon Bedrock AgentCore

ツール

ツールは宣言型です。エージェントが呼び出すことができるものを一覧表示します。AgentCore は呼び出し、認証情報、結果を処理します。ハーネスは 5 つのツールタイプと、組み込みのファイルシステムとシェルツールをサポートしています。

  • MCP サーバー: URL で任意のリモートモデルコンテキストプロトコルエンドポイントに接続します。シンプルなケースではゲートウェイは必要ありません。

  • AgentCore Gateway: インバウンド/アウトバウンド認証、アクセスコントロール、ポリシーの適用を備えた APIs および MCP サーバーへの管理された接続。ゲートウェイ ARN を参照し、そのゲートウェイで設定されたすべてのツールが使用可能になります。マネージド型のポリシーベースのツールサーフェスが必要な場合は、Gateway を使用します。

  • AgentCore Browser: マネージドウェブブラウジングと自動化。

  • AgentCore Code Interpreter: データ分析と計算のためのサンドボックス化された Python/JavaScript/TypeScript コード実行。

  • インライン関数: ハーネス VM ではなくクライアント側で実行されるツールスキーマ。ツールが呼び出されるとハーネスが一時停止し、コードへの呼び出しが返されます。これにより、何をするかが決まり、結果が返されます。これは、ヒューhuman-in-the-loop承認とカスタム統合のパターンです。

で制限しない限り、デフォルトのツール shellおよび file_operationsはすべてのセッションで使用できますallowedTools。 は bash コマンドshellを実行します。 はファイルの表示、作成、編集file_operationsをサポートします。

allowedTools パラメータは、エージェントが使用できるツールを制御します。省略すると、すべてのツールが許可されます。

サポートされているパターン:

パターン マッチ

*

"*"

すべてのツール

プレーン名

"shell"

名前による組み込み

組み込み glob

"file_*"

file_operations, file_read

@builtin

"@builtin"

すべての組み込みツール

@builtin/name

"@builtin/shell"

特定の組み込み

@server

"@git"

MCP サーバーからのすべてのツール

@server/tool

"@git/git_status"

特定の MCP ツール

@server/glob

"@git/read_*"

サーバー内の Glob

@*/tool

"@*-mcp/status"

サーバー間の Glob

注記

allowedTools は、 中にInvokeHarnessのみ LLM ツールの選択をスコープします。InvokeAgentRuntimeCommand には影響しません。InvokeAgentRuntimeCommand は、LLM を経由せずにコマンドを直接実行する独自の IAM アクション (bedrock-agentcore:InvokeAgentRuntimeCommand) を持つ別の API です。コマンドの直接実行を防ぐには、IAM ポリシーbedrock-agentcore:InvokeAgentRuntimeCommandで を に付与しないでください。

ツールを追加する

AWS CLI/boto3

作成、更新、または呼び出しtools時に を渡します。

tools = [ # MCP server { "type": "remote_mcp", "name": "exa", "config": {"remoteMcp": {"url": "https://mcp.exa.ai/mcp"}}, }, # MCP server with authentication headers (plain text) { "type": "remote_mcp", "name": "my-private-mcp", "config": {"remoteMcp": { "url": "https://mcp.example.com/api", "headers": {"Authorization": "Bearer <your-token>"} }}, }, # MCP server with API key stored in AgentCore Identity Token Vault. # Use ${arn:...} to reference a credential provider - the ARN is resolved # to the actual API key at invocation time. { "type": "remote_mcp", "name": "exa-secure", "config": {"remoteMcp": { "url": "https://mcp.exa.ai/mcp", "headers": {"x-api-key": "${arn:aws:bedrock-agentcore:us-west-2:123456789012:token-vault/default/apikeycredentialprovider/my-exa-key}"} }}, }, # For managed credential rotation and OAuth-protected tools, put your MCP server # behind AgentCore Gateway and use AgentCore Identity instead of raw headers. # # AgentCore Gateway with SigV4 auth (default) { "type": "agentcore_gateway", "name": "my-gateway", "config": {"agentCoreGateway": {"gatewayArn": "arn:aws:bedrock-agentcore:us-west-2:123456789012:gateway/my-gateway"}}, }, # AgentCore Gateway with OAuth auth { "type": "agentcore_gateway", "name": "my-oauth-gateway", "config": {"agentCoreGateway": { "gatewayArn": "arn:aws:bedrock-agentcore:us-west-2:123456789012:gateway/my-oauth-gateway", "outboundAuth": {"oauth": { "credentialProviderName": "my-oauth-provider", "scopes": ["read", "write"] }} }}, }, # AgentCore Browser {"type": "agentcore_browser", "name": "browser"}, # AgentCore Code Interpreter {"type": "agentcore_code_interpreter", "name": "code_interpreter"}, # Inline function - executes on the client side, not on the harness VM. # When the agent calls this tool, the call is returned to your code for handling. { "type": "inline_function", "name": "approve_purchase", "config": { "inlineFunction": { "description": "Request human approval for a purchase.", "inputSchema": { "type": "object", "properties": { "item": {"type": "string"}, "amount": {"type": "number"}, }, "required": ["item", "amount"], }, } }, }, ] response = client.invoke_harness( harnessArn=HARNESS_ARN, runtimeSessionId=SESSION_ID, tools=tools, messages=[{"role": "user", "content": [{"text": "Find a mechanical keyboard under $200 and request approval."}]}], )
AgentCore CLI

新しいハーネスをインタラクティブに作成すると、agentcore add harnessウィザードでツールを選択できます。CLI 経由でツールを追加するには、ハーネスの作成agentcore add tool後に を使用します。

注記

--type フラグはアンダースコアで区切られた名前 ( などagentcore_browser) を使用します。これは、 のツールタイプ識別子と一致しますharness.json

# Add a remote MCP server agentcore add tool --harness my-agent --type remote_mcp \ --name exa --url https://mcp.exa.ai/mcp # Add a remote MCP server with an API key from AgentCore Identity Token Vault. # Use ${arn:...} syntax in header values to reference a credential provider. agentcore add tool --harness my-agent --type remote_mcp \ --name exa-secure --url https://mcp.exa.ai/mcp \ --header 'x-api-key=${arn:aws:bedrock-agentcore:us-west-2:123456789012:token-vault/default/apikeycredentialprovider/my-exa-key}' # Add Browser agentcore add tool --harness my-agent --type agentcore_browser --name browser # Add Code Interpreter agentcore add tool --harness my-agent --type agentcore_code_interpreter --name code-interpreter # Add Gateway by ARN agentcore add tool --harness my-agent --type agentcore_gateway \ --name my-gateway --gateway-arn arn:aws:bedrock-agentcore:us-west-2:123456789012:gateway/my-gateway # Add Gateway by project-local name agentcore add tool --harness my-agent --type agentcore_gateway \ --name my-gateway --gateway my-gateway # Add an inline function tool (executes client-side, not on the harness VM) agentcore add tool --harness my-agent --type inline_function \ --name approve_purchase \ --description "Request human approval for a purchase" \ --input-schema '{"type": "object", "properties": {"item": {"type": "string"}, "amount": {"type": "number"}}, "required": ["item", "amount"]}'

デプロイして適用します。

1 回の呼び出しでツールを上書きします。

agentcore invoke --harness research-agent --tools agentcore-browser "Find the latest news on AI agents"
Interactive

プロジェクトディレクトリagentcoreで を実行し、 の追加 を選択し、ハーネス を選択し、詳細設定 に進みます。Tools with Space を有効にし、Enter キーを押します。

  1. ハーネスのツールを選択します: AgentCore BrowserAgentCore Code InterpreterAgentCore Gateway 、またはリモート MCP Serverスペースを使用してそれぞれを切り替え、Enter キーを押します。

    選択ツール: ブラウザ、コードインタープリタ、ゲートウェイ、リモート MCP サーバー
  2. リモート MCP サーバー の場合、ウィザードはサーバー名、URL、およびオプションのリクエストヘッダーを求めます。

    MCP サーバー URL を入力する
  3. AgentCore Gateway の場合は、ゲートウェイ ARN を入力し、アウトバウンド認証を選択します: AWS IAM (デフォルト)、なし、または OAuth

    ゲートウェイアウトバウンド認証を選択する
  4. 設定の概要を確認して確認します。

    ハーネスツールの設定を確認する

次に、 を実行して適用agentcore deployします。

エージェントにウェブ検索を許可するには、Web Search Tool コネクタを AgentCore Gateway の背後に配置し、そのゲートウェイをagentcore_gatewayツールとしてハーネスにアタッチします。ゲートウェイは、ウェブ検索を標準 MCP WebSearch ツールとして公開します。エージェントはそれを他のゲートウェイツールと同様に検出して呼び出します。AgentCore Gateway は、すべてのクエリを完全に内部で処理します AWS。プライバシーモデルと専用ウェブインデックスの詳細については、ウェブ検索ツールコネクタページを参照してください。

リージョンの可用性

ウェブ検索ツールは、米国東部 (バージニア北部) us-east-1リージョンで利用できます。でゲートウェイとハーネスを作成しますus-east-1

次の手順を実行して、ハーネスのウェブ検索を設定します。

  1. ゲートウェイとコネクタターゲットを作成します。「ウェブ検索ツールのセットアップ」の手順に従ってゲートウェイ (MCP プロトコル、AWS_IAMインバウンド認証) を作成し、 でターゲットを追加しますconnectorId: "web-search"。このターゲットには、コネクタbedrock-agentcore:InvokeWebSearchに を持つ Gateway サービスロールが必要です。詳細については、「ゲートウェイサービスロールの設定」を参照してください。ゲートウェイ ARN が に達したら書き留めますREADY

  2. ハーネス実行ロールにアクセス権を付与します。ハーネス実行ロール (前のステップのゲートウェイサービスロールとは異なる) は、ゲートウェイ ARN bedrock-agentcore:InvokeGatewayに必要です。必要なアクセス許可の詳細については、 セキュリティトピックのAgentCore Gateway optional-permissions」ポリシーを参照してください。ハーネスがマネージドメモリ (デフォルト) を使用している場合、実行ロールには AgentCore Memory アクセス許可も必要です。エージェントは、各呼び出しでセッションメモリの読み取りと書き込みを行います。

  3. ゲートウェイをハーネスにアタッチします。デフォルトのAWS_IAMアウトバウンド認証を使用してagentcore_gatewayツールとして追加します。次の例は、作成時にゲートウェイをアタッチする方法を示しています。

AWS CLI/boto3

作成時にゲートウェイをアタッチする (または update_harness / toolsを渡すinvoke_harness):

tools = [ { "type": "agentcore_gateway", "name": "web-search", "config": {"agentCoreGateway": { "gatewayArn": "arn:aws:bedrock-agentcore:us-east-1:123456789012:gateway/my-web-search-gateway", "outboundAuth": {"awsIam": {}} }}, }, ] client.create_harness( harnessName="research-agent", executionRoleArn="arn:aws:iam::123456789012:role/MyHarnessRole", tools=tools, )

ゲートウェイのツールがエージェントで使用できるようになりました。現在の情報を必要とするプロンプトでハーネスを呼び出します。

response = client.invoke_harness( harnessArn=HARNESS_ARN, runtimeSessionId=SESSION_ID, messages=[{"role": "user", "content": [{"text": "Search the web for the latest AWS announcements and cite your sources."}]}], )
AgentCore CLI
# Attach the web-search gateway to your harness agentcore add tool --harness research-agent --type agentcore_gateway \ --name web-search \ --gateway-arn arn:aws:bedrock-agentcore:us-east-1:123456789012:gateway/my-web-search-gateway # Deploy, then invoke agentcore deploy agentcore invoke --harness research-agent "Search the web for the latest AWS announcements and cite your sources."

インライン関数呼び出し

インライン関数を使用すると、ハーネスではなくコードで実行するツールを定義できます。これは、ヒューhuman-in-the-loop承認、内部 APIs呼び出し、またはクライアント側を制御するロジックに役立ちます。

AWS CLI/boto3

呼び出し時にインライン関数ツールを渡します。

# 1. Invoke with an inline function tool response = client.invoke_harness( harnessArn=HARNESS_ARN, runtimeSessionId=SESSION_ID, tools=[{ "type": "inline_function", "name": "get_weather", "config": {"inlineFunction": { "description": "Get the current weather for a city.", "inputSchema": { "type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"] } }} }], messages=[{"role": "user", "content": [{"text": "What's the weather in Seattle?"}]}], ) # 2. The agent calls the tool - capture the toolUseId and input from the stream tool_use_id = None tool_name = None tool_input = None for event in response["stream"]: if "contentBlockStart" in event: start = event["contentBlockStart"].get("start", {}) if "toolUse" in start and start["toolUse"].get("name") == "get_weather": tool_use_id = start["toolUse"]["toolUseId"] tool_name = start["toolUse"]["name"] if "contentBlockDelta" in event: delta = event["contentBlockDelta"].get("delta", {}) if "toolUse" in delta: tool_input = (tool_input or "") + delta["toolUse"].get("input", "") # 3. Execute the tool yourself and send the result back # Include the assistant's toolUse message followed by your toolResult client.invoke_harness( harnessArn=HARNESS_ARN, runtimeSessionId=SESSION_ID, messages=[ { "role": "assistant", "content": [{"toolUse": {"toolUseId": tool_use_id, "name": tool_name, "input": json.loads(tool_input)}}], }, { "role": "user", "content": [{ "toolResult": { "toolUseId": tool_use_id, "content": [{"text": "72°F, partly cloudy"}], "status": "success", } }], }, ], )
注記

toolResult ステップ 3 では、アシスタントtoolUseメッセージと の両方を含める必要があります。ハーネスは意図的にインライン関数のターンをセッションに保持しません。クライアントが結果を返さない場合、部分ターン (一致する toolUseなしで維持toolResult) を保持すると、セッションは破損した状態になります。クライアントが両方のメッセージを送信するように要求することで、クライアントがツール呼び出しを完了したかどうかにかかわらず、セッションはクリーンのままになります。

エージェントはツールの結果で推論を再開し、最終レスポンスをストリーミングします。

AgentCore CLI

インライン関数ツールをハーネスに追加します。

agentcore add tool --harness my-agent --type inline_function \ --name get_weather

次に、 で説明と入力スキーマを定義しますapp/my-agent/harness.json

{ "type": "inline_function", "name": "get_weather", "config": { "inlineFunction": { "description": "Get the current weather for a city.", "inputSchema": { "type": "object", "properties": { "city": { "type": "string" } }, "required": ["city"] } } } }

を実行して適用agentcore deployします。エージェントが呼び出し中にインライン関数を呼び出すと、TUI は一時停止し、ツールの結果をインラインで提供するように求められます。非インタラクティブ (CLI) モードでは、ストリームは で戻りstopReason: "tool_use"、フォローアップ呼び出し呼び出しで結果を返します。

各ツールの詳細をご覧ください。