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

字符串

要更新的配置包的 ID。作为路径参数传递。

bundleName

字符串

更新了捆绑包的名称。

description

字符串

更新了描述。最多 500 个字符。

components

Map

更新了组件配置。使用这些组件创建新版本。

parentVersionIds

字符串列表

用于世系跟踪的父版本 ID。更新时为必填项components定期提交:单亲提交。合并提交:两个父分支(目标分支最新,源分支最新)。如果分支已经存在,则第一个父分支必须是该分支上的最新版本。

branchName

字符串

此版本的分支名称。如果未指定,则继承父分支或默认为。mainline

commitMessage

字符串

提交描述更改的消息。最多 500 个字符。

createdBy

对象

创建此版本的来源。包含name(必填)和arn(可选)。使用它来跟踪版本是由用户、推荐作业还是其他自动化创建的。

clientToken

字符串

等能令牌。

响应

字段 Type 说明

bundleArn

字符串

配置包的 ARN。

bundleId

字符串

配置包的 ID。

versionId

字符串

此更新创建的新版本的 UUID。

updatedAt

Timestamp

何时应用更新。

分支和合并

配置包支持类似 git 的分支:

  • 线性提交。省略parentVersionIds或传递单亲父母。新版本扩展了分支血统。

  • 新分支。指定尚不branchName存在的,并parentVersionIds指向要从中分支的版本。

  • 合并提交。第二步parentVersionIds:第一个是目标分支上的最新版本,第二个是源分支上的最新版本。这将在目标分支上创建合并提交。

错误

错误 HTTP 状态 说明

ValidationException

400

请求参数无效。检查字段限制。

ResourceNotFoundException

404

指定的bundleId不存在。

ConflictException

409

版本冲突。指定的父版本不是分支上的最新版本。获取最新版本并重试。

AccessDeniedException

403

权限不足。验证 IAM 策略是否包含bedrock-agentcore:UpdateConfigurationBundle

ThrottlingException

429

超出请求速率。使用指数回退进行重试。

InternalServerException

500

Service-side 错误。重试请求。