本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
数据集架构
一个数据集包含一个或多个场景。每个场景都代表与代理的对话(会话)。按需和批处理数据集运行器都使用相同的数据集格式。
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_responseassertions,同时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 |
向代理发送了此回合的提示。可以是纯字符串(例如 |
|
|
否 |
字符串 |
本回合的预期代理响应。由 |
模拟场景
模拟场景定义了演员概况和初始输入。演员动态生成后续回合:
{ "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_response因此模拟场景不支持expected_trajectory每回合。使用assertions模拟场景了解真实情况。
实况测绘
两位运行者都会自动将数据集字段映射到使用它们的评估器:
| 评估员 | 实地真相字段 | 级别 | 说明 |
|---|---|---|---|
|
|
|
追踪 |
衡量代理的响应与预期答案匹配的准确程度。 |
|
|
|
会话 |
验证代理的行为是否满足自然语言断言。 |
|
|
|
会话 |
检查实际的工具调用顺序是否完全匹配。 |
|
|
|
会话 |
检查预期的工具是否按顺序显示,允许它们之间有额外的东西。 |
|
|
|
会话 |
检查所有预期的工具是否都存在,无论顺序如何。 |
-
实况字段是可选的。不使用实情(例如
Builtin.Helpfulness,Builtin.Faithfulness)的评估人员仅根据会话内容进行评估。 -
您可以将所有地面实况字段包含在单个数据集中。每位跑步者将相关字段路由给相应的评估者。
-
如果不存在地面真值字段,则评估人员会退回到地面无真值模式。
有关实地真值字段及其如何与评估 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()