Alat bersifat deklaratif. Anda mencantumkan apa yang dapat dipanggil agen; AgentCore menangani pemanggilan, kredensi, dan hasil. Harness mendukung lima jenis alat, ditambah sistem file bawaan dan alat shell.
Alat default shell dan file_operations tersedia di setiap sesi kecuali Anda membatasinyaallowedTools. shellmenjalankan perintah bash; file_operations mendukung melihat, membuat, dan mengedit file.
allowedToolsParameter mengontrol alat mana yang dapat digunakan agen. Jika dihilangkan, semua alat diizinkan.
Pola yang didukung:
| Pola |
Contoh |
Cocok |
|
*
|
"*"
|
Semua alat
|
|
Nama biasa
|
"shell"
|
Builtin dengan nama
|
|
Gumpalan bawaan
|
"file_*"
|
file_operations, file_read
|
|
@builtin
|
"@builtin"
|
Semua alat bawaan
|
|
@builtin/name
|
"@builtin/shell"
|
Builtin khusus
|
|
@server
|
"@git"
|
Semua alat dari server MCP
|
|
@server/tool
|
"@git/git_status"
|
Alat MCP khusus
|
|
@server/glob
|
"@git/read_*"
|
Glob dalam server
|
|
@*/tool
|
"@*-mcp/status"
|
Glob di seluruh server
|
allowedToolslingkup pemilihan alat LLM hanya selamaInvokeHarness. Itu tidak mempengaruhi InvokeAgentRuntimeCommand, yang merupakan API terpisah dengan tindakan IAM sendiri (bedrock-agentcore:InvokeAgentRuntimeCommand) yang mengeksekusi perintah secara langsung tanpa melewati LLM. Untuk mencegah eksekusi perintah langsung, jangan berikan bedrock-agentcore:InvokeAgentRuntimeCommand dalam kebijakan IAM Anda.
contoh
- AWS CLI/boto3
-
Lulus tools saat membuat, memperbarui, atau memanggil waktu:
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
-
Saat membuat harness baru secara interaktif, agentcore add harness wizard memungkinkan Anda memilih alat. Untuk menambahkan alat melalui CLI, gunakan agentcore add tool setelah membuat harness:
--typeBendera menggunakan nama yang dipisahkan dengan underscore-separated (misalnya,agentcore_browser), yang cocok dengan pengidentifikasi jenis alat di. 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"]}'
Menyebarkan untuk menerapkan.
Ganti alat pada satu pemanggilan:
agentcore invoke --harness research-agent --tools agentcore-browser "Find the latest news on AI agents"
- Interactive
-
Jalankan agentcore di direktori proyek, pilih tambahkan, pilih Harness, dan lanjutkan ke Pengaturan lanjutan. Aktifkan Tools with Space, lalu tekan Enter.
-
Pilih alat untuk harness Anda: AgentCore Browser, Penerjemah AgentCore Kode, AgentCore Gateway, atau Server MCP Jarak Jauh. Gunakan Spasi untuk beralih masing-masing, lalu tekan Enter.
-
Untuk Server MCP Jarak Jauh, wizard meminta nama server, URL, dan header permintaan opsional.
-
Untuk AgentCore Gateway, masukkan ARN gateway dan pilih otentikasi keluarnya: AWS IAM (default), None, atau OAuth.
-
Tinjau ringkasan konfigurasi dan konfirmasi.
Kemudian jalankan agentcore deploy untuk melamar.
Pencarian web
Untuk memberikan pencarian web agen Anda, letakkan konektor Alat Pencarian Web di belakang AgentCore Gateway dan pasang gateway itu ke harness Anda sebagai agentcore_gateway alat. Gateway mengekspos pencarian web sebagai alat MCP WebSearch standar. Agen Anda menemukan dan menyebutnya seperti alat gateway lainnya. AgentCore Gateway melayani semua pertanyaan sepenuhnya di dalam AWS. Untuk informasi selengkapnya tentang model privasi dan indeks web yang dibuat khusus, lihat halaman konektor Alat Pencarian Web.
Alat Pencarian Web tersedia di us-east-1 Wilayah AS Timur (Virginia N.). Buat gateway dan harness dius-east-1.
Selesaikan langkah-langkah berikut untuk mengatur pencarian web untuk harness Anda.
-
Buat target gateway dan konektor. Ikuti langkah-langkah dalam Mengatur Alat Pencarian Web untuk membuat Gateway (protokol MCP, autentikasi AWS_IAM masuk) dan menambahkan target dengan. connectorId: "web-search" Target itu membutuhkan peran layanan Gateway bedrock-agentcore:InvokeWebSearch pada konektor. Untuk informasi selengkapnya, lihat Mengkonfigurasi Peran Layanan Gateway. Perhatikan gateway ARN setelah mencapai. READY
-
Berikan akses peran eksekusi harness. Peran eksekusi harness (berbeda dari peran layanan Gateway pada langkah sebelumnya) perlu bedrock-agentcore:InvokeGateway pada ARN gateway. Untuk informasi selengkapnya tentang izin yang diperlukan, lihat kebijakan izin opsional AgentCore Gateway dalam topik keamanan. Jika harness Anda menggunakan memori terkelola (default), peran eksekusi juga memerlukan izin AgentCore Memori. Agen membaca dan menulis memori sesi pada setiap doa.
-
Pasang gateway ke harness. Tambahkan sebagai agentcore_gateway alat dengan autentikasi AWS_IAM keluar default. Contoh berikut menunjukkan cara melampirkan gateway pada waktu pembuatan.
contoh
- AWS CLI/boto3
-
Lampirkan gateway pada waktu pembuatan (atau tools teruskanupdate_harness/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,
)
Alat gateway sekarang tersedia untuk agen. Panggil harness dengan prompt yang membutuhkan informasi terkini:
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."
Panggilan fungsi sebaris
Fungsi inline memungkinkan Anda mendefinisikan alat yang mengeksekusi dalam kode Anda, bukan pada harness. Ini berguna untuk persetujuan manusia-in-the-loop, memanggil API internal, atau logika apa pun yang ingin Anda kontrol sisi klien.
contoh
- AWS CLI/boto3
-
Lewati alat fungsi inline pada waktu pemanggilan:
# 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",
}
}],
},
],
)
Anda harus menyertakan toolUse pesan asisten dan Anda toolResult di langkah 3. Harness sengaja tidak mempertahankan fungsi sebaris beralih ke sesi - jika klien tidak pernah mengembalikan hasil, mempertahankan giliran sebagian (asisten toolUse tanpa pencocokantoolResult) akan meninggalkan sesi dalam keadaan rusak. Dengan mengharuskan klien untuk mengirim kedua pesan, sesi tetap bersih terlepas dari apakah klien menyelesaikan panggilan alat.
Agen melanjutkan penalaran dengan hasil alat dan mengalirkan respons akhir.
- AgentCore CLI
-
Tambahkan alat fungsi inline ke harness:
agentcore add tool --harness my-agent --type inline_function \
--name get_weather
Kemudian tentukan deskripsi dan skema masukan diapp/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"]
}
}
}
}
Jalankan agentcore deploy untuk melamar. Ketika agen memanggil fungsi inline selama pemanggilan, TUI berhenti dan meminta Anda untuk memberikan hasil alat sebaris. Dalam mode non-interaktif (CLI), aliran kembali stopReason: "tool_use" dengan dan Anda mengirim hasilnya kembali dengan panggilan panggilan tindak lanjut.
Pelajari lebih lanjut tentang setiap alat: