@runloop/api-client - v1.18.1
    Preparing search index...

    Class ScenarioBuilder

    Fluent builder for constructing ScenarioCreateParams.

    The ScenarioBuilder provides a step-by-step, chainable interface for configuring all aspects of a scenario before pushing it to the platform.

    import { RunloopSDK } from '@runloop/api-client';

    const runloop = new RunloopSDK();
    const scenario = await runloop.scenario
    .builder('my-scenario')
    .fromBlueprint(blueprint)
    .withWorkingDirectory('/app')
    .withProblemStatement('Fix the bug in main.py')
    .addTestCommandScorer('tests', { test_command: 'pytest' })
    .push();
    Index

    Constructors

    Accessors

    Methods

    • Set the working directory for the scenario.

      Parameters

      • directory: string

        Working directory path

      Returns this

      Builder for chaining

    • Set the problem statement for the scenario. This will be provided as input context to the agent.

      Parameters

      • statement: string

        Problem statement text

      Returns this

      Builder for chaining

    • Set additional structured context for the scenario.

      Parameters

      • context: unknown

        Additional context (JSON-serializable)

      Returns this

      Builder for chaining

    • Add a test-based scorer that runs a test command.

      Parameters

      • name: string

        Name of the scoring function

      • opts: { test_command: string; weight?: number; test_files?: TestFile[] }

        Scorer options

        • test_command: string

          Command to run tests

        • Optionalweight?: number

          Weight for this scorer (default: 1.0)

        • Optionaltest_files?: TestFile[]

          Test files to create before running

      Returns this

      Builder for chaining

      builder.addTestCommandScorer('tests', {
      test_command: 'pytest',
      test_files: [{ file_path: 'test_main.py', file_contents: 'def test_foo(): ...' }],
      });
    • Add a command scorer that runs a shell command. Scoring passes if the command returns exit code 0.

      Parameters

      • name: string

        Name of the scoring function

      • opts: { command: string; weight?: number }

        Scorer options

        • command: string

          Shell command to execute

        • Optionalweight?: number

          Weight for this scorer (default: 1.0)

      Returns this

      Builder for chaining

    • Add a standalone bash script scorer. The script should output "score=X.X" where X.X is a float between 0.0 and 1.0.

      Parameters

      • name: string

        Name of the scoring function

      • opts: { bash_script: string; weight?: number }

        Scorer options

        • bash_script: string

          Bash script content

        • Optionalweight?: number

          Weight for this scorer (default: 1.0)

      Returns this

      Builder for chaining

    • Add a standalone Python script scorer. The script should print the score in the range [0.0, 1.0] to stdout.

      Parameters

      • name: string

        Name of the scoring function

      • opts: {
            python_script: string;
            weight?: number;
            python_version_constraint?: string;
            requirements_contents?: string;
        }

        Scorer options

        • python_script: string

          Python script content

        • Optionalweight?: number

          Weight for this scorer (default: 1.0)

        • Optionalpython_version_constraint?: string

          Python version (default "==3.12.10")

        • Optionalrequirements_contents?: string

          pip requirements.txt content

      Returns this

      Builder for chaining

    • Add an AST grep scorer that matches code patterns.

      Parameters

      • name: string

        Name of the scoring function

      • opts: { pattern: string; weight?: number; search_directory?: string; lang?: string }

        Scorer options

        • pattern: string

          AST pattern to match

        • Optionalweight?: number

          Weight for this scorer (default: 1.0)

        • Optionalsearch_directory?: string

          Directory to search (default: ".")

        • Optionallang?: string

          Language of the pattern

      Returns this

      Builder for chaining

    • Add a custom scorer registered with Runloop.

      Parameters

      • name: string

        Name of the scoring function

      • opts: { custom_scorer_type: string; weight?: number; scorer_params?: unknown }

        Scorer options

        • custom_scorer_type: string

          Type identifier registered with Runloop

        • Optionalweight?: number

          Weight for this scorer (default: 1.0)

        • Optionalscorer_params?: unknown

          Additional JSON parameters for the scorer

      Returns this

      Builder for chaining

    • Set metadata for the scenario.

      Parameters

      • metadata: Record<string, string>

        Key-value metadata

      Returns this

      Builder for chaining

    • Set the reference solution or gold patch for validation.

      Parameters

      • output: string

        Reference solution (e.g., git diff)

      Returns this

      Builder for chaining

    • Set required environment variables.

      Parameters

      • envVars: string[]

        List of required environment variable names

      Returns this

      Builder for chaining

    • Set required secrets.

      Parameters

      • secrets: string[]

        List of required secret names

      Returns this

      Builder for chaining

    • Set the validation strategy.

      Parameters

      • validationType: "UNSPECIFIED" | "FORWARD" | "REVERSE" | "EVALUATION"

        Validation type

      Returns this

      Builder for chaining

    • Build the scenario creation parameters.

      Validates that required fields are set and normalizes scorer weights to sum to 1.0.

      Returns ScenarioCreateParams

      Parameters for scenario creation

      const params = builder.build();
      // Use params with the raw API client
      const scenarioView = await client.scenarios.create(params);

      If problem statement is missing or no scorers are configured

    • Create the scenario on the platform.

      Calls build to validate and assemble parameters, then creates the scenario via the API.

      Parameters

      • Optionaloptions: RequestOptions<unknown>

        Request options

      Returns Promise<RunloopSDK.Scenario>

      Created Scenario instance

      const scenario = await runloop.scenario
      .builder('my-scenario')
      .withProblemStatement('Fix the bug')
      .addTestCommandScorer('tests', { test_command: 'pytest' })
      .push();
      console.log(`Created scenario: ${scenario.id}`);

      If required fields are missing