

# A/B テストを管理する
<a name="ab-testing-manage"></a>

A/B テストを更新して、テストを開始、一時停止、または停止します。`UpdateABTest` オペレーションを使用して実行ステータスを変更します。

**注記**  
AgentCore CLI ライフサイクルコマンド (`view`、`pause`、`resume`、`stop`、`archive`) は`promote`、名前ではなく `-i, --id`で渡された**ジョブ ID** によってテストを識別します。でテストを一覧表示して、 `agentcore run ab-test --json` ( `id`フィールド) または から ID を取得します`agentcore view ab-test`。ジョブ ID は 形式を使用します`name-suffix`。例: `customerSupportTargetTest-Ab1Cd2Ef3G`。ジョブレコードは、プロジェクト内の の JSON としてローカル`.cli/jobs/ab-tests/`に保存されます。

## コードサンプル
<a name="manage-ab-test-examples"></a>

### 表示、一時停止、再開、停止
<a name="manage-ab-test-start-stop"></a>

**Example**  
すべての A/B テストジョブを一覧表示するか、詳細を表示します (呼び出し URL と結果も表示されます）。  

```
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>
```
テストを開始します (実行ステータスを に設定します`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']}")
```

### 処理バリアントを昇格させる
<a name="manage-ab-test-promote"></a>

結果が統計的に有意であれば、処理バリアントを昇格させます。 はテスト`promote`を停止し、処理バリアントを に書き込みます`agentcore.json`。`agentcore deploy`その後、 を実行してロールアウトします。

**Example**  

```
agentcore promote ab-test -i <ab-test-id>
agentcore deploy
```
SDK には、単一の「昇格」オペレーションはありません。テストを停止し、勝ったバリアントを自分でリソースに適用します (たとえば、コントロール設定バンドルまたはゲートウェイターゲットを処理に合わせて更新するなど）。

### A/B テストを削除する
<a name="manage-ab-test-remove"></a>

A/B テストとそれに関連するメタデータを削除します。削除する前に、テストが`STOPPED`実行ステータスになっている必要があります。テストを削除しても、テストが参照した設定バンドル、AgentCore Gateway、またはオンライン評価設定には影響しません。

**Example**  

```
agentcore archive ab-test -i <ab-test-id>
```
停止してから、以下を削除します。  

```
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']}")
```

## 実行ステータスの遷移
<a name="manage-ab-test-execution-states"></a>


| から | まで | 説明 | 
| --- | --- | --- | 
|  `NOT_STARTED`  |  `RUNNING`  | テストを開始します。AgentCore Gateway はトラフィックの分割を開始します。 | 
|  `RUNNING`  |  `PAUSED`  | テストを一時停止します。トラフィックの分割が停止します。制御するすべてのトラフィックルート。 | 
|  `PAUSED`  |  `RUNNING`  | 一時停止したテストを再開します。 | 
|  `RUNNING`  |  `STOPPED`  | テストを完全に停止します。トラフィックルーティングはすぐに終了します。 | 
|  `PAUSED`  |  `STOPPED`  | 一時停止したテストを完全に停止します。 | 