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]

Fix: Running on coding challenges

Kilian Lieretde91f53f8956
diff --git a/config/coding_challenge.yaml b/config/coding_challenge.yaml
index fa4e1a9c..a7925bbe 100644
--- a/config/coding_challenge.yaml
+++ b/config/coding_challenge.yaml
@@ -75,23 +75,23 @@ agent:
--- END OF DEMONSTRATION ---
demonstrations:
- trajectories/demonstrations/human_thought__swe-bench-HumanEvalFix-python__lcb__t-0.00__p-0.95__c-4.00__install-0/humanevalfix-python-0.traj
-tools:
- env_variables:
- WINDOW: 100
- OVERLAP: 2
- CURRENT_LINE: 0
- CURRENT_FILE: ""
- SEARCH_RESULTS: ()
- SEARCH_FILES: ()
- SEARCH_INDEX: 0
- bundles:
- - path: tools/registry
- - path: tools/defaults
- - path: tools/search
- - path: tools/edit_replace
- - path: tools/submit
- parse_function:
- type: thought_action
-history_processors:
- - type: last_n_observations
- n: 5
+ tools:
+ env_variables:
+ WINDOW: 100
+ OVERLAP: 2
+ CURRENT_LINE: 0
+ CURRENT_FILE: ""
+ SEARCH_RESULTS: ()
+ SEARCH_FILES: ()
+ SEARCH_INDEX: 0
+ bundles:
+ - path: tools/registry
+ - path: tools/defaults
+ - path: tools/search
+ - path: tools/edit_replace
+ - path: tools/submit
+ parse_function:
+ type: thought_action
+ history_processors:
+ - type: last_n_observations
+ n: 5
diff --git a/docs/usage/coding_challenges.md b/docs/usage/coding_challenges.md
index 6f6820f5..efd8fb3d 100644
--- a/docs/usage/coding_challenges.md
+++ b/docs/usage/coding_challenges.md
@@ -55,13 +55,13 @@ git add . && git commit -m "Add problem stub"
Now, we can let SWE-agent solve the problem:
```bash
-python run.py \
+sweagent run \
--config config/coding_challenge.yaml \
--problem_statement.path=problem.md \
- --repo.path=/path/to/empty \
+ --env.repo.path=/path/to/empty \
--agent.model.name=gpt4 \
--agent.model.per_instance_cost_limit 3.0 \
- --action.apply_patch_locally=True
+ --actions.apply_patch_locally=True
```
<details>
diff --git a/sweagent/environment/repo.py b/sweagent/environment/repo.py
index 52a1247d..ee1fdf83 100644
--- a/sweagent/environment/repo.py
+++ b/sweagent/environment/repo.py
@@ -3,10 +3,9 @@ import os
from pathlib import Path
from typing import Any, Literal, Protocol
-import pydantic
from git import InvalidGitRepositoryError
from git import Repo as GitRepo
-from pydantic import BaseModel, Field
+from pydantic import BaseModel, ConfigDict, Field
from swerex.deployment.abstract import AbstractDeployment
from swerex.runtime.abstract import Command, UploadRequest
from typing_extensions import Self
@@ -45,6 +44,8 @@ class PreExistingRepoConfig(BaseModel):
type: Literal["preexisting"] = "preexisting"
"""Discriminator for (de)serialization/CLI. Do not change."""
+ model_config = ConfigDict(extra="forbid")
+
def copy(self, deployment: AbstractDeployment):
"""Does nothing."""
pass
@@ -62,12 +63,15 @@ class LocalRepoConfig(BaseModel):
type: Literal["local"] = "local"
"""Discriminator for (de)serialization/CLI. Do not change."""
+ model_config = ConfigDict(extra="forbid")
+
@property
def repo_name(self) -> str:
"""Set automatically based on the repository name. Cannot be set."""
return Path(self.path).resolve().name.replace(" ", "-").replace("'", "")
- @pydantic.model_validator(mode="after")
+ # Let's not make this a model validator, because it leads to cryptic errors.
+ # Let's just check during copy instead.
def check_valid_repo(self) -> Self:
try:
repo = GitRepo(self.path, search_parent_directories=True)
@@ -80,6 +84,7 @@ class LocalRepoConfig(BaseModel):
return self
def copy(self, deployment: AbstractDeployment):
+ self.check_valid_repo()
asyncio.run(
deployment.runtime.upload(UploadRequest(source_path=str(self.path), target_path=f"/{self.repo_name}"))
)
@@ -90,7 +95,7 @@ class LocalRepoConfig(BaseModel):
class GithubRepoConfig(BaseModel):
- github_url: str = ""
+ github_url: str
base_commit: str = Field(default="HEAD")
"""The commit to reset the repository to. The default is HEAD,
@@ -105,6 +110,8 @@ class GithubRepoConfig(BaseModel):
type: Literal["github"] = "github"
"""Discriminator for (de)serialization/CLI. Do not change."""
+ model_config = ConfigDict(extra="forbid")
+
def model_post_init(self, __context: Any) -> None:
if self.github_url.count("/") == 1:
self.github_url = f"https://github.com/{self.github_url}"