import yaml
import json
from sweagent.run.run_batch import RunBatchConfig, run_from_config
from sweagent.agent.agents import DefaultAgentConfig
from sweagent.run.batch_instances import InstancesFromFile

agent_config_path = "scripts/agent.yaml"
output_dir = "scripts/test_output"
instances_path = "scripts/swe_gym_instances_with_image.json"

with open(agent_config_path) as f:
    config_data = yaml.safe_load(f)
agent_config = DefaultAgentConfig.model_validate(config_data["agent"])

# Use InstancesFromFile with the path to your JSON file
instances = InstancesFromFile(
    path=instances_path,
    filter=".*",
    slice="0:2",
    shuffle=False,
)

config = RunBatchConfig(
    instances=instances,
    agent=agent_config,
    output_dir=output_dir,
    redo_existing=True,
)

# Run the batch
run_from_config(config)