数据集架构
一个数据集包含一个或多个场景。每个场景都代表与代理的对话(会话)。按需数据集运行器和批处理数据集运行器都使用相同的数据集格式。
S AgentCore DK 支持两种场景类型:
-
预定义场景使用您手动创作的固定回合顺序。跑步者完全按照所写的那样重播转弯。
-
模拟场景使用 LLM-backed 角色根据角色和目标动态生成回合。有关角色配置文件和仿真配置的详细信息,请参阅用户模拟。
FileDatasetProvider从 JSON 结构中自动检测场景类型:带turns字段的场景按预定义加载;带actor_profile字段(且没有turns)的场景按模拟方式加载。
预定义场景
预定义的场景指定了固定的回合顺序,其中包含已知的输入和可选的预期输出。
Single-turn 示例
每个场景都会发送一个提示并检查响应:
{ "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 示例
Multi-turn 每个场景都有多个回合。轮流在同一个会话中按顺序执行,保持对话上下文。每个回合可以有自己的 expected_response while,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" ] } ] }
场景字段
| 字段 | 必填 | Type | 约束 | Description |
|---|---|---|---|---|
|
|
是 |
字符串 |
Non-empty |
场景的唯一标识符。 |
|
|
是 |
对象列表 |
Non-empty 名单 |
对话中的轮流清单。每回合都有 |
|
|
否 |
字符串列表 |
预期的工具名称顺序。由轨迹赋值器 ( |
|
|
|
否 |
字符串列表 |
关于预期行为的自然语言断言。由 |
|
|
|
否 |
对象 |
该场景的任意键值元数据。 |
转弯场
| 字段 | 必填 | Type | 约束 | Description |
|---|---|---|---|---|
|
|
是 |
字符串或对象 |
Non-empty |
本回合中发送给特工的提示。可以是纯字符串(例如 |
|
|
否 |
字符串 |
本回合的预期特工响应。由 |
模拟场景
模拟场景定义了演员配置文件和初始输入。Actor 动态生成后续回合:
{ "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" ] } ] }
场景字段
| 字段 | 必填 | Type | 约束 | Description |
|---|---|---|---|---|
|
|
是 |
字符串 |
Non-empty |
场景的唯一标识符。 |
|
|
是 |
对象 |
必须包含 |
演员的身份和目标,包含 |
|
|
是 |
字符串或对象 |
Non-empty |
发送给您的代理以开始对话的第一条消息。通常是纯字符串,但也可以是结构化对象。 |
|
|
否 |
字符串 |
描述场景的可选元数据。对于组织和识别结果中的场景很有用。 |
|
|
|
否 |
整数 |
必须等于 1 |
对话停止前的最大回合数。默认值:10。 |
|
|
否 |
字符串列表 |
关于预期行为的自然语言断言。由 |
|
|
|
否 |
对象 |
该场景的任意键值元数据。 |
注意
模拟场景不支持expected_trajectory或逐回合,expected_response因为事先不知道对话流程。assertions用于模拟场景的真实情况。
地面实况测绘
两个运行器都会自动将数据集字段映射到使用它们的赋值器:
| 评估者 | 地面真相字段 | 级别 | 说明 |
|---|---|---|---|
|
|
|
跟踪 |
衡量代理的响应与预期答案相匹配的准确程度。 |
|
|
|
会话 |
验证代理的行为是否满足自然语言断言。 |
|
|
|
会话 |
检查实际的工具调用顺序是否完全匹配。 |
|
|
|
会话 |
检查预期的工具是否按顺序显示,允许它们之间有额外内容。 |
|
|
|
会话 |
检查所有预期的工具是否都存在,无论顺序如何。 |
-
真实情况字段是可选的。不使用基本真相(例如
Builtin.Helpfulness,Builtin.Faithfulness)的评估者仅根据会话内容进行评估。 -
您可以将所有真实数据字段包含在单个数据集中。每个跑步者都会将相关字段路由到相应的赋值器。
-
如果不存在地面真值字段,则赋值器会回退到其地面无真值模式。
有关地面真值字段及其如何与 Evaluate API 配合使用的更多详细信息,请参阅地面真值评估。
内联数据集构造
您可以直接在 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()