Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

Change: batch instances: instance_id instead of id field (#1030)

Kilian Lieret9f53a6039f88
diff --git a/docs/usage/batch_mode.md b/docs/usage/batch_mode.md
index b8c70a90..0e3defef 100644
--- a/docs/usage/batch_mode.md
+++ b/docs/usage/batch_mode.md
@@ -98,14 +98,19 @@ Here'the simplest example of what such a file can look like
```yaml title="instances.yaml"
- image_name: "python:3.11" # (1)!
problem_statement: "A simple test problem"
- id: "simple_test_problem"
+ instance_id: "simple_test_problem"
- image_name: "python:3.11"
problem_statement: "Another test problem"
- id: "simple_test_problem_2"
+ instance_id: "simple_test_problem_2"
```
1. Must be available locally or on dockerhub.
+!!! warning "Recent changes"
+ The `instance_id` key was named `id` until Mar 16, 2025.
+ This was changed to add compatibility with the standard SWE-bench format.
+ However, we temporarily support both names.
+
!!! tip "More options"
* There's a few more fields that you can populate. See [`SimpleBatchInstances`](../reference/batch_instances.md/#sweagent.run.batch_instances.SimpleBatchInstance) for more information.
* For all command line options with this instance type, see [`InstancesFromFile`](../reference/batch_instances.md/#sweagent.run.batch_instances.InstancesFromFile).
diff --git a/sweagent/run/batch_instances.py b/sweagent/run/batch_instances.py
index 0e193017..d1623b9e 100644
--- a/sweagent/run/batch_instances.py
+++ b/sweagent/run/batch_instances.py
@@ -4,7 +4,7 @@ from abc import ABC, abstractmethod
from pathlib import Path
from typing import Any, Literal
-from pydantic import BaseModel, Field
+from pydantic import BaseModel, ConfigDict, Field, model_validator
from swerex.deployment.config import (
DeploymentConfig,
DockerDeploymentConfig,
@@ -87,7 +87,7 @@ class SimpleBatchInstance(BaseModel):
image_name: str
problem_statement: str
- id: str
+ instance_id: str
repo_name: str = ""
"""Specifies the repository to use. If empty, no repository is used.
If the string does not contain a slash, it is interpreted as an already existing repository at the root
@@ -101,12 +101,15 @@ class SimpleBatchInstance(BaseModel):
This data will be available when formatting prompt templates.
"""
+ # Ignore instead of allow because they should be added as `extra_fields`
+ model_config = ConfigDict(extra="ignore")
+
def to_full_batch_instance(self, deployment: DeploymentConfig) -> BatchInstance:
"""Merge the deployment options into the `SimpleBatchInstance` object to get a full `BatchInstance`."""
# Very important: Make a copy of the deployment config because it will be shared among instances!!!
deployment = deployment.model_copy(deep=True)
problem_statement = TextProblemStatement(
- text=self.problem_statement, id=self.id, extra_fields=self.extra_fields
+ text=self.problem_statement, id=self.instance_id, extra_fields=self.extra_fields
)
if not self.repo_name:
repo = None
@@ -137,6 +140,17 @@ class SimpleBatchInstance(BaseModel):
env=EnvironmentConfig(deployment=deployment, repo=repo), problem_statement=problem_statement
)
+ @model_validator(mode="before")
+ @classmethod
+ def handle_legacy_id(cls, data):
+ # Handling compatibility with swe-agent <= 1.0.1
+ if isinstance(data, dict):
+ if "id" in data and "instance_id" not in data:
+ data["instance_id"] = data["id"]
+ data.pop("id")
+ return data
+
+ # todo: Maybe populate extra fields?
@classmethod
def from_swe_bench(cls, instance: dict[str, Any]) -> Self:
"""Convert instances from the classical SWE-bench dataset to the `SimpleBatchInstance` format."""
@@ -149,7 +163,7 @@ class SimpleBatchInstance(BaseModel):
return cls(
image_name=image_name,
problem_statement=instance["problem_statement"],
- id=iid,
+ instance_id=iid,
repo_name="testbed",
base_commit=instance["base_commit"],
)