View a markdown version of this page

Erste Schritte mit Konfigurationspaketen - Amazon Grundgestein AgentCore

Erste Schritte mit Konfigurationspaketen

Diese exemplarische Vorgehensweise führt Sie von Null zu einem versionierten Konfigurationspaket, das Ihr Agent zur Laufzeit liest. Sie erstellen ein Paket, aktualisieren es, um eine neue Version zu erstellen, lesen die Konfiguration und sehen sich den Versionsverlauf an.

Bevor Sie beginnen

Stellen Sie Folgendes sicher:

  • Ein AgentCore CLI-Projekt mit einem auf AgentCore Runtime bereitgestellten Agenten (oder folgen Sie dem Anhang unten, um eines mit Unterstützung für das Konfigurationspaket zu erstellen)

  • AWS Anmeldeinformationen mit Berechtigungen für bedrock-agentcore und bedrock-agentcore-control (siehe Voraussetzungen)

Die folgenden Konstanten werden in den boto3-Beispielen verwendet. Ersetze sie durch deine eigenen Werte:

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

Schritt 1: Erstellen Sie ein Konfigurationspaket

Erstellen Sie ein Paket mit der Erstkonfiguration Ihres Agenten. Das Bundle speichert Schlüssel-Wert-Paare (Systemaufforderung, Modell-ID, Temperatur, Werkzeugbeschreibungen), die durch den Komponenten-ARN eingegeben werden.

Beispiel
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

Nach der Bereitstellung druckt die CLI die Bundle-ID und die ursprüngliche Versions-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}")

Schritt 2: Aktualisieren Sie das Bundle

Nachdem Sie eine Batch-Auswertung durchgeführt und festgestellt haben, dass die Antworten Ihres Agenten zu ausführlich sind, aktualisieren Sie die Systemaufforderung. Bei jedem Update wird eine neue unveränderliche Version erstellt.

Beispiel
AgentCore CLI

Bearbeiten Sie die Bundle-Konfiguration in und stellen Sie sie agentcore.json dann erneut bereit:

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

Die CLI erkennt das vorhandene Bundle und erstellt automatisch eine neue Version.

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}")

Schritt 3: Lesen Sie das Bundle

Rufen Sie die aktuelle Konfiguration ab, um zu überprüfen, ob das Update wirksam wurde.

Beispiel
AgentCore CLI
agentcore config-bundle versions --name myAgentConfig

Die Ausgabe zeigt den Versionsverlauf mit Commit-Nachrichten:

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')}")

Schritt 4: Versionen vergleichen

Vergleichen Sie zwei Versionen, um genau zu sehen, was sich geändert hat:

Beispiel
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)}")

Nächste Schritte

  • Führen Sie eine Batch-Auswertung durch, um die Auswirkungen Ihrer Konfigurationsänderung zu messen. Siehe Batch-Auswertung.

  • Verwenden Sie Empfehlungen, damit der Service automatisch optimierte Eingabeaufforderungen generiert. Siehe Empfehlungen.

  • Richten Sie A/B Tests ein, um zwei Bundle-Versionen mit Live-Traffic zu vergleichen. Siehe A/B Testen.

  • Verzweigen Sie Ihre Konfiguration für Experimente, ohne die Hauptleitung zu beeinträchtigen. Siehe Ein Konfigurationspaket aktualisieren.

Anhang: Agentencode mit Integration des Konfigurationspakets

Der folgende Agentencode liest das aktive Konfigurationspaket zur Laufzeit mithilfe des BeforeModelCallEvent Hook-Musters. Der Agent wird einmal auf Modulebene erstellt, und der Hook aktualisiert die Systemaufforderung vor jedem Modellaufruf dynamisch. Änderungen am Konfigurationspaket werden sofort wirksam, ohne dass ein Neustart erforderlich ist.

  • SDK-Anforderung: bedrock-agentcore-sdk-python Version 1.8 oder höher ist erforderlich. Die get_config_bundle() Methode on BedrockAgentCoreContext ist ab dieser Version verfügbar.

Speichern Sie dies unter dem Namen Ihres main.py Agenten:

"""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()