Back to Mastra

Reference: dataset.startExperimentAsync() | Datasets

docs/src/content/en/reference/datasets/startExperimentAsync.mdx

2025-12-181.7 KB
Original Source

dataset.startExperimentAsync()

Added in: @mastra/[email protected]

Starts an experiment asynchronously (fire-and-forget). Returns immediately with the experiment ID and a 'pending' status. The experiment runs in the background.

Usage example

typescript
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}`)

Parameters

Takes the same StartExperimentConfig as dataset.startExperiment().

Returns

<PropertiesTable content={[ { name: 'result', type: 'Promise<object>', description: 'Immediate response with experiment ID.', properties: [ { type: 'object', parameters: [ { name: 'experimentId', type: 'string', description: 'Unique ID of the created experiment.', }, { name: 'status', type: "'pending'", description: "Always 'pending' since the experiment hasn't started executing yet.", }, ], }, ], }, ]} />