@langwatch/scenario
    Preparing search index...

    Function run

    • High-level interface for running a scenario test.

      This is the main entry point for executing scenario tests. It creates a ScenarioExecution instance and runs it.

      Parameters

      • cfg: ScenarioConfig

        Configuration for the scenario test.

        Configuration for a scenario.

        • agents: AgentAdapter[]

          The agents participating in the scenario.

        • description: string

          A description of what the scenario tests.

        • Optionalid?: string

          Optional unique identifier for the scenario. If not provided, a UUID will be generated.

        • OptionalmaxTurns?: number

          The maximum number of turns to execute.

          If no value is provided, this defaults to DEFAULT_MAX_TURNS.

        • name: string

          The name of the scenario.

        • Optionalscript?: ScriptStep[]

          The script of steps to execute for the scenario.

        • OptionalsetId?: string

          Optional identifier to group this scenario into a set ("Simulation Set"). This is useful for organizing related scenarios in the UI and for reporting. If not provided, the scenario will not be grouped into a set.

        • OptionalthreadId?: string

          Optional thread ID to use for the conversation. If not provided, a new thread will be created.

        • Optionalverbose?: boolean

          Whether to output verbose logging.

          If no value is provided, this defaults to DEFAULT_VERBOSE.

      Returns Promise<ScenarioResult>

      A promise that resolves with the ScenarioResult containing the test outcome, conversation history, success/failure status, and detailed reasoning.

      import { run, AgentAdapter, AgentRole, user, agent } from '@langwatch/scenario';

      const myAgent: AgentAdapter = {
      role: AgentRole.AGENT,
      async call(input) {
      return `The user said: ${input.messages.at(-1)?.content}`;
      }
      };

      async function main() {
      const result = await run({
      name: "Customer Service Test",
      description: "A simple test to see if the agent responds.",
      agents: [myAgent],
      script: [
      user("Hello, world!"),
      agent(),
      ],
      });

      if (result.success) {
      console.log("Scenario passed!");
      } else {
      console.error(`Scenario failed: ${result.reasoning}`);
      }
      }

      main();