Creates a new ScenarioExecution instance.
The scenario configuration.
The script steps to execute.
Readonly
events$An observable stream of events that occur during the scenario execution. Subscribe to this to monitor the progress of the scenario in real-time.
The history of messages in the conversation.
The unique identifier for the conversation thread.
Executes an agent turn.
If content is provided, it's used as the agent's message.
If not, the agent under test is called to generate a response.
This is part of the ScenarioExecutionLike
interface used by script steps.
Optional
content: string | CoreMessageThe optional content of the agent's message.
Executes the entire scenario from start to finish. This will run through the script and any automatic proceeding logic until a final result (success, failure, or error) is determined.
A promise that resolves with the final result of the scenario.
Immediately ends the scenario with a failure verdict.
This is part of the ScenarioExecutionLike
interface used by script steps.
Optional
reasoning: stringAn optional explanation for the failure.
A promise that resolves with the final failed scenario result.
Invokes the judge agent to evaluate the current state of the conversation.
This is part of the ScenarioExecutionLike
interface used by script steps.
Optional
content: string | CoreMessageOptional message to pass to the judge.
A promise that resolves with the scenario result if the judge makes a final decision, otherwise null.
Adds a message to the conversation history.
This is part of the ScenarioExecutionLike
interface used by script steps.
The message to add.
Lets the scenario proceed automatically for a specified number of turns.
This simulates the natural flow of conversation between agents.
This is part of the ScenarioExecutionLike
interface used by script steps.
Optional
turns: numberThe number of turns to proceed. If undefined, runs until a conclusion or max turns is reached.
Optional
onTurn: (state: ScenarioExecutionStateLike) => void | Promise<void>A callback executed at the end of each turn.
Optional
onStep: (state: ScenarioExecutionStateLike) => void | Promise<void>A callback executed after each agent interaction.
A promise that resolves with the scenario result if a conclusion is reached.
Executes a single step in the scenario. A step usually corresponds to a single agent's turn. This method is useful for manually controlling the scenario's progress.
A promise that resolves with the new messages added during the step, or a final scenario result if the step concludes the scenario.
Immediately ends the scenario with a success verdict.
This is part of the ScenarioExecutionLike
interface used by script steps.
Optional
reasoning: stringAn optional explanation for the success.
A promise that resolves with the final successful scenario result.
Executes a user turn.
If content is provided, it's used as the user's message.
If not, the user simulator agent is called to generate a message.
This is part of the ScenarioExecutionLike
interface used by script steps.
Optional
content: string | CoreMessageThe optional content of the user's message.
Manages the execution of a single scenario.
This class orchestrates the interaction between agents, executes the script, and manages the scenario's state. It also emits events that can be subscribed to for observing the scenario's progress.
Note: This is an internal class. Most users will interact with the higher-level
scenario.run()
function instead of instantiating this class directly.Example