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: No retries if costs cannot be calculated (#990)
Kilian Lieret09e0e8c4a475
diff --git a/sweagent/agent/models.py b/sweagent/agent/models.pyindex 593b1ab1..aa0bcd03 100644--- a/sweagent/agent/models.py+++ b/sweagent/agent/models.py@@ -32,6 +32,7 @@ from sweagent.exceptions import (FunctionCallingFormatError,InstanceCallLimitExceededError,InstanceCostLimitExceededError,+ ModelConfigurationError,TotalCostLimitExceededError,)from sweagent.tools.tools import ToolConfig@@ -549,7 +550,7 @@ class LiteLLMModel(AbstractModel):" does not support function calling, you can use `parse_function='thought_action'` instead. ""See https://swe-agent.com/latest/faq/ for more information.")- raise ValueError(msg)+ raise ModelConfigurationError(msg)self.model_max_input_tokens = litellm.model_cost.get(self.config.name, {}).get("max_input_tokens")self.model_max_output_tokens = litellm.model_cost.get(self.config.name, {}).get("max_output_tokens")self.lm_provider = litellm.model_cost.get(self.config.name, {}).get("litellm_provider")@@ -659,7 +660,8 @@ class LiteLLMModel(AbstractModel):"(local models, etc.), please make sure you set `per_instance_cost_limit` and ""`total_cost_limit` to 0 to disable this safety check.")- raise ValueError(msg)+ self.logger.error(msg)+ raise ModelConfigurationError(msg)cost = 0choices: litellm.types.utils.Choices = response.choices # type: ignoren_choices = n if n is not None else 1@@ -710,6 +712,7 @@ class LiteLLMModel(AbstractModel):TypeError,litellm.exceptions.AuthenticationError,ContentPolicyViolationError,+ ModelConfigurationError,)),):diff --git a/sweagent/exceptions.py b/sweagent/exceptions.pyindex 782e79ca..1df920bf 100644--- a/sweagent/exceptions.py+++ b/sweagent/exceptions.py@@ -46,3 +46,9 @@ class InstanceCallLimitExceededError(CostLimitExceededError):class ContentPolicyViolationError(Exception):"""Raised when the model response violates a content policy"""+++class ModelConfigurationError(Exception):+ """Raised when the model configuration is invalid/no further retries+ should be made.+ """diff --git a/sweagent/run/run_batch.py b/sweagent/run/run_batch.pyindex d95ba672..fa5409f7 100644--- a/sweagent/run/run_batch.py+++ b/sweagent/run/run_batch.py@@ -51,6 +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 ModelConfigurationErrorfrom sweagent.run._progress import RunBatchProgressManagerfrom sweagent.run.batch_instances import BatchInstance, BatchInstanceSourceConfig, SWEBenchInstancesfrom sweagent.run.common import BasicCLI, ConfigHelper, save_predictions@@ -303,10 +304,10 @@ class RunBatch:result = self._run_instance(instance)except KeyboardInterrupt:raise _BreakLoop- except SystemExit:+ except (SystemExit, ModelConfigurationError) as e:if self._raise_exceptions:raise- self.logger.critical("❌ Exiting because SystemExit was called")+ self.logger.critical(f"❌ Exiting because {e.__class__.__name__} was called")raise _BreakLoopexcept Exception as e:self.logger.error(traceback.format_exc())