Skip to content

Configuring repositories

We currently support the following repository types:

  • A pre-existing repository (PreExistingRepoConfig)
  • A local repository (LocalRepoConfig)
  • A GitHub repository (GithubRepoConfig)

With sweagent run, you can specify the repository type with the --env.repo flag. For example:

From a pre-existing repository
--env.repo.repo_name="testbed" # (1)!
--env.repo.type=preexisting
  1. Folder name at the root of the deployment
From a local repository
--env.repo.path=/path/to/repo
--env.repo.type=local

All of these classes are defined in sweagent.environment.repo.

PreExistingRepoConfig pydantic-model

Use this to specify a repository that already exists on the deployment. This is important because we need to cd to the repo before running the agent.

Note: The repository must be at the root of the deployment.

Config:

  • extra: 'forbid'

Fields:

base_commit pydantic-field

base_commit: str = 'HEAD'

The commit to reset the repository to. The default is HEAD, i.e., the latest commit. You can also set this to a branch name (e.g., dev), a tag (e.g., v0.1.0), or a commit hash (e.g., a4464baca1f). SWE-agent will then start from this commit when trying to solve the problem.

repo_name pydantic-field

repo_name: str

The repo name (the repository must be located at the root of the deployment).

type pydantic-field

type: Literal['preexisting'] = 'preexisting'

Discriminator for (de)serialization/CLI. Do not change.

copy

copy(deployment: AbstractDeployment)

Does nothing.

Source code in sweagent/environment/repo.py
49
50
51
def copy(self, deployment: AbstractDeployment):
    """Does nothing."""
    pass

LocalRepoConfig pydantic-model

Config:

  • extra: 'forbid'

Fields:

base_commit pydantic-field

base_commit: str = 'HEAD'

The commit to reset the repository to. The default is HEAD, i.e., the latest commit. You can also set this to a branch name (e.g., dev), a tag (e.g., v0.1.0), or a commit hash (e.g., a4464baca1f). SWE-agent will then start from this commit when trying to solve the problem.

path pydantic-field

path: Path

repo_name pydantic-field

repo_name: str

Set automatically based on the repository name. Cannot be set.

type pydantic-field

type: Literal['local'] = 'local'

Discriminator for (de)serialization/CLI. Do not change.

check_valid_repo

check_valid_repo() -> Self
Source code in sweagent/environment/repo.py
75
76
77
78
79
80
81
82
83
84
def check_valid_repo(self) -> Self:
    try:
        repo = GitRepo(self.path, search_parent_directories=True)
    except InvalidGitRepositoryError as e:
        msg = f"Could not find git repository at {self.path=}."
        raise ValueError(msg) from e
    if repo.is_dirty() and "PYTEST_CURRENT_TEST" not in os.environ:
        msg = f"Local git repository {self.path} is dirty. Please commit or stash changes."
        raise ValueError(msg)
    return self

copy

copy(deployment: AbstractDeployment)
Source code in sweagent/environment/repo.py
86
87
88
89
90
91
92
93
94
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}"))
    )
    r = asyncio.run(deployment.runtime.execute(Command(command=f"chown -R root:root {self.repo_name}", shell=True)))
    if r.exit_code != 0:
        msg = f"Failed to change permissions on copied repository (exit code: {r.exit_code}, stdout: {r.stdout}, stderr: {r.stderr})"
        raise RuntimeError(msg)

GithubRepoConfig pydantic-model

Config:

  • extra: 'forbid'

Fields:

base_commit pydantic-field

base_commit: str = 'HEAD'

The commit to reset the repository to. The default is HEAD, i.e., the latest commit. You can also set this to a branch name (e.g., dev), a tag (e.g., v0.1.0), or a commit hash (e.g., a4464baca1f). SWE-agent will then start from this commit when trying to solve the problem.

clone_timeout pydantic-field

clone_timeout: float = 500

Timeout for git clone operation.

github_url pydantic-field

github_url: str

repo_name pydantic-field

repo_name: str

type pydantic-field

type: Literal['github'] = 'github'

Discriminator for (de)serialization/CLI. Do not change.

copy

copy(deployment: AbstractDeployment)

Clones the repository to the sandbox.

Source code in sweagent/environment/repo.py
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
def copy(self, deployment: AbstractDeployment):
    """Clones the repository to the sandbox."""
    base_commit = self.base_commit
    github_token = os.getenv("GITHUB_TOKEN", "")
    url = self._get_url_with_token(github_token)
    asyncio.run(
        deployment.runtime.execute(
            Command(
                command=" && ".join(
                    (
                        f"mkdir {self.repo_name}",
                        f"cd {self.repo_name}",
                        "git init",
                        f"git remote add origin {url}",
                        f"git fetch --depth 1 origin {base_commit}",
                        "git checkout FETCH_HEAD",
                        "cd ..",
                    )
                ),
                timeout=self.clone_timeout,
                shell=True,
                check=True,
            )
        ),
    )

repo_from_simplified_input

repo_from_simplified_input(*, input: str, base_commit: str = 'HEAD', type: Literal['local', 'github', 'preexisting', 'auto'] = 'auto') -> RepoConfig

Get repo config from a simplified input.

Parameters:

Name Type Description Default
input str

Local path or GitHub URL

required
type Literal['local', 'github', 'preexisting', 'auto']

The type of repo. Set to "auto" to automatically detect the type (does not work for preexisting repos).

'auto'
Source code in sweagent/environment/repo.py
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
def repo_from_simplified_input(
    *, input: str, base_commit: str = "HEAD", type: Literal["local", "github", "preexisting", "auto"] = "auto"
) -> RepoConfig:
    """Get repo config from a simplified input.

    Args:
        input: Local path or GitHub URL
        type: The type of repo. Set to "auto" to automatically detect the type
            (does not work for preexisting repos).
    """
    if type == "local":
        return LocalRepoConfig(path=Path(input), base_commit=base_commit)
    if type == "github":
        return GithubRepoConfig(github_url=input, base_commit=base_commit)
    if type == "preexisting":
        return PreExistingRepoConfig(repo_name=input, base_commit=base_commit)
    if type == "auto":
        if input.startswith("https://github.com/"):
            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}"
    raise ValueError(msg)