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]

Defensive: Ensure model_copy is always deep

Kilian Liereta2661c66c153
diff --git a/sweagent/agent/agents.py b/sweagent/agent/agents.py
index b1474516..e4872460 100644
--- a/sweagent/agent/agents.py
+++ b/sweagent/agent/agents.py
@@ -717,7 +717,7 @@ class DefaultAgent(AbstractAgent):
"""For most exceptions, we attempt to still extract the patch and submit that.
This means we send the `submit` command to the runtime and parse the output.
"""
- step = step.model_copy()
+ step = step.model_copy(deep=True)
step.done = True
assert self._env is not None
if not asyncio.run(self._env.deployment.is_alive(timeout=10)):
@@ -767,7 +767,7 @@ class DefaultAgent(AbstractAgent):
Returns:
step: step with submission and observation updated (if submission was found)
"""
- step = step.model_copy()
+ step = step.model_copy(deep=True)
assert self.tools is not None
is_submission = self.tools.check_for_submission_cmd(observation or step.observation)
if is_submission or force_submission:
diff --git a/sweagent/run/batch_instances.py b/sweagent/run/batch_instances.py
index 82741e5b..57e1dcec 100644
--- a/sweagent/run/batch_instances.py
+++ b/sweagent/run/batch_instances.py
@@ -104,7 +104,7 @@ class SimpleBatchInstance(BaseModel):
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()
+ deployment = deployment.model_copy(deep=True)
problem_statement = TextProblemStatement(
text=self.problem_statement, id=self.id, extra_fields=self.extra_fields
)