

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 数据集架构
<a name="dataset-evaluations-schema"></a>

一个数据集包含一个或多个场景。每个场景都代表与代理的对话（会话）。按[需](dataset-evaluations-on-demand.md)和[批处理](dataset-evaluations-batch.md)数据集运行器都使用相同的数据集格式。

S AgentCore DK 支持两种场景类型：
+  **预定义场景**使用您手动创建的固定回合顺序。跑步者完全按照写法重播回合。
+  **模拟场景**使用 LLM-backed 演员根据角色和目标动态生成回合。有关角色配置文件和模拟配置[的详细信息，请参阅](user-simulation.md)用户模拟。

 `FileDatasetProvider`从 JSON 结构中自动检测场景类型：带`turns`字段的场景按预定义加载；带`actor_profile`字段（无字段`turns`）的场景以模拟方式加载。

## 预定义的场景
<a name="dataset-schema-predefined"></a>

预定义的场景指定了具有已知输入和可选预期输出的固定转弯顺序。

### Single-turn 示例
<a name="dataset-schema-predefined-single-turn"></a>

每个场景都会发送一个提示并检查响应：

```
{
  "scenarios": [
    {
      "scenario_id": "math-question",
      "turns": [
        {
          "input": "What is 15 + 27?",
          "expected_response": "15 + 27 = 42"
        }
      ],
      "expected_trajectory": ["calculator"],
      "assertions": ["Agent used the calculator tool to compute the result"]
    },
    {
      "scenario_id": "weather-check",
      "turns": [
        {
          "input": "What's the weather?",
          "expected_response": "The weather is sunny"
        }
      ],
      "expected_trajectory": ["weather"],
      "assertions": ["Agent used the weather tool"]
    }
  ]
}
```

### Multi-turn 示例
<a name="dataset-schema-predefined-multi-turn"></a>

Multi-turn 每个场景都有多个回合。回合在同一个会话中按顺序执行，保持对话上下文。每个回合都有自己的回合 `expected_response``assertions`，同时`expected_trajectory`适用于整个会话：

```
{
  "scenarios": [
    {
      "scenario_id": "math-then-weather",
      "turns": [
        {
          "input": "What is 15 + 27?",
          "expected_response": "15 + 27 = 42"
        },
        {
          "input": "What's the weather?",
          "expected_response": "The weather is sunny"
        }
      ],
      "expected_trajectory": ["calculator", "weather"],
      "assertions": [
        "Agent used the calculator tool for the math question",
        "Agent used the weather tool when asked about weather"
      ]
    }
  ]
}
```

### 场景字段
<a name="dataset-schema-predefined-fields"></a>


| 字段 | 必填 | Type | 约束 | Description | 
| --- | --- | --- | --- | --- | 
|  `scenario_id`  | 是 | 字符串 | Non-empty | 场景的唯一标识符。 | 
|  `turns`  | 是 | 对象列表 | Non-empty 清单 | 对话中的回合清单。每回合都有`input`（必填）和`expected_response`（可选）。 | 
|  `expected_trajectory`  | 否 | 字符串列表 |  | 预期的工具名称顺序。由轨迹评估器 (`Builtin.TrajectoryExactOrderMatch`,`Builtin.TrajectoryInOrderMatch`,`Builtin.TrajectoryAnyOrderMatch`) 使用。 | 
|  `assertions`  | 否 | 字符串列表 |  | 关于预期行为的自然语言断言。由 `Builtin.GoalSuccessRate` 使用。 | 
|  `metadata`  | 否 | 对象 |  | 该场景的任意键值元数据。 | 

### 转弯字段
<a name="dataset-schema-turn-fields"></a>


| 字段 | 必填 | Type | 约束 | Description | 
| --- | --- | --- | --- | --- | 
|  `input`  | 是 | 字符串或对象 | Non-empty | 向代理发送了此回合的提示。可以是纯字符串（例如`"What is my balance?"`）或结构化对象（例如，`{"role": "user", "content": "What is my balance?"}`）。 | 
|  `expected_response`  | 否 | 字符串 |  | 本回合的预期代理响应。由 `Builtin.Correctness` 使用。在位置上映射到本回合生成的轨迹；回合 0 映射到跟踪 0，回合 1 映射到跟踪 1。 | 

## 模拟场景
<a name="dataset-schema-simulated"></a>

模拟场景定义了演员概况和初始输入。演员动态生成后续回合：

