View a markdown version of this page

更新組態套件 - Amazon Bedrock AgentCore

更新組態套件

更新組態套件,以建立變更組態的新不可變版本。每次更新都會產生新的版本 ID;不會修改現有的版本。版本會透過 形成鏈結parentVersionIds,類似於 git 遞交。

程式碼範例

範例
AgentCore CLI

在 中編輯組態agentcore.json並重新部署。CLI 會偵測現有的套件,並parentVersionIds自動建立具有正確 的新版本:

# Edit the bundle configuration in agentcore.json (change model_id, system prompt, etc.) # Then redeploy to create a new version: agentcore deploy # After deploying, confirm a new immutable version was created: agentcore cb versions --name MyBundle # Inspect what changed between two versions (get IDs from `cb versions`): agentcore cb diff --name MyBundle --from <v1> --to <v2>
AWS SDK (boto3)

更新變更模型 ID:

import boto3 import uuid client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") RUNTIME_ARN = "arn:aws:bedrock-agentcore:us-west-2:123456789012:runtime/MyAgent-abc123" response = client.update_configuration_bundle( bundleId="myAgentConfig-a1b2c3d4e5", components={ RUNTIME_ARN: { "configuration": { "system_prompt": "You are a helpful customer support assistant.", "model_id": "us.anthropic.claude-sonnet-4-20250514-v1:0", "temperature": 0.7, } } }, parentVersionIds=["12345678-1234-1234-1234-123456789012"], commitMessage="Switch to Claude Sonnet 4", clientToken=str(uuid.uuid4()), ) print(f"New version ID: {response['versionId']}")

使用建議結果中的建議系統提示進行更新:

import boto3 import uuid cp_client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") dp_client = boto3.client("bedrock-agentcore", region_name="us-west-2") RUNTIME_ARN = "arn:aws:bedrock-agentcore:us-west-2:123456789012:runtime/MyAgent-abc123" # Get the recommendation result recommendation = dp_client.get_recommendation(recommendationId="myRec-a1b2c3d4e5") recommended_prompt = recommendation["result"]["systemPromptRecommendationResult"]["recommendedSystemPrompt"] # Update the bundle with the recommended prompt response = cp_client.update_configuration_bundle( bundleId="myAgentConfig-a1b2c3d4e5", components={ RUNTIME_ARN: { "configuration": { "system_prompt": recommended_prompt, "model_id": "global.anthropic.claude-sonnet-4-5-20250929-v1:0", "temperature": 0.7, } } }, parentVersionIds=["12345678-1234-1234-1234-123456789012"], commitMessage="Apply recommended system prompt", createdBy={"name": "optimization-job", "arn": recommendation["recommendationArn"]}, clientToken=str(uuid.uuid4()), ) print(f"New version ID: {response['versionId']}")

請求參數

參數 Type 必要 描述

bundleId

String

要更新的組態套件 ID。以路徑參數傳遞。

bundleName

String

已更新套件的名稱。

description

String

已更新描述。最多 500 個字元。

components

Map

已更新元件組態。使用這些元件建立新的版本。

parentVersionIds

字串清單

用於歷程追蹤的父版本 IDs。更新 時為必要components一般遞交:單一父項。合併遞交:兩個父系 (目標分支最新、來源分支最新)。如果分支已存在,則第一個父系必須是該分支的最新版本。

branchName

String

此版本的分支名稱。如果未指定, 會繼承父系的分支或預設為 mainline

commitMessage

String

遞交說明變更的訊息。最多 500 個字元。

createdBy

物件

建立此版本的來源。包含 name(必要) 和 arn(選用)。使用此項目來追蹤版本是由使用者、建議任務或其他自動化所建立。

clientToken

String

等冪性字符。

回應

欄位 Type Description

bundleArn

String

組態套件的 ARN。

bundleId

String

組態套件的 ID。

versionId

String

此更新所建立新版本的 UUID。

updatedAt

時間戳記

套用更新的時間。

分支和合併

組態套件支援類似 git 的分支:

  • 線性遞交。省略parentVersionIds或傳遞單一父系。新版本擴展分支歷程。

  • 新的分支。指定尚不存在branchName的 ,並parentVersionIds指向您要分支的版本。

  • 合併遞交。傳遞兩個 parentVersionIds:第一個是目標分支的最新版本,第二個是來源分支的最新版本。這會在目標分支上建立合併遞交。

錯誤

錯誤 HTTP 狀態 說明

ValidationException

400

無效的請求參數。檢查欄位限制條件。

ResourceNotFoundException

404

指定的 bundleId 不存在。

ConflictException

409

版本衝突。指定的父版本不是分支上的最新版本。擷取最新版本並重試。

AccessDeniedException

403

許可不足。驗證 IAM 政策是否包含 bedrock-agentcore:UpdateConfigurationBundle

ThrottlingException

429

超過請求率。以指數退避重試。

InternalServerException

500

服務端錯誤。重試 請求。