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]
Rename url->github_url in CL and config
Kilian Liereted92f539895f
diff --git a/docs/usage/cl_tutorial.md b/docs/usage/cl_tutorial.mdindex 6be54542..7b462385 100644--- a/docs/usage/cl_tutorial.md+++ b/docs/usage/cl_tutorial.md@@ -23,8 +23,8 @@ Let's start with an absolutely trivial example and solve an issue about a simplepython run.py \--agent.model.name=gpt4 \--agent.model.per_instance_cost_limit=2.00 \ # (1)!- --env.repo.url=https://github.com/SWE-agent/test-repo \- --problem_statement.url=https://github.com/SWE-agent/test-repo/issues/1+ --env.repo.github_url=https://github.com/SWE-agent/test-repo \+ --problem_statement.github_url=https://github.com/SWE-agent/test-repo/issues/1```1. This limits the inference cost per instance to $2. The default is $3.@@ -95,7 +95,7 @@ python run.py \```bash title="Github repo with custom problem statement" hl_lines="4"python run.py \...- --env.repo.url=https://github.com/SWE-agent/test-repo \+ --env.repo.github_url=https://github.com/SWE-agent/test-repo \--problem_statement.text="Hey, can you fix all the bugs?"```@@ -114,8 +114,25 @@ python run.py \## Configuration basics-All configuration options can be specified either in `.yaml`+All configuration options can be specified either in one or more `.yaml` files, or as command line arguments. For example, our first command can be written as+```bash+python run.py --config my_run.yaml+```++with++```yaml title="my_run.yaml"+agent:+ model:+ name: gpt4+ per_instance_cost_limit: 2.00+env:+ repo:+ github_url: https://github.com/SWE-agent/test-repo+problem_statement:+ github_url: https://github.com/SWE-agent/test-repo/issues/1+```## Specifying the repositorydiff --git a/sweagent/environment/config/problem_statement.py b/sweagent/environment/config/problem_statement.pyindex 9c49ff05..825652d6 100644--- a/sweagent/environment/config/problem_statement.py+++ b/sweagent/environment/config/problem_statement.py@@ -76,7 +76,7 @@ class FileProblemStatement(BaseModel):class GithubIssue(BaseModel):- url: str+ github_url: strtype: Literal["github"] = "github""""Discriminator for (de)serialization/CLI. Do not change."""@@ -88,11 +88,11 @@ class GithubIssue(BaseModel):def model_post_init(self, __context: Any) -> None:if self.id is None:logger.info("Setting problem statement based on github issue url")- owner, repo, issue_number = _parse_gh_issue_url(self.url)+ owner, repo, issue_number = _parse_gh_issue_url(self.github_url)self.id = f"{owner}__{repo}-i{issue_number}"def get_problem_statement(self) -> str:- owner, repo, issue_number = _parse_gh_issue_url(self.url)+ owner, repo, issue_number = _parse_gh_issue_url(self.github_url)return _get_problem_statement_from_github_issue(owner, repo, issue_number, token=os.getenv("GITHUB_TOKEN"))@@ -113,7 +113,7 @@ def problem_statement_from_simplified_input(elif type == "text_file":return FileProblemStatement(path=Path(input))elif type == "github_issue":- return GithubIssue(url=input)+ return GithubIssue(github_url=input)else:msg = f"Unknown problem statement type: {type}"raise ValueError(msg)diff --git a/sweagent/environment/config/repo.py b/sweagent/environment/config/repo.pyindex 8aa27256..0e2d9314 100644--- a/sweagent/environment/config/repo.py+++ b/sweagent/environment/config/repo.py@@ -1,7 +1,7 @@import asyncioimport osfrom pathlib import Path-from typing import Literal, Protocol+from typing import Any, Literal, Protocolimport pydanticfrom git import InvalidGitRepositoryError@@ -80,7 +80,7 @@ class LocalRepoConfig(BaseModel):class GithubRepoConfig(BaseModel):- url: str = ""+ github_url: str = ""base_commit: str = "HEAD"@@ -90,19 +90,23 @@ class GithubRepoConfig(BaseModel):type: Literal["github"] = "github""""Discriminator for (de)serialization/CLI. Do not change."""+ def model_post_init(self, __context: Any) -> None:+ if self.github_url.count("/") == 1:+ self.github_url = f"https://github.com/{self.github_url}"+@propertydef repo_name(self) -> str:- org, repo = _parse_gh_repo_url(self.url)+ org, repo = _parse_gh_repo_url(self.github_url)return f"{org}__{repo}"def _get_url_with_token(self, token: str) -> str:"""Prepend github token to URL"""if not token:- return self.url- if "@" in self.url:+ return self.github_url+ if "@" in self.github_url:logger.warning("Cannot prepend token to URL. '@' found in URL")- return self.url- _, _, url_no_protocol = self.url.partition("://")+ return self.github_url+ _, _, url_no_protocol = self.github_url.partition("://")return f"https://{token}@{url_no_protocol}"def copy(self, deployment: AbstractDeployment):@@ -148,12 +152,12 @@ def repo_from_simplified_input(if type == "local":return LocalRepoConfig(path=Path(input), base_commit=base_commit)if type == "github":- return GithubRepoConfig(url=input, base_commit=base_commit)+ return GithubRepoConfig(github_url=input, base_commit=base_commit)if type == "preexisting":return PreExistingRepo(repo_name=input, base_commit=base_commit)if type == "auto":if input.startswith("https://github.com/"):- return GithubRepoConfig(url=input, base_commit=base_commit)+ return GithubRepoConfig(github_url=input, base_commit=base_commit)else:return LocalRepoConfig(path=Path(input), base_commit=base_commit)msg = f"Unknown repo type: {type}"diff --git a/sweagent/run/batch_instances.py b/sweagent/run/batch_instances.pyindex 8bb5561d..edc34286 100644--- a/sweagent/run/batch_instances.py+++ b/sweagent/run/batch_instances.py@@ -125,7 +125,7 @@ class SimpleBatchInstance(BaseModel):if not self.repo_name:repo = Noneelif "github" in self.repo_name:- repo = GithubRepoConfig(url=self.repo_name, base_commit=self.base_commit)+ repo = GithubRepoConfig(github_url=self.repo_name, base_commit=self.base_commit)elif "/" not in self.repo_name:repo = PreExistingRepo(repo_name=self.repo_name, base_commit=self.base_commit)else:diff --git a/sweagent/run/run_single.py b/sweagent/run/run_single.pyindex d5f61ae1..9d783d9c 100644--- a/sweagent/run/run_single.py+++ b/sweagent/run/run_single.py@@ -14,8 +14,8 @@Basic usage: Run over a [bold][cyan]github issue[/bold][/cyan][green]:sweagent run --config config/config.yaml --agent.model.name "gpt-4o" \\- --env.repo.url=https://github.com/SWE-agent/test-repo/ \\- --problem_statement.url=https://github.com/SWE-agent/test-repo/issues/1+ --env.repo.github_url=https://github.com/SWE-agent/test-repo/ \\+ --problem_statement.github_url=https://github.com/SWE-agent/test-repo/issues/1[/green]By default this will start a docker container and run the agent in there.diff --git a/tests/test_run_single.py b/tests/test_run_single.pyindex 9b8289a4..ee4f6def 100644--- a/tests/test_run_single.py+++ b/tests/test_run_single.py@@ -87,7 +87,7 @@ def test_run_ies_repo_ps_matrix(for fmt in output_formats:assert not list(Path(tmpdir).glob(f"*.{fmt}"))if problem_statement_source == "github":- ps_args = ["--problem_statement.url", "https://github.com/swe-agent/test-repo/issues/1"]+ ps_args = ["--problem_statement.github_url", "https://github.com/swe-agent/test-repo/issues/1"]elif problem_statement_source == "local":ps_args = ["--problem_statement.path", str(swe_agent_test_repo_clone / "problem_statements" / "1.md")]elif problem_statement_source == "text":@@ -97,7 +97,7 @@ def test_run_ies_repo_ps_matrix(if repo == "local":repo_args = ["--env.repo.path", str(swe_agent_test_repo_clone)]elif repo == "github":- repo_args = ["--env.repo.url", "https://github.com/swe-agent/test-repo"]+ repo_args = ["--env.repo.github_url", "https://github.com/swe-agent/test-repo"]else:raise ValueError(repo)args = [