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: Handle total cost limit exceeded (#994)
Kilian Lieret2755c28bd149
diff --git a/sweagent/agent/agents.py b/sweagent/agent/agents.pyindex 3d9f3e0c..0672fd78 100644--- a/sweagent/agent/agents.py+++ b/sweagent/agent/agents.py@@ -43,6 +43,7 @@ from sweagent.exceptions import (ContextWindowExceededError,CostLimitExceededError,FormatError,+ TotalCostLimitExceededError,)from sweagent.tools.parsing import (ActionOnlyParser,@@ -296,6 +297,9 @@ class RetryAgent(AbstractAgent):return self._agent.attempt_autosubmission_after_error(step=StepOutput())try:step = self._agent.step()+ except TotalCostLimitExceededError:+ # Need to make sure that this error causes everything to stop+ raiseexcept Exception as e:msg = "Error in agent step: %s. This really shouldn't happen, please report this. Triggering autosubmit."self.logger.critical(msg, e, exc_info=True)@@ -320,6 +324,8 @@ class RetryAgent(AbstractAgent):if choose:try:best_attempt_idx = self._rloop.get_best()+ except TotalCostLimitExceededError:+ raiseexcept Exception as e:self.logger.critical(f"Error getting best attempt index: {e}. Setting to 0.", exc_info=True)best_attempt_idx = 0@@ -1099,6 +1105,8 @@ class DefaultAgent(AbstractAgent):"exit_context","Exit due to context window",)+ except TotalCostLimitExceededError:+ raiseexcept CostLimitExceededError:return handle_error_with_autosubmission("exit_cost",diff --git a/sweagent/run/run_batch.py b/sweagent/run/run_batch.pyindex fa5409f7..302c4706 100644--- a/sweagent/run/run_batch.py+++ b/sweagent/run/run_batch.py@@ -51,7 +51,7 @@ from sweagent.agent.agents import AgentConfig, get_agent_from_configfrom sweagent.agent.hooks.status import SetStatusAgentHookfrom sweagent.environment.hooks.status import SetStatusEnvironmentHookfrom sweagent.environment.swe_env import SWEEnv-from sweagent.exceptions import ModelConfigurationError+from sweagent.exceptions import ModelConfigurationError, TotalCostLimitExceededErrorfrom sweagent.run._progress import RunBatchProgressManagerfrom sweagent.run.batch_instances import BatchInstance, BatchInstanceSourceConfig, SWEBenchInstancesfrom sweagent.run.common import BasicCLI, ConfigHelper, save_predictions@@ -304,7 +304,7 @@ class RunBatch:result = self._run_instance(instance)except KeyboardInterrupt:raise _BreakLoop- except (SystemExit, ModelConfigurationError) as e:+ except (SystemExit, ModelConfigurationError, TotalCostLimitExceededError) as e:if self._raise_exceptions:raiseself.logger.critical(f"❌ Exiting because {e.__class__.__name__} was called")@@ -347,9 +347,9 @@ class RunBatch:env.deployment.add_hook(SetStatusDeploymentHook(instance.problem_statement.id, self._progress_manager.update_instance_status))- env.start()- self._chooks.on_instance_start(index=0, env=env, problem_statement=instance.problem_statement)try:+ env.start()+ self._chooks.on_instance_start(index=0, env=env, problem_statement=instance.problem_statement)result = agent.run(problem_statement=instance.problem_statement,env=env,