

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 取得批次評估結果
<a name="batch-evaluations-get"></a>

擷取批次評估任務的狀態和結果。輪詢此操作，直到任務達到結束狀態 (`COMPLETED`、 `FAILED`或 `STOPPED`)。

## 程式碼範例
<a name="get-batch-eval-examples"></a>

**Example**  
`--wait` 旗標會控制 `agentcore run batch-evaluation`的行為：  
+ 使用 `--wait`：命令會封鎖，直到任務達到結束狀態為止。
+ 如果沒有 `--wait`： 命令會啟動任務並立即傳回。您可以分別輪詢狀態。

  ```
  # Start a job and block until it reaches a terminal state
  agentcore run batch-evaluation -r MyAgent -e Builtin.Correctness --wait
  
  # List previously started jobs (running jobs are refreshed from the service)
  agentcore batch-evaluations history
  
  # Check the status and results of a single job
  agentcore view batch-evaluation <batch-evaluation-id>
  
  # Non-interactive (JSON) output, the CLI analogue of a get_batch_evaluation polling loop
  agentcore view batch-evaluation <batch-evaluation-id> --json
  
  # Stop a running job
  agentcore stop batch-evaluation -i <batch-evaluation-id>
  ```

  使用來自 `agentcore run batch-evaluation`或`agentcore batch-evaluations history`清單中 CLI 輸出的批次評估 ID。

```
import time
import boto3

client = boto3.client("bedrock-agentcore", region_name="us-west-2")

# Poll until terminal state
while True:
    result = client.get_batch_evaluation(batchEvaluationId=batch_eval_id)
    status = result["status"]
    print(f"Status: {status}")

    if status in ("COMPLETED", "COMPLETED_WITH_ERRORS", "FAILED", "STOPPED"):
        break
    time.sleep(30)

# Display results
if result.get("evaluationResults"):
    er = result["evaluationResults"]
    print(f"Sessions completed: {er.get('numberOfSessionsCompleted', 0)}")
    print(f"Sessions failed:    {er.get('numberOfSessionsFailed', 0)}")
    print(f"Total sessions:     {er.get('totalNumberOfSessions', 0)}")

    for summary in er.get("evaluatorSummaries", []):
        avg = summary.get("statistics", {}).get("averageScore")
        print(f"  {summary['evaluatorId']}: {avg}")
```

## 請求參數
<a name="get-batch-eval-params"></a>


| 參數 | Type | 必要 | 描述 | 
| --- | --- | --- | --- | 
|  `batchEvaluationId`  | String | 是 | 傳回的批次評估 ID`StartBatchEvaluation`。以路徑參數傳遞。 | 

## 回應
<a name="get-batch-eval-response"></a>


| 欄位 | Type | Description | 
| --- | --- | --- | 
|  `batchEvaluationId`  | String | 批次評估 ID。 | 
|  `batchEvaluationArn`  | String | 批次評估的 ARN。 | 
|  `batchEvaluationName`  | String | 任務名稱。 | 
|  `status`  | String | 目前狀態：`PENDING`、`IN_PROGRESS`、`COMPLETED`、`COMPLETED_WITH_ERRORS`、`FAILED`、`STOPPING``STOPPED`、、`DELETING`。 | 
|  `createdAt`  | 時間戳記 | 建立任務時。 | 
|  `evaluators`  | 清單 | 使用的評估者。 | 
|  `outputConfig`  | 物件 | 每個工作階段詳細資訊的 CloudWatch Logs 目的地。包含 `cloudWatchConfig.logGroupName`和 `cloudWatchConfig.logStreamName`。 | 
|  `evaluationResults`  | 物件 | 當任務已處理工作階段時出現。請參閱[了解結果和輸出](batch-evaluations-results.md)。 | 
|  `errorDetails`  | 字串清單 | 任務失敗時的錯誤訊息。 | 

### evaluationResults 欄位
<a name="get-batch-eval-results-fields"></a>


| 欄位 | Type | 說明 | 
| --- | --- | --- | 
|  `numberOfSessionsCompleted`  | Integer | 已成功評估的工作階段數量。 | 
|  `numberOfSessionsFailed`  | Integer | 評估失敗的工作階段數目。 | 
|  `numberOfSessionsInProgress`  | Integer | 仍在評估的工作階段數量。 | 
|  `totalNumberOfSessions`  | Integer | 探索的工作階段總數。 | 
|  `numberOfSessionsIgnored`  | Integer | 忽略進行評估的工作階段數目。此服務會評估每個任務最多 500 個工作階段；如果發現更多工作階段，則會選取最近的 500 個工作階段。 | 
|  `evaluatorSummaries`  | 清單 | 每個評估者彙總結果。 | 

### evaluatorSummaries 欄位
<a name="get-batch-eval-summaries-fields"></a>


| 欄位 | Type | Description | 
| --- | --- | --- | 
|  `evaluatorId`  | String | 評估者 ID （例如 `Builtin.GoalSuccessRate`)。 | 
|  `statistics.averageScore`  | Double | 所有評估工作階段的平均分數。 | 
|  `totalEvaluated`  | Integer | 此評估者獲得分數的工作階段數目。 | 
|  `totalFailed`  | Integer | 此評估器失敗的工作階段數目。 | 

## 狀態生命週期
<a name="get-batch-eval-status-lifecycle"></a>

```
PENDING → IN_PROGRESS → COMPLETED
                      → COMPLETED_WITH_ERRORS
                      → FAILED
         STOPPING     → STOPPED
         DELETING
```
+  **待定** — 已接受任務，並排入佇列進行處理。
+  **IN\_PROGRESS** — 服務正在探索工作階段並執行評估程式。
+  **已完成** — 已評估所有工作階段。結果可用。
+  **COMPLETED\_WITH\_ERRORS** — 已完成任務，但部分工作階段發生錯誤。部分結果可用。
+  **失敗** — 任務發生錯誤。檢查`errorDetails`詳細資訊。
+  **停止 —** 已收到停止請求。任務正在倒轉。
+  **已停止** — 任務在完成之前已停止。部分結果可能可用。
+  **刪除** — 正在刪除任務。

## 錯誤
<a name="get-batch-eval-errors"></a>


| 錯誤 | HTTP 狀態 | 說明 | 
| --- | --- | --- | 
|  `ResourceNotFoundException`  | 404 | 找不到具有指定 ID 的批次評估。 | 
|  `ValidationException`  | 400 | 無效的批次評估 ID 格式。 | 
|  `AccessDeniedException`  | 403 | 許可不足。 | 
|  `ThrottlingException`  | 429 | 超過請求率。 | 
|  `InternalServerException`  | 500 | 服務端錯誤。 | 