Stage Scope Impl
Core implementation of StageScope.
Each instance owns a StageRecord whose MetricsMap is recomputed from substages on each substage update, then propagated upward via onUpdate.
Constructors
Properties
The session's dataset, taken from TrainingResources.dataset.
The record this scope owns and mutates; its metrics are recomputed on each substage update.
The session's tracked agent, taken from TrainingResources.trackedAgent.
Functions
Executes an LLM prompt with consumption tracking. Creates a PromptExecutionRecord as a leaf record, recording elapsed time and consumption. On success, returns the raw LLM response messages.
.getOrThrow() shortcut over executePrompt; throws on a recorded execution failure.
Executes a structured LLM prompt with consumption tracking. Creates a PromptExecutionRecord and returns the deserialized structure.
.getOrThrow() shortcut over executePromptStructured; throws on a recorded execution failure.
Runs execute against a fresh consumption-capturing executor and records exactly one leaf entry under the current stage — PromptExecutionRecord.Completed on success, or PromptExecutionRecord.Failed on any failure. Shared by executePrompt and executePromptStructured.
Thin delegate over runStage with the datasetIterationMetrics preset (plus any customMetricsToRecord). Threshold breach throws inside the block so runStage's catch arm records it on the dataset stage — preserving the documented "marks but does not throw" contract and letting per-item aborts propagate naturally.
Builds an action log via the ActionLogBuilder DSL and stores it on the current stage record.
Convenience wrapper that maps a collection, enclosing it in a dedicated stage. Pros: automatically sets substagesTotal to enable ETC calculation.
Attaches a custom metric to the records tree of this stage. This method has two uses:
Runs agentToRun on item and records exactly one leaf entry under the current stage — AgentRunRecord.Completed on success, or AgentRunRecord.Failed on any failure (regular exception, retry-exhausted transient, or ExecutionAbortException).
.getOrThrow() shortcut over StageScope.runAgent; throws on a recorded run failure.
Re-samples the agent: runs it up to maxAttempts times, returning the first attempt whose outcome satisfies until (default RunUntil.SOLVED). The intended use is intentional re-sampling — e.g. bootstrap demonstration generation — not transient-failure recovery.
Runs the agent up to maxAttempts times, creating a fresh agent per attempt via agentProvider.
Convenience wrapper that iterates a collection, enclosing it in a dedicated stage. Pros: automatically sets substagesTotal to enable ETC calculation.
Runs block as a named child stage and records the result.
.getOrThrow() shortcut over StageScope.runStage. See its KDoc for the metrics preset conventions; the default and parameter semantics are identical.
Serializes data with defaultExperimentsJson and stores it as this stage's additional data via StageScope.setAdditionalDataJson. Overwrites any previously set value.
Sets some additional data in this stage's record. Overwrites if additional data was already added.