View a markdown version of this page

資料集結構描述 - Amazon Bedrock AgentCore

資料集結構描述

資料集包含一或多個案例。每個案例都代表與客服人員的對話 (工作階段)。隨需批次資料集執行器都使用相同的資料集格式。

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,而 assertionsexpected_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 說明

scenario_id

String

非空白

案例的唯一識別符。

turns

物件清單

非空白清單

對話中的轉彎清單。每個轉彎都有 input(必要) 和 expected_response(選用)。

expected_trajectory

字串清單

預期的工具名稱序列。由軌跡評估器 (Builtin.TrajectoryExactOrderMatchBuiltin.TrajectoryInOrderMatch、) 使用Builtin.TrajectoryAnyOrderMatch

assertions

字串清單

有關預期行為的自然語言聲明。使用者:Builtin.GoalSuccessRate

metadata

物件

案例的任意鍵值中繼資料。

開啟欄位

欄位 必要 Type Constraints 說明

input

字串或物件

非空白

傳送給客服人員的提示。可以是純字串 (例如 "What is my balance?") 或結構化物件 (例如 {"role": "user", "content": "What is my balance?"})。

expected_response

String

此回合的預期客服人員回應。使用者:Builtin.Correctness。將位置映射至此轉產生的追蹤;將 0 個映射轉換為追蹤 0,將 1 個映射轉換為追蹤 1。

模擬案例

模擬案例會定義演員描述檔和初始輸入。演員會動態產生後續轉彎:

{ "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 說明

scenario_id

String

非空白

案例的唯一識別符。

actor_profile

物件

必須包含 contextgoal

演員的身分和目標,包含 context(必要)、 goal (必要) 和 traits(選用)。請參閱使用者模擬

input

字串或物件

非空白

傳送給客服人員以開始對話的第一個訊息。通常為純字串,但也可以是結構化物件。

scenario_description

String

描述案例的選用中繼資料。用於整理和識別結果中的案例。

max_turns

Integer

必須 ≥ 1

對話停止前的轉彎次數上限。預設值:10

assertions

字串清單

有關預期行為的自然語言聲明。使用者:Builtin.GoalSuccessRate

metadata

物件

案例的任意鍵值中繼資料。

注意

模擬案例不支援expected_trajectory或迴轉,expected_response因為對話流程無法事先得知。將 assertions用於模擬案例的 Ground Truth。

Ground Truth 映射

兩個執行器會自動將資料集欄位映射至使用它們的評估器:

評估者 Ground Truth 欄位 Level 說明

Builtin.Correctness

turns[].expected_response

追蹤

測量客服人員的回應符合預期答案的準確度。

Builtin.GoalSuccessRate

assertions

Session (工作階段)

驗證客服人員的行為是否符合自然語言聲明。

Builtin.TrajectoryExactOrderMatch

expected_trajectory

Session (工作階段)

檢查實際工具呼叫序列是否完全相符。

Builtin.TrajectoryInOrderMatch

expected_trajectory

Session (工作階段)

檢查預期工具是否按順序顯示,允許它們之間的額外項目。

Builtin.TrajectoryAnyOrderMatch

expected_trajectory

Session (工作階段)

檢查所有預期的工具是否存在,無論順序為何。

  • Ground Truth 欄位為選用。不使用 Ground Truth (例如 Builtin.HelpfulnessBuiltin.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()