資料集結構描述
資料集包含一或多個案例。每個案例都代表與客服人員的對話 (工作階段)。隨需和批次資料集執行器都使用相同的資料集格式。
AgentCore SDK 支援兩種案例類型:
-
預先定義的案例會使用您手動編寫的固定輪換順序。執行器會完全按照寫入的方式重播 轉彎。
-
模擬案例使用 LLM 支援的演員,根據角色和目標動態產生轉彎。如需演員設定檔和模擬組態的詳細資訊,請參閱使用者模擬。
FileDatasetProvider 從 JSON 結構自動偵測案例類型:具有 turns 欄位的案例會以預先定義的方式載入;具有 actor_profile 欄位 (且沒有 turns) 的案例會以模擬方式載入。
預先定義的案例
預先定義的案例會指定具有已知輸入和選用預期輸出的固定輪換序列。
單轉範例
每個案例都會傳送一個提示,並檢查回應:
{ "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"] } ] }
多迴轉範例
多迴轉案例每個案例有多個迴轉。輪換在同一工作階段內循序執行,以維持對話內容。每個回合都可以有自己的 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" ] } ] }
案例欄位
| 欄位 | 必要 | Type | Constraints | 說明 |
|---|---|---|---|---|
|
|
是 |
String |
非空白 |
案例的唯一識別符。 |
|
|
是 |
物件清單 |
非空白清單 |
對話中的轉彎清單。每個轉彎都有 |
|
|
否 |
字串清單 |
預期的工具名稱序列。由軌跡評估器 ( |
|
|
|
否 |
字串清單 |
有關預期行為的自然語言聲明。使用者: |
|
|
|
否 |
物件 |
案例的任意鍵值中繼資料。 |
開啟欄位
| 欄位 | 必要 | Type | Constraints | 說明 |
|---|---|---|---|---|
|
|
是 |
字串或物件 |
非空白 |
傳送給客服人員的提示。可以是純字串 (例如 |
|
|
否 |
String |
此回合的預期客服人員回應。使用者: |
模擬案例
模擬案例會定義演員描述檔和初始輸入。演員會動態產生後續轉彎:
{ "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 | Constraints | 說明 |
|---|---|---|---|---|
|
|
是 |
String |
非空白 |
案例的唯一識別符。 |
|
|
是 |
物件 |
必須包含 |
演員的身分和目標,包含 |
|
|
是 |
字串或物件 |
非空白 |
傳送給客服人員以開始對話的第一個訊息。通常為純字串,但也可以是結構化物件。 |
|
|
否 |
String |
描述案例的選用中繼資料。用於整理和識別結果中的案例。 |
|
|
|
否 |
Integer |
必須 ≥ 1 |
對話停止前的轉彎次數上限。預設值:10 |
|
|
否 |
字串清單 |
有關預期行為的自然語言聲明。使用者: |
|
|
|
否 |
物件 |
案例的任意鍵值中繼資料。 |
注意
模擬案例不支援expected_trajectory或迴轉,expected_response因為對話流程無法事先得知。將 assertions用於模擬案例的 Ground Truth。
Ground Truth 映射
兩個執行器會自動將資料集欄位映射至使用它們的評估器:
| 評估者 | Ground Truth 欄位 | Level | 說明 |
|---|---|---|---|
|
|
|
追蹤 |
測量客服人員的回應符合預期答案的準確度。 |
|
|
|
Session (工作階段) |
驗證客服人員的行為是否符合自然語言聲明。 |
|
|
|
Session (工作階段) |
檢查實際工具呼叫序列是否完全相符。 |
|
|
|
Session (工作階段) |
檢查預期工具是否按順序顯示,允許它們之間的額外項目。 |
|
|
|
Session (工作階段) |
檢查所有預期的工具是否存在,無論順序為何。 |
-
Ground Truth 欄位為選用。不使用 Ground Truth (例如
Builtin.Helpfulness、Builtin.Faithfulness) 的評估者僅根據工作階段內容進行評估。 -
您可以在單一資料集中包含所有 Ground Truth 欄位。每個執行器會將相關欄位路由至適當的評估者。
-
如果沒有地面實況欄位,則評估者會回到其地面實況模式。
如需 Ground Truth 欄位及其使用評估 API 方式的詳細資訊,請參閱 Ground Truth 評估。
內嵌資料集建構
您可以直接在 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()