

# A/B 測試先決條件
<a name="ab-testing-prereqs"></a>

建立 A/B 測試之前，請確定已備妥下列資源。

## 必要的資源
<a name="ab-prereqs-resources"></a>


| 資源 | 說明 | 
| --- | --- | 
| AgentCore Gateway | 具有至少一個 HTTP 目標的作用中 AgentCore Gateway，指向您的代理程式執行時間。AgentCore Gateway 會處理變體之間的流量分割。 | 
| 代理程式執行時間 | 至少一個使用 Amazon Bedrock AgentCore SDK (1.8 版以上） 的已部署代理程式執行期。軟體開發套件`BaggageSpanProcessor`會自動將 A/B 測試實驗詳細資訊 （實驗 ARN 和變體名稱） 連接到執行時間發出的所有 OpenTelemetry 範圍。[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/bedrock-agentcore/latest/devguide/ab-testing-prereqs.html) | 
| 線上評估組態 | 作用中的線上評估組態，指定要針對工作階段執行哪些評估器。[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/bedrock-agentcore/latest/devguide/ab-testing-prereqs.html) | 
| 組態套件 （選用） | 使用組態套件型變體時為必要。兩個套件版本或兩個不同的套件：一個用於控制，另一個用於處理。 | 

## 開發套件需求
<a name="ab-prereqs-sdk"></a>

需要 Amazon Bedrock AgentCore SDK 1.8 版或更新版本。開發套件包含讀取 AgentCore Gateway 傳播的實驗封包標頭的 `BaggageSpanProcessor`，並自動用實驗 ARN 和變體名稱對 OpenTelemetry 的所有執行時間加上戳記。線上評估管道會讀取這些屬性，將工作階段分數映射至正確的變體。您的代理程式程式碼不需要額外的檢測。

## 評估者要求
<a name="ab-prereqs-evaluators"></a>

**注意**  
A/B 測試支援內建、自訂 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 Gateway 操作、組態套件讀取、線上評估組態讀取和 CloudWatch Logs 存取的許可。

**注意**  
只有在您擁有自己的執行角色並使用 傳遞時，才需要手動建立此角色`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:*"
            ]
        }
    ]
}
```