dataset.startExperimentAsync()
新增於: @mastra/core@1.4.0
以非同步方式啟動實驗(啟動後即不再等待)。立即傳回實驗 ID 及 'pending' 狀態;實驗會在背景執行。
使用範例使用範例 的直接連結
import { Mastra } from '@mastra/core'
const mastra = new Mastra({/* storage config */})
const dataset = await mastra.datasets.get({ id: 'dataset-id' })
// Start experiment without waiting
const { experimentId, status } = await dataset.startExperimentAsync({
targetType: 'agent',
targetId: 'my-agent',
scorers: ['accuracy'],
})
console.log(`Experiment ${experimentId} started with status: ${status}`)
// Check progress later
const experiment = await dataset.getExperiment({ experimentId })
console.log(`Current status: ${experiment.status}`)
參數參數 的直接連結
接受與 dataset.startExperiment() 相同的 StartExperimentConfig。
當 persistence.experiments 設為 'none' 時,startExperimentAsync() 不會保存實驗記錄、進度更新或項目結果。分數保存仍由 persistence.scores 獨立控制。如沒有實驗事件觀察器,執行會在啟動後即不再等待,而實驗 API 無法回報其完成或失敗狀態。
如呼叫端需要傳回的摘要,請使用同步的 startExperiment()。實驗事件觀察器可接收生命週期事件及終止摘要。
傳回值傳回值 的直接連結
result:
Promise<object>
包含實驗 ID 的即時回應。
object
experimentId:
string
已建立實驗的唯一 ID。
status:
'pending'
實驗尚未開始執行,因此必定為
'pending'。