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]

Use implicit flags for boolean arguments

Kilian Lieret41da56b94f5b
diff --git a/sweagent/run/run_batch.py b/sweagent/run/run_batch.py
index dd95ebf5..a8651bf6 100644
--- a/sweagent/run/run_batch.py
+++ b/sweagent/run/run_batch.py
@@ -21,14 +21,14 @@ from sweagent.run.hooks.apply_patch import SaveApplyPatchHook
from sweagent.utils.log import get_logger
-class RunBatchConfig(BaseSettings):
+class RunBatchConfig(BaseSettings, cli_implicit_flags=True):
instances: BatchInstanceSourceConfig = Field(union_mode="left_to_right")
agent: AgentConfig = AgentConfig(
model=ModelArguments(name="human"), next_step_template="Observation: {observation}"
)
traj_dir: Path = Path(".")
raise_exceptions: bool = False
- skip_existing: bool = True
+ redo_existing: bool = False
class _BreakLoop(Exception):
@@ -44,7 +44,7 @@ class RunBatch:
traj_dir: Path = Path("."),
hooks: list[RunHook] | None = None,
raise_exceptions: bool = False,
- skip_existing: bool = True,
+ redo_existing: bool = False,
):
"""Note: When initializing this class, make sure to add the hooks that are required by your actions.
See `from_config` for an example.
@@ -59,7 +59,7 @@ class RunBatch:
self._hooks = []
self._raise_exceptions = raise_exceptions
self._chooks = CombinedRunHooks()
- self._skip_existing = skip_existing
+ self._redo_existing = redo_existing
for hook in hooks or [SaveApplyPatchHook()]:
self.add_hook(hook)
@@ -135,7 +135,7 @@ class RunBatch:
def should_skip(self, instance: BatchInstance) -> bool:
"""Check if we should skip this instance"""
- if not self._skip_existing:
+ if self._redo_existing:
return False
# Check if there's an existing trajectory for this instance
diff --git a/sweagent/run/run_single.py b/sweagent/run/run_single.py
index bb49a604..c8dbe069 100644
--- a/sweagent/run/run_single.py
+++ b/sweagent/run/run_single.py
@@ -4,6 +4,7 @@ import sys
from pathlib import Path
from typing import Self
+import yaml
from pydantic import BaseModel, Field
from pydantic_settings import BaseSettings
@@ -22,7 +23,7 @@ from sweagent.run.hooks.open_pr import OpenPRConfig, OpenPRHook
from sweagent.utils.log import get_logger
-class RunSingleActionConfig(BaseModel):
+class RunSingleActionConfig(BaseModel, cli_implicit_flags=True):
"""Run real-life actions (opening PRs, etc.) if we can solve the issue."""
# Open a PR with the patch if we can solve the issue
@@ -32,7 +33,7 @@ class RunSingleActionConfig(BaseModel):
apply_patch_locally: bool = False
-class RunSingleConfig(BaseSettings):
+class RunSingleConfig(BaseSettings, cli_implicit_flags=True):
env: EnvironmentConfig = Field(default_factory=EnvironmentConfig)
agent: AgentConfig = AgentConfig(
model=ModelArguments(name="human"), next_step_template="Observation: {observation}"
@@ -40,10 +41,9 @@ class RunSingleConfig(BaseSettings):
problem_statement: ProblemStatementConfig = Field(default_factory=EmptyProblemStatement)
traj_dir: Path = Path(".")
actions: RunSingleActionConfig = Field(default_factory=RunSingleActionConfig)
- # todo: implement this
- raise_exceptions: bool = True
- # todo: implement this
- print_config: bool = True
+
+ print_config: bool = False
+ """Print config at the beginning of the run."""
class Config:
extra = "forbid"
@@ -82,6 +82,10 @@ class RunSingle:
@classmethod
def from_config(cls, config: RunSingleConfig) -> Self:
+ logger = get_logger("Run", emoji="🏃")
+ if config.print_config:
+ config_str = yaml.dump(config.model_dump())
+ logger.info(f"Config:\n {config_str}")
self = cls(
env=SWEEnv.from_config(config.env),
agent=Agent("main", config.agent),
diff --git a/tests/test_run_batch.py b/tests/test_run_batch.py
index be6e1b19..a146ab6e 100644
--- a/tests/test_run_batch.py
+++ b/tests/test_run_batch.py
@@ -20,7 +20,6 @@ def test_expert_instances(test_data_sources_path: Path, tmp_path: Path):
"--traj_dir",
str(tmp_path),
"--raise_exceptions",
- "True",
]
main(cmd)
for _id in ["simple_test_problem", "simple_test_problem_2"]:
@@ -40,7 +39,6 @@ def test_simple_instances(test_data_sources_path: Path, tmp_path: Path):
"--traj_dir",
str(tmp_path),
"--raise_exceptions",
- "True",
]
main(cmd)
assert (tmp_path / "simple_test_problem.traj").exists(), list(tmp_path.iterdir())
@@ -58,7 +56,6 @@ def test_empty_instances_simple(test_data_sources_path: Path, tmp_path: Path):
"--traj_dir",
str(tmp_path),
"--raise_exceptions",
- "True",
"--instances.filter",
"doesnotmatch",
]
@@ -80,7 +77,6 @@ def test_empty_instances_expert(test_data_sources_path: Path, tmp_path: Path):
"--traj_dir",
str(tmp_path),
"--raise_exceptions",
- "True",
"--instances.filter",
"doesnotmatch",
]
diff --git a/tests/test_run_single.py b/tests/test_run_single.py
index 4385281a..744357e0 100644
--- a/tests/test_run_single.py
+++ b/tests/test_run_single.py
@@ -76,8 +76,7 @@ def test_run_ies_repo_ps_matrix(
raise ValueError(repo)
args = [
"--agent.model.name=instant_empty_submit",
- "--raise_exceptions=True",
- "--print_config=False",
+ "--print_config",
"--traj_dir",
str(tmpdir),
*ps_args,