```
{
  "scenarios": [
    {
      "scenario_id": "geography-student",
      "scenario_description": "A curious student asks geography questions",
      "actor_profile": {
        "traits": {"expertise": "novice", "tone": "curious"},
        "context": "A student studying world geography who wants to learn about capitals",
        "goal": "Find out the capital cities of at least two different countries"
      },
      "input": "Hi! I'm studying geography. Can you help me learn about world capitals?",
      "max_turns": 5,
      "assertions": [
        "Agent provides accurate capital city information",
        "Agent is helpful and encouraging to the student"
      ]
    }
  ]
}
```

### 场景字段
<a name="dataset-schema-simulated-fields"></a>


| 字段 | 必填 | Type | 约束 | Description | 
| --- | --- | --- | --- | --- | 
|  `scenario_id`  | 是 | 字符串 | Non-empty | 场景的唯一标识符。 | 
|  `actor_profile`  | 是 | 对象 | 必须包含`context`和 `goal`  | 演员的身份和目标，包含`context`（必填）、`goal`（必填）和`traits`（可选）。参见[用户模拟](user-simulation.md)。 | 
|  `input`  | 是 | 字符串或对象 | Non-empty | 发送给您的代理人以开始对话的第一条消息。通常是普通字符串，但也可以是结构化对象。 | 
|  `scenario_description`  | 否 | 字符串 |  | 描述场景的可选元数据。可用于组织和识别结果中的场景。 | 
|  `max_turns`  | 否 | 整数 | 必须等于 1 | 对话停止前的最大回合数。默认值：10。 | 
|  `assertions`  | 否 | 字符串列表 |  | 关于预期行为的自然语言断言。由 `Builtin.GoalSuccessRate` 使用。 | 
|  `metadata`  | 否 | 对象 |  | 该场景的任意键值元数据。 | 

**注意**  
由于事先不知道会话流程，`expected_response`因此模拟场景不支持`expected_trajectory`每回合。使用`assertions`模拟场景了解真实情况。

## 实况测绘
<a name="dataset-schema-ground-truth"></a>

两位运行者都会自动将数据集字段映射到使用它们的评估器：


| 评估员 | 实地真相字段 | 级别 | 说明 | 
| --- | --- | --- | --- | 
|  `Builtin.Correctness`  |  `turns[].expected_response`  | 追踪 | 衡量代理的响应与预期答案匹配的准确程度。 | 
|  `Builtin.GoalSuccessRate`  |  `assertions`  | 会话 | 验证代理的行为是否满足自然语言断言。 | 
|  `Builtin.TrajectoryExactOrderMatch`  |  `expected_trajectory`  | 会话 | 检查实际的工具调用顺序是否完全匹配。 | 
|  `Builtin.TrajectoryInOrderMatch`  |  `expected_trajectory`  | 会话 | 检查预期的工具是否按顺序显示，允许它们之间有额外的东西。 | 
|  `Builtin.TrajectoryAnyOrderMatch`  |  `expected_trajectory`  | 会话 | 检查所有预期的工具是否都存在，无论顺序如何。 | 
+ 实况字段是可选的。不使用实情（例如`Builtin.Helpfulness`，`Builtin.Faithfulness`）的评估人员仅根据会话内容进行评估。
+ 您可以将所有地面实况字段包含在单个数据集中。每位跑步者将相关字段路由给相应的评估者。
+ 如果不存在地面真值字段，则评估人员会退回到地面无真值模式。

有关实地真值字段及其如何与评估 API 配合使用的更多详细信息，请参阅[实况评估](ground-truth-evaluations.md)。

## 内联数据集构建
<a name="dataset-schema-inline-construction"></a>

您可以直接在 Python 中构造数据集，而不是从 JSON 文件中加载：

```
from bedrock_agentcore.evaluation import Dataset, PredefinedScenario, Turn

dataset = Dataset(
    scenarios=[
        PredefinedScenario(
            scenario_id="math-question",
            turns=[
                Turn(
                    input="What is 15 + 27?",
                    expected_response="15 + 27 = 42",
                ),
            ],
            expected_trajectory=["calculator"],
            assertions=["Agent used the calculator tool"],
        ),
        PredefinedScenario(
            scenario_id="weather-check",
            turns=[
                Turn(input="What's the weather?"),
            ],
            expected_trajectory=["weather"],
        ),
    ]
)
```

或者从 JSON 文件中加载：

```
from bedrock_agentcore.evaluation import FileDatasetProvider

dataset = FileDatasetProvider("dataset.json").get_dataset()
```