

# A/B 测试先决条件
<a name="ab-testing-prereqs"></a>

在创建 A/B 测试之前，请确保以下资源已准备就绪。

## 所需的资源
<a name="ab-prereqs-resources"></a>


| 资源 | 说明 | 
| --- | --- | 
| AgentCore 网关 | 一个活动 AgentCore 网关，其中至少有一个 HTTP 目标指向您的代理运行时。 AgentCore 网关处理变体之间的流量分配。 | 
| 代理运行时 | 至少有一个使用 Amazon Bedrock AgentCore SDK（版本 1.8\+）部署的代理运行时。SDK `BaggageSpanProcessor` 会自动将 A/B 测试实验详情（实验 ARN 和变体名称）附加到运行时发出的所有 OpenTelemetry 跨度。[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/bedrock-agentcore/latest/devguide/ab-testing-prereqs.html) | 
| 在线评估配置 | 一种有效的在线评估配置，用于指定要对会话运行哪些评估器。[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/bedrock-agentcore/latest/devguide/ab-testing-prereqs.html) | 
| 配置包（可选） | 使用基于配置包的变体时是必需的。两个捆绑包版本或两个单独的捆绑包：一个用于控制，一个用于治疗。 | 

## 软件开发工具包要求
<a name="ab-prereqs-sdk"></a>

需要使用 Amazon Bedrock AgentCore SDK 版本 1.8 或更高版本。SDK `BaggageSpanProcessor` 包含一个读取 Gate AgentCore way 传播的实验行李标头，并自动使用实验 ARN 和变体名称标记所有运行时间 OpenTelemetry 跨度。在线评估管道读取这些属性以将会话分数映射到正确的变体。您的代理代码中不需要其他工具。

## 评估员要求
<a name="ab-prereqs-evaluators"></a>

**注意**  
A/B testing 支持内置 LLM-as-judge、自定义和基于代码的赋值器，但要求每个评估器返回一个用于统计显著性计算的数值。对于自定义 LLM-as-judge 赋值器，请`ratingScale`使用`numerical`比例（不是`categorical`）进行配置。对于基于代码的赋值器，请在[响应](code-based-evaluators.md#code-based-response-schema)架构中包含`value`字段。

## IAM 权限
<a name="ab-prereqs-iam"></a>

 A/B 测试执行角色必须信任`bedrock-agentcore.amazonaws.com`服务主体，并且拥有 AgentCore 网关操作、配置包读取、在线评估配置读取和 CloudWatch 日志访问权限。

**注意**  
只有在您自带执行角色并随之传递时，才需要手动创建此角色`agentcore run ab-test --role-arn <arn>`。如果省略`--role-arn`， AgentCore CLI 将自动为测试创建执行角色。

信任策略示例：

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": "bedrock-agentcore.amazonaws.com"
            },
            "Action": "sts:AssumeRole",
            "Condition": {
                "StringEquals": {
                    "aws:SourceAccount": "${aws:PrincipalAccount}"
                },
                "ArnLike": {
                    "aws:SourceArn": "arn:aws:bedrock-agentcore:*:${aws:PrincipalAccount}:ab-test/*"
                }
            }
        }
    ]
}
```

权限策略示例：

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AgentCoreResources",
            "Effect": "Allow",
            "Action": [
                "bedrock-agentcore:GetGateway",
                "bedrock-agentcore:GetGatewayTarget",
                "bedrock-agentcore:ListGatewayTargets",
                "bedrock-agentcore:CreateGatewayRule",
                "bedrock-agentcore:UpdateGatewayRule",
                "bedrock-agentcore:GetGatewayRule",
                "bedrock-agentcore:DeleteGatewayRule",
                "bedrock-agentcore:ListGatewayRules",
                "bedrock-agentcore:GetOnlineEvaluationConfig",
                "bedrock-agentcore:GetEvaluator",
                "bedrock-agentcore:GetConfigurationBundle",
                "bedrock-agentcore:GetConfigurationBundleVersion",
                "bedrock-agentcore:ListConfigurationBundleVersions"
            ],
            "Resource": "arn:aws:bedrock-agentcore:*:${aws:PrincipalAccount}:*",
            "Condition": {
                "StringEquals": {
                    "aws:ResourceAccount": "${aws:PrincipalAccount}"
                }
            }
        },
        {
            "Sid": "CloudWatchLogsDescribe",
            "Effect": "Allow",
            "Action": [
                "logs:DescribeLogGroups"
            ],
            "Resource": "*"
        },
        {
            "Sid": "CloudWatchLogs",
            "Effect": "Allow",
            "Action": [
                "logs:DescribeIndexPolicies",
                "logs:PutIndexPolicy",
                "logs:StartQuery",
                "logs:GetQueryResults",
                "logs:StopQuery",
                "logs:FilterLogEvents",
                "logs:GetLogEvents"
            ],
            "Resource": [
                "arn:aws:logs:*:${aws:PrincipalAccount}:log-group:/aws/bedrock-agentcore/evaluations/*",
                "arn:aws:logs:*:${aws:PrincipalAccount}:log-group:aws/spans",
                "arn:aws:logs:*:${aws:PrincipalAccount}:log-group:aws/spans:*"
            ]
        }
    ]
}
```