dataset.runExperimentItem()
Added in: @mastra/core@1.61.0
Executes one experiment item server-side: runs the experiment's target against the item, runs the resolved scorers, and upserts the result row keyed by (experimentId, itemId, attempt).
Built for caller-driven loops where a durable orchestrator (for example a Temporal workflow) fans out one call per item and owns retries and timeouts. A retried call converges on the same row. Requires an experiment created with a target via createExperiment().
Scorers resolve with the same precedence as native runs: experiment scorers win over item scorerIds, which win over dataset scorerIds.
Usage exampleDirect link to Usage example
const { experimentId } = await dataset.createExperiment({
targetType: 'agent',
targetId: 'translation-agent',
scorers: ['accuracy'],
})
const { result, scores } = await dataset.runExperimentItem({
experimentId,
itemId: 'item-1',
})
console.log(result.output)
console.log(scores)
Each call executes the item once, retrying up to maxRetries times when you pass it, and you pass run options such as agentModel or itemTimeout on every call because the experiment record doesn't store them.
Calling it on a target-less experiment throws EXPERIMENT_HAS_NO_TARGET. Use submitExperimentResult() for those. Calls after finalization throw EXPERIMENT_ALREADY_FINALIZED, and an itemId that isn't visible at the pinned dataset version throws DATASET_ITEM_NOT_FOUND.
ParametersDirect link to Parameters
experimentId:
itemId:
attempt?:
0. Same (experimentId, itemId, attempt) upserts the existing row.requestContext?:
agentModel?:
agentModel in `startExperiment()`. Throws for non-agent targets.itemTimeout?:
maxRetries?:
0. Uses exponential backoff. Aborts, timeouts, and tool mock errors aren't retried. The result row records retryCount.unmockedToolPolicy?:
toolMocks don't declare. Defaults to 'allow'. The item's own unmockedToolPolicy wins.versions?:
ReturnsDirect link to Returns
result:
result:
output, error, traceId, attempt, and timestamps.