runStage

abstract suspend fun <T> runStage(name: String, substagesTotal: Int? = null, metrics: MetricsMap = standardStageMetrics(), block: suspend StageScope<Input, Output, InputLabel>.() -> T): Result<T>

Runs a named substage. Creates a StageRecord as a substage of the current stage.

Exceptions from the block are caught, recorded as a stage failure, and wrapped in StageFailedException. Use .getOrThrow() to re-throw.

Parameters

name

The display name of this substage.

substagesTotal

How many substages does this stage have. Used to calculate ETC and progress.

metrics

The metrics preset for the substage. Defaults to standardStageMetrics; pass a different preset (e.g. ai.koog.agents.optimization.training.metrics.datasetIterationMetrics) when the stage needs an extended set. Follow the standardStageMetrics() + extras convention so cluster progress and consumption tracking keep working. Pass a fresh MetricsMap per call (factory or +); the map is mutated in place during the stage's lifetime, so sharing instances across stages is unsafe.