

# Gestione e A/B test
<a name="ab-testing-manage"></a>

Aggiorna un A/B test per avviarlo, metterlo in pausa o interromperlo. L'`UpdateABTest`operazione viene utilizzata per modificare lo stato di esecuzione.

**Nota**  
I comandi del ciclo di vita della AgentCore CLI (`view`,,,`pause`, `resume` `stop``promote`,`archive`) identificano un test in base all'**ID del processo** passato con`-i, --id`, non per nome. Ottieni l'ID da `agentcore run ab-test --json` (il `id` campo) o elencando i test con. `agentcore view ab-test` L'ID del lavoro utilizza il formato`name-suffix`. Ad esempio: `customerSupportTargetTest-Ab1Cd2Ef3G`. I record dei lavori vengono archiviati localmente come JSON `.cli/jobs/ab-tests/` nel progetto.

## Esempi di codice
<a name="manage-ab-test-examples"></a>

### Visualizza, metti in pausa, riprendi e interrompi
<a name="manage-ab-test-start-stop"></a>

**Example**  
Elenca tutti i processi di A/B test o visualizzane uno in dettaglio (visualizza anche l'URL di invocazione e i risultati):  

```
agentcore view ab-test
agentcore view ab-test <ab-test-id>
```
Riprendi un test in pausa:  

```
agentcore resume ab-test -i <ab-test-id>
```
Metti in pausa un test in esecuzione. Il traffico si interrompe e tutte le richieste vengono indirizzate alla variante di controllo. Può essere ripreso.  

```
agentcore pause ab-test -i <ab-test-id>
```
Interrompi definitivamente un test. Tutto il traffico torna alla variante di controllo. Questa operazione non può essere annullata.  

```
agentcore stop ab-test -i <ab-test-id>
```
Avvia un test (imposta lo stato di esecuzione su`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']}")
```
Metti in pausa un test in esecuzione:  

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

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

### Promuovi la variante del trattamento
<a name="manage-ab-test-promote"></a>

Quando i risultati sono statisticamente significativi, promuovi la variante del trattamento. `promote`interrompe il test e scrive la variante di trattamento`agentcore.json`; eseguila `agentcore deploy` successivamente per implementarla.

**Example**  

```
agentcore promote ab-test -i <ab-test-id>
agentcore deploy
```
L'SDK non ha un'unica operazione di «promozione». Interrompi il test, quindi applica tu stesso la variante vincente alle tue risorse (ad esempio, aggiornando il pacchetto di configurazione del controllo o il gateway target in base al trattamento).

### Eliminare un test A/B
<a name="manage-ab-test-remove"></a>

Eliminare un A/B test e i relativi metadati associati. Il test deve essere in stato di `STOPPED` esecuzione prima di poter essere eliminato. L'eliminazione di un test non influisce sui bundle di configurazione, sul AgentCore gateway o sulla configurazione di valutazione online a cui il test ha fatto riferimento.

**Example**  

```
agentcore archive ab-test -i <ab-test-id>
```
Interrompi e poi elimina:  

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

## Transizioni dello stato di esecuzione
<a name="manage-ab-test-execution-states"></a>


| Da | Per | Description | 
| --- | --- | --- | 
|  `NOT_STARTED`  |  `RUNNING`  | Inizia il test. Il AgentCore Gateway inizia a suddividere il traffico. | 
|  `RUNNING`  |  `PAUSED`  | Metti in pausa il test. Il traffico smette di dividersi; tutte le vie di traffico da controllare. | 
|  `PAUSED`  |  `RUNNING`  | Riprendi un test in pausa. | 
|  `RUNNING`  |  `STOPPED`  | Interrompi definitivamente il test. Il routing del traffico termina immediatamente. | 
|  `PAUSED`  |  `STOPPED`  | Interrompi definitivamente un test in pausa. | 