trainingSession

fun <Input, Output, InputLabel> trainingSession(experimentName: ExperimentName, trackedAgent: GraphAIAgent<Input, Output>, dataset: TrainSet<Input, InputLabel>, substepPromptExecutor: PromptExecutor, metric: (TrainSetItem<Input, InputLabel>, Output) -> Double, serializers: DatasetExecutionSerializers<Input, Output, InputLabel>, threshold: Double = 0.9, consumptionCollector: () -> LLMConsumption? = { null }, logger: KLogger = KotlinLogging.logger {}): TrainingSession<Input, Output, InputLabel>

Builds a TrainingSession for the common case in a single call, filling in library defaults: no smart failure recognition (NoOpFailureAnalyzer), LiteLLM token capture (LiteLLMConsumptionCapturingPromptExecutor, which reads koog's standard token counts), single-attempt runs (RetryPolicy.None), ActionLogTruncation.DEFAULT, no records file, and no cluster/spend-limit metadata.

Reach for the TrainingResources/TrainingSession constructors directly when you need to customize any of those injection points (provider-specific failure analysis, retries, abort policies, progress listeners, cluster metadata, …), or to persist a training-records JSON — this builder keeps records in-memory only (TrainingSession.use returns them as a TrainingResult).

The serializers are still required despite the missing records file: they serialize that in-memory result and the optimizer's own saved artifact, which is written separately by the optimizer regardless of the records path.

To capture real token consumption per agent run, build trackedAgent on a LiteLLMConsumptionCapturingPromptExecutor and pass its collectAndClear as consumptionCollector:

val capturing = LiteLLMConsumptionCapturingPromptExecutor(executor)
val agent = AIAgent.invokeGraphAgent(promptExecutor = capturing, /* … */)
val session = trainingSession(
experimentName = ExperimentName(runId = "demo", optimizerName = "GEPA", agentName = "agent"),
trackedAgent = agent,
dataset = dataset,
substepPromptExecutor = executor,
metric = metric,
serializers = serializers,
consumptionCollector = { capturing.collectAndClear() },
)