code: def run_scenarios(
      scenario,
      n_repeats,
      is_native,
      config_list,
      requirements,
      docker_image=None,
      results_dir="results",
  ):
      """
      Run a set testbed scenarios a given number of times.
  
      Args:
          scenario (path):    The file or folder containing the scenario JSONL instances. If given a folder, then
                              all JSONL files in the folder will be loaded and run.
          n_repeats (int):    The number of times each scenario instance will be repeated
          is_native (bool):   True if the scenario should be run locally rather than in Docker (proceed with caution!)
          config_list (list): An Autogen OAI_CONFIG_LIST to be used when running scenarios.
          results_dir (path): The folder were results will be saved.
      """
  
      files = []
  
      # Figure out which files or folders we are working with
      if os.path.isfile(scenario):
          files.append(scenario)
      elif os.path.isdir(scenario):
          for f in os.listdir(scenario):
              scenario_file = os.path.join(scenario, f)
  
              if not os.path.isfile(scenario_file):
                  continue
  
              if not scenario_file.lower().endswith(".jsonl"):
                  continue
  
              files.append(scenario_file)
      else:
          raise FileNotFoundError(
              errno.ENOENT, os.strerror(errno.ENOENT), scenario
          )
  
      # Run all the scenario files
      for scenario_file in files:
          scenario_name = os.path.basename(scenario_file).split(".")
          scenario_name.pop()
          scenario_name = ".".join(scenario_name)
  
          scenario_dir = os.path.dirname(
              os.path.realpath(scenario_file)
          )
  
          # Each line in the scenario file is an instance. Run it.
          with open(scenario_file) as fh:
              for line in fh:
                  instance = json.loads(line)
  
                  # Create a folder to store the results
                  # Results base
                  if not os.path.isdir(results_dir):
                      os.mkdir(results_dir)
  
                  # Results for the scenario
                  results_scenario = os.path.join(
                      results_dir, scenario_name
                  )
                  if not os.path.isdir(results_scenario):
                      os.mkdir(results_scenario)
  
                  # Results for the instance
                  results_instance = os.path.join(
                      results_scenario, instance["id"]
                  )
                  if not os.path.isdir(results_instance):
                      os.mkdir(results_instance)
  
                  # Results for the repeats
                  for i in range(0, n_repeats):
                      results_repetition = os.path.join(
                          results_instance, str(i)
                      )
  
                      # Skip it if it already exists
                      if os.path.isdir(results_repetition):
                          print(
                              f"Found folder {results_repetition} ... Skipping."
                          )
                          continue
                      print(f"Running scenario {results_repetition}")
  
                      # Expand the scenario
                      expand_scenario(
                          scenario_dir, instance, results_repetition
                      )
  
                      # Append the config list to the ENV file
                      with open(
                          os.path.join(results_repetition, "ENV"), "at"
                      ) as fh:
                          config_list_json = json.dumps(config_list)
                          fh.write(
                              f"export OAI_CONFIG_LIST='{config_list_json}'\n"
                          )
  
                          # If set, append the OpenAI API Key
                          openai_api_key = os.environ.get(
                              "OPENAI_API_KEY"
                          )
                          if (
                              openai_api_key is not None
                              and len(openai_api_key.strip()) > 0
                          ):
                              fh.write(
                                  f"export OPENAI_API_KEY='{openai_api_key}'\n"
                              )
  
                      # Run the scenario
                      if is_native:
                          run_scenario_natively(results_repetition)
                      else:
                          run_scenario_in_docker(
                              results_repetition,
                              requirements,
                              docker_image=docker_image,
                          )
  
file_path: autogen/samples/tools/testbed/run_scenarios.py
imports: import os
  import errno
  import shutil
  import subprocess
  import json
  import sys
  import time
  import pathlib
  import argparse
  from autogen import config_list_from_json
label_desc: Use image node_id 1 for calling a global function with example usage: run_scenarios(scenario, n_repeats, is_native, config_list, requirements, docker_image, results_dir) without return types