Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions javascript/src/domain/core/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import type { ScenarioConfig } from "../scenarios";
*
*/
export interface ScenarioResult {
/**
* Unique identifier for this scenario run.
*/
runId: string;

/**
* Indicates whether the scenario was successful.
*/
Expand Down
21 changes: 17 additions & 4 deletions javascript/src/execution/scenario-execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import {
generateScenarioId,
generateScenarioRunId,
generateThreadId,
getBatchRunId,
} from "../utils/ids";
import { Logger } from "../utils/logger";

Expand Down Expand Up @@ -183,13 +182,21 @@ export class ScenarioExecution implements ScenarioExecutionLike {
public readonly events$: Observable<ScenarioEvent> =
this.eventSubject.asObservable();

/** Batch run ID for grouping scenario runs */
private batchRunId: string;

/** The run ID for the current execution */
private scenarioRunId?: string;

/**
* Creates a new ScenarioExecution instance.
*
* @param config - The scenario configuration containing agents, settings, and metadata
* @param script - The ordered sequence of script steps that define the test flow
* @param batchRunId - Batch run ID for grouping scenario runs
*/
constructor(config: ScenarioConfig, script: ScriptStep[]) {
constructor(config: ScenarioConfig, script: ScriptStep[], batchRunId: string) {
this.batchRunId = batchRunId;
this.config = {
id: config.id ?? generateScenarioId(),
name: config.name,
Expand Down Expand Up @@ -243,8 +250,12 @@ export class ScenarioExecution implements ScenarioExecutionLike {
* @param result - The final scenario result (without messages/timing, which will be added automatically)
*/
private setResult(
result: Omit<ScenarioResult, "messages" | "totalTime" | "agentTime">
result: Omit<ScenarioResult, "runId" | "messages" | "totalTime" | "agentTime">
): void {
if (!this.scenarioRunId) {
throw new Error("Cannot set result: scenarioRunId has not been initialized. This is a bug in ScenarioExecution.");
}

const agentRoleAgentsIdx = this.agents
.map((agent, i) => ({ agent, idx: i }))
.filter(({ agent }) => agent.role === AgentRole.AGENT)
Expand All @@ -257,6 +268,7 @@ export class ScenarioExecution implements ScenarioExecutionLike {
const totalAgentTime = agentTimes.reduce((sum, time) => sum + time, 0);

this._result = {
runId: this.scenarioRunId,
...result,
messages: this.state.messages,
totalTime: this.totalTime,
Expand Down Expand Up @@ -315,6 +327,7 @@ export class ScenarioExecution implements ScenarioExecutionLike {
this.reset();

const scenarioRunId = generateScenarioRunId();
this.scenarioRunId = scenarioRunId;
this.logger.debug(`[${this.config.id}] Generated run ID: ${scenarioRunId}`);
this.emitRunStarted({ scenarioRunId });

Expand Down Expand Up @@ -1212,7 +1225,7 @@ export class ScenarioExecution implements ScenarioExecutionLike {
return {
type: "placeholder", // This will be replaced by the specific event type
timestamp: Date.now(),
batchRunId: getBatchRunId(),
batchRunId: this.batchRunId,
scenarioId: this.config.id,
scenarioRunId,
scenarioSetId: this.config.setId,
Expand Down
Loading
Loading