Back to list
実装に手を染めよう - AgentCore ギateway
Get Your Hands Dirty - AgentCore - Gateway
Translated: 2026/3/15 2:09:52
Japanese Translation
エージェント開発における最も大きな障壁の一つは、外部 API 用の「接着コード」をすべて手動で記述することです。Bedrock AgentCore Gateway は、この問題を解決するためにツール作成への「ゼロコード」パースを提供します。Gateway を標準的な OpenAPI 仕様(Swagger)に指向するだけで、モデルコンテキストプロトコル(MCP)サーバーを自動生成します。これにより、Strands エージェントが複雑なリクエストスキーマと認証を含むあらゆる REST API を理解し、相互作用できるようになり、統合ロジックの記述を一行も不要にします。
Gateway は、エージェントと外部サービス間のハンドシェークを管理することで、エンタープライズグレードのセキュリティも提供します。エージェント自体用の JWT ベースの認証を設定でき、AgentCore Identity とリンクすることで、Exa や Slack などの外部 API キーをすべて送信ヘッダーに安全に注入できます。
Python 関数を記述する代わりに、単に API の OpenAPI URL を登録するだけです。Gateway は仕様に解析を行い、そのすべてのエンドポイントを呼び出し可能なツールとして即座にエージェントに公開します。
```python
from bedrock_agentcore.tools.gateway_client import GatewayClient
# Gateway クライアントを初期化
gateway_client = GatewayClient(region="us-east-1")
# OpenAPI 仕様に MCP ツールを変換する Gateway を作成
gateway = gateway_client.create_gateway(
name="ExaSearchGateway",
auth_config={"type": "JWT"}, # Gateway 自体を保護
targets=[{
"name": "ExaAPI",
"openapi_url": "https://api.exa.ai/openapi.json", # 「真の価値」の元
"credential_provider_id": "your-secure-credential-id" # 安全に注入される
}]
)
print(f"Gateway で生成された MCP エンドポイント: {gateway['endpoint']}")
```
Strands エージェントは、Gateway を通常のツールセットのいずれかのように扱います。Gateway が OpenAPI 仕様から完全な意味的な説明を提供するため、エージェントは外部 API に必要とされる正確なパラメータを知り、タスクを達成できます。
```python
from strands import Agent
from strands.models import BedrockModel
from strands_tools.gateway import AgentCoreGateway
# Strands エージェントと Gateway を接続
agentcore_gateway = AgentCoreGateway(region="us-east-1", gateway_id=gateway["id"])
agent = Agent(
model=BedrockModel(model_id="us.amazon.nova-pro-v1:0"),
system_prompt="あなたは研究アシスタントです。Exa ツールを使って最新のデータを検索してください。",
tools=[agentcore_gateway.gateway] # すべての OpenAPI エンドポイントがツールになりました
)
# アージェントは仕様から正しい 'search' エンドポイントを選定します
agent("この週に最も人気のある量子計算関連の研究論文のトップ 5 を検索してください。")
要点:Bedrock AgentCore Gateway は、AI と既存の Web を結ぶ究極の架け橋です。標準的なドキュメントを機能するコードに変換し、ツール単一から数分で API エコシステム全体へとエージェントの能力を拡張させることを可能にします。手動記写から仕様駆動型の統合へ移行することで、エージェントは常に消費しているサービスの最新バージョンと常に一致します。
Original Content
One of the biggest hurdles in agent development is manually writing "glue code" for every external API. Bedrock AgentCore Gateway eliminates this by providing a "zero-code" path to tool creation. By pointing the Gateway to a standard OpenAPI specification (Swagger), it automatically generates a Model Context Protocol (MCP) server. This allows your Strands Agent to understand and interact with any REST API—complete with complex request schemas and authentication—without you writing a single line of integration logic.
The Gateway also handles enterprise-grade security by managing the handshake between your agent and the external service. You can configure JWT-based authentication for the agent itself and link it to AgentCore Identity to securely inject the external API keys (like Exa or Slack) into the headers of every outgoing request.
Instead of writing Python functions, you simply register the API's OpenAPI URL. The Gateway parses the specification and instantly exposes every endpoint as a callable tool for the agent.
from bedrock_agentcore.tools.gateway_client import GatewayClient
# Initialize the Gateway Client
gateway_client = GatewayClient(region="us-east-1")
# Create a Gateway that converts an OpenAPI spec into MCP tools
gateway = gateway_client.create_gateway(
name="ExaSearchGateway",
auth_config={"type": "JWT"}, # Secure the gateway itself
targets=[{
"name": "ExaAPI",
"openapi_url": "https://api.exa.ai/openapi.json", # The "source of truth"
"credential_provider_id": "your-secure-credential-id" # Injected securely
}]
)
print(f"Gateway generated MCP endpoint: {gateway['endpoint']}")
The Strands Agent treats the Gateway like any other toolset. Because the Gateway provides full semantic descriptions from the OpenAPI spec, the agent knows exactly which parameters to send to the external API to get the job done.
from strands import Agent
from strands.models import BedrockModel
from strands_tools.gateway import AgentCoreGateway
# Connect the Strands Agent to the Gateway
agentcore_gateway = AgentCoreGateway(region="us-east-1", gateway_id=gateway["id"])
agent = Agent(
model=BedrockModel(model_id="us.amazon.nova-pro-v1:0"),
system_prompt="You are a research assistant. Use the Exa tools to find live data.",
tools=[agentcore_gateway.gateway] # All OpenAPI endpoints are now tools
)
# The agent automatically picks the correct 'search' endpoint from the spec
agent("Search for the top 5 trending research papers in Quantum Computing from this week.")
Key Takeaway: Bedrock AgentCore Gateway is the ultimate bridge between AI and the existing web. It turns standard documentation into functional code, allowing you to scale an agent's capabilities from a single tool to an entire ecosystem of APIs in minutes. By moving from manual coding to specification-driven integration, you ensure your agents are always aligned with the latest version of the services they consume.