View a markdown version of this page

設定バンドルの開始方法 - Amazon Bedrock AgentCore

設定バンドルの開始方法

このチュートリアルでは、実行時にエージェントが読み取るバージョン管理された設定バンドルをゼロから取得します。バンドルを作成し、新しいバージョンを生成するように更新し、設定を読み、バージョン履歴を表示します。

[開始する前に]

以下を確認してください。

  • エージェントを AgentCore Runtime にデプロイした AgentCore CLI プロジェクト (または以下の付録に従って、設定バンドルをサポートするエージェントを作成します)

  • AWS bedrock-agentcoreおよび のアクセス許可を持つ 認証情報 bedrock-agentcore-control (「前提条件」を参照)

boto3 の例では、次の定数が使用されます。それらを独自の値に置き換えます。

REGION = "us-west-2" BUNDLE_ID = "myAgentConfig-a1b2c3d4e5" # from create response COMPONENT_ARN = "arn:aws:bedrock-agentcore:us-west-2:123456789012:runtime/MyAgent-abc123"

ステップ 1: 設定バンドルを作成する

エージェントの初期設定でバンドルを作成します。バンドルには、コンポーネント ARN によってキーと値のペア (システムプロンプト、モデル ID、温度、ツールの説明) が保存されます。

AgentCore CLI
agentcore add config-bundle \ --name myAgentConfig \ --components '{"arn:aws:bedrock-agentcore:us-west-2:123456789012:runtime/MyAgent-abc123": {"configuration": {"system_prompt": "You are a helpful customer support assistant for Acme Store.", "model_id": "global.anthropic.claude-sonnet-4-5-20250929-v1:0"}}}' agentcore deploy

デプロイ後、CLI はバンドル ID と初期バージョン ID を出力します。

AWS SDK (boto3)
import boto3 import uuid client = boto3.client("bedrock-agentcore-control", region_name=REGION) response = client.create_configuration_bundle( bundleName="myAgentConfig", components={ COMPONENT_ARN: { "configuration": { "system_prompt": "You are a helpful customer support assistant for Acme Store.", "model_id": "global.anthropic.claude-sonnet-4-5-20250929-v1:0", "temperature": 0.7, } } }, description="Acme Store agent configuration", commitMessage="Initial configuration", clientToken=str(uuid.uuid4()), ) bundle_id = response["bundleId"] version_id = response["versionId"] print(f"Created bundle: {bundle_id}") print(f"Initial version: {version_id}")

ステップ 2: バンドルを更新する

バッチ評価を実行し、エージェントのレスポンスが詳細すぎることを確認したら、システムプロンプトを更新します。更新ごとに新しいイミュータブルバージョンが作成されます。

AgentCore CLI

でバンドル設定を編集しagentcore.json、再デプロイします。

# Edit the system_prompt in agentcore.json, then: agentcore deploy

CLI は既存のバンドルを検出し、新しいバージョンを自動的に作成します。

AWS SDK (boto3)
response = client.update_configuration_bundle( bundleId=bundle_id, components={ COMPONENT_ARN: { "configuration": { "system_prompt": ( "You are a helpful customer support assistant for Acme Store. " "Be concise. Confirm actions taken in one sentence." ), "model_id": "global.anthropic.claude-sonnet-4-5-20250929-v1:0", "temperature": 0.5, } } }, parentVersionIds=[version_id], commitMessage="Reduce verbosity: shorter prompt, lower temperature", clientToken=str(uuid.uuid4()), ) new_version_id = response["versionId"] print(f"New version: {new_version_id}")

ステップ 3: バンドルを読み取る

現在の設定を取得して、更新が有効になったことを確認します。

AgentCore CLI
agentcore config-bundle versions --name myAgentConfig

出力には、コミットメッセージを含むバージョン履歴が表示されます。

Version                               Branch     Created              Message
────────────────────────────────────────────────────────────────────────────────
a1b2c3d4-...                          mainline   2026-04-28 03:00     Reduce verbosity: shorter prompt, lower temperature
e5f6a7b8-...                          mainline   2026-04-28 02:30     Initial configuration
AWS SDK (boto3)
response = client.get_configuration_bundle(bundleId=bundle_id) config = response["components"][COMPONENT_ARN]["configuration"] print(f"Version: {response['versionId']}") print(f"System prompt: {config['system_prompt']}") print(f"Model: {config['model_id']}") print(f"Temperature: {config.get('temperature')}")

ステップ 4: バージョンを比較する

2 つのバージョンを差分して、何が変更されたかを正確に確認します。

AgentCore CLI
agentcore config-bundle diff --name myAgentConfig --from <version-1> --to <version-2>
AWS SDK (boto3)
# Fetch both versions v1 = client.get_configuration_bundle_version(bundleId=bundle_id, versionId=version_id) v2 = client.get_configuration_bundle_version(bundleId=bundle_id, versionId=new_version_id) # Compare v1_config = v1["components"][COMPONENT_ARN]["configuration"] v2_config = v2["components"][COMPONENT_ARN]["configuration"] for key in set(list(v1_config.keys()) + list(v2_config.keys())): if v1_config.get(key) != v2_config.get(key): print(f"{key}:") print(f" before: {v1_config.get(key)}") print(f" after: {v2_config.get(key)}")

次の手順

  • バッチ評価を実行して、設定変更の影響を測定します。「バッチ評価」を参照してください。

  • 推奨事項を使用して、サービスが最適化されたプロンプトを自動的に生成できるようにします。「推奨事項」を参照してください。

  • A/B テストを設定して、2 つのバンドルバージョンをライブトラフィックと比較します。「A/B テスト」を参照してください。

  • メインラインに影響を与えずに、実験の設定を分岐させます「設定バンドルを更新する」を参照してください。

付録: 設定バンドル統合によるエージェントコード

次のエージェントコードは、 BeforeModelCallEventフックパターンを使用して、実行時にアクティブな設定バンドルを読み取ります。エージェントはモジュールレベルで 1 回作成され、フックは各モデル呼び出しの前にシステムプロンプトを動的に更新します。設定バンドルの変更は、再起動せずにすぐに有効になります。

  • SDK の要件: bedrock-agentcore-sdk-pythonバージョン 1.8 以降が必要です。の get_config_bundle()メソッドBedrockAgentCoreContextは、このバージョン以降から使用できます。

これをエージェントの として保存しますmain.py

"""Agent with Configuration Bundle integration — hooks pattern.""" from strands import Agent, tool from strands.models.bedrock import BedrockModel from strands.hooks.events import BeforeModelCallEvent from bedrock_agentcore.runtime import BedrockAgentCoreApp, BedrockAgentCoreContext app = BedrockAgentCoreApp() DEFAULT_MODEL_ID = "global.anthropic.claude-sonnet-4-5-20250929-v1:0" DEFAULT_SYSTEM_PROMPT = ( "You are a helpful customer support assistant for Acme Store. " "Help customers with their orders, returns, and shipping questions." ) @tool def lookup_order(order_id: str) -> str: """Look up an order by ID.""" orders = { "ORD-1001": {"status": "delivered", "item": "Blue T-Shirt (L)", "total": "$29.99"}, "ORD-1002": {"status": "in_transit", "item": "Running Shoes (10)", "total": "$89.99"}, "ORD-1003": {"status": "delayed", "item": "Wireless Headphones", "days_late": 5, "total": "$59.99"}, } return str(orders.get(order_id, {"error": f"Order {order_id} not found"})) @tool def check_shipping_status(order_id: str) -> str: """Check detailed shipping status for an order.""" statuses = { "ORD-1002": "Package is with carrier, on schedule for April 5.", "ORD-1003": "Package delayed 5 days. Policy: 3+ days late qualifies for 15% discount.", } return statuses.get(order_id, f"No active shipment found for {order_id}.") TOOLS = [lookup_order, check_shipping_status] def dynamic_config_hook(event: BeforeModelCallEvent): """Read config bundle and apply system prompt before every model call.""" config_bundle = BedrockAgentCoreContext.get_config_bundle() event.agent.system_prompt = config_bundle.get("system_prompt", DEFAULT_SYSTEM_PROMPT) agent = Agent( model=BedrockModel(model_id=DEFAULT_MODEL_ID), tools=TOOLS, system_prompt=DEFAULT_SYSTEM_PROMPT, ) agent.hooks.add_callback(BeforeModelCallEvent, dynamic_config_hook) @app.entrypoint def invoke(payload, context): result = agent(payload.get("prompt", "Hello")) return {"response": str(result)} if __name__ == "__main__": app.run()