View a markdown version of this page

管理 A/B 测试 - Amazon Bedrock AgentCore

管理 A/B 测试

更新 A/B 测试以启动、暂停或停止。您可以使用该UpdateABTest操作来更改执行状态。

注意

AgentCore CLI 生命周期命令(viewpauseresumestoppromote、、、archive)通过传递的任务 ID 而不是名称来标识测试。-i, --idagentcore run ab-test --jsonid字段)或通过列出测试来获取 ID agentcore view ab-test。作业 ID 使用格式name-suffix。例如:customerSupportTargetTest-Ab1Cd2Ef3G。Job 记录以 JSON 形式存储.cli/jobs/ab-tests/在本地项目中。

代码示例

查看、暂停、恢复和停止

AgentCore CLI

列出所有 A/B 测试作业,或详细查看一个测试作业(还会显示调用网址和结果):

agentcore view ab-test agentcore view ab-test <ab-test-id>

恢复暂停的测试:

agentcore resume ab-test -i <ab-test-id>

暂停正在运行的测试。流量停止分割,所有请求都会路由到控制变体。可以恢复。

agentcore pause ab-test -i <ab-test-id>

永久停止测试。所有流量都将恢复到控制变体。此操作无法撤消。

agentcore stop ab-test -i <ab-test-id>
AWS SDK (boto3)

开始测试(将执行状态设置为RUNNING):

import boto3 import uuid client = boto3.client("bedrock-agentcore", region_name="us-west-2") response = client.update_ab_test( abTestId="customerSupportPromptTest-Ab1Cd2Ef3G", executionStatus="RUNNING", clientToken=str(uuid.uuid4()), ) print(f"Execution status: {response['executionStatus']}")

暂停正在运行的测试:

response = client.update_ab_test( abTestId="customerSupportPromptTest-Ab1Cd2Ef3G", executionStatus="PAUSED", clientToken=str(uuid.uuid4()), ) print(f"Execution status: {response['executionStatus']}")

永久停止正在运行的测试:

response = client.update_ab_test( abTestId="customerSupportPromptTest-Ab1Cd2Ef3G", executionStatus="STOPPED", clientToken=str(uuid.uuid4()), ) print(f"Execution status: {response['executionStatus']}")

推广治疗变体

当结果具有统计学意义时,推广治疗变体。 promote停止测试并将治疗变体写入agentcore.json;然后agentcore deploy运行以将其推出。

AgentCore CLI
agentcore promote ab-test -i <ab-test-id> agentcore deploy
AWS SDK (boto3)

SDK 没有单一的 “升级” 操作。停止测试,然后自己将获胜的变体应用于您的资源(例如,更新控制配置包或网关目标以匹配处理方法)。

删除 A/B 测试

删除 A/B 测试及其关联的元数据。在删除测试之前,测试必须处于STOPPED执行状态。删除测试不会影响该测试引用的配置包、 AgentCore 网关或在线评估配置。

AgentCore CLI
agentcore archive ab-test -i <ab-test-id>
AWS SDK (boto3)

停止然后删除:

import boto3 import uuid client = boto3.client("bedrock-agentcore", region_name="us-west-2") # First stop the test if it's running client.update_ab_test( abTestId="customerSupportPromptTest-Ab1Cd2Ef3G", executionStatus="STOPPED", clientToken=str(uuid.uuid4()), ) # Then delete response = client.delete_ab_test( abTestId="customerSupportPromptTest-Ab1Cd2Ef3G" ) print(f"Deleted: {response['abTestId']}")

执行状态转换

来源 目标 说明

NOT_STARTED

RUNNING

开始测试。 AgentCore 网关开始分流量。

RUNNING

PAUSED

暂停测试。交通停止分裂;所有交通路线都要控制。

PAUSED

RUNNING

恢复暂停的测试。

RUNNING

STOPPED

永久停止测试。流量路由立即结束。

PAUSED

STOPPED

永久停止暂停的测试。