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]

Increase number of retries when querying model (#629)

Kilian Lierete0d43659d8ce
diff --git a/docs/config/env.md b/docs/config/env.md
index f4e0cc80..2663896d 100644
--- a/docs/config/env.md
+++ b/docs/config/env.md
@@ -9,6 +9,7 @@ This page details all environment variables that are currently in use by SWE-age
* All API keys (for LMs and GitHub) can be set as an environment variable. See [here](../installation/keys.md) for more information.
* `SWE_AGENT_CONFIG_ROOT`: Used to resolve relative paths in the [config](config.md)
* `SWE_AGENT_ENV_LONG_TIMEOUT` (default: 500): Timeout in seconds used for commands that install instance environment.
+* `SWE_AGENT_MODEL_MAX_RETRIES` (default: 10): Maximum retries when querying the model
The following three variables can only be set as environment variables, not in the config file
diff --git a/sweagent/agent/models.py b/sweagent/agent/models.py
index ae00a141..307b0ffb 100644
--- a/sweagent/agent/models.py
+++ b/sweagent/agent/models.py
@@ -24,6 +24,8 @@ from sweagent.utils.log import get_logger
logger = get_logger("api_models")
+_MAX_RETRIES = keys_config.get("SWE_AGENT_MODEL_MAX_RETRIES", 10)
+
@dataclass(frozen=True)
class ModelArguments(FrozenSerializable):
@@ -277,7 +279,7 @@ class OpenAIModel(BaseModel):
@retry(
wait=wait_random_exponential(min=1, max=15),
reraise=True,
- stop=stop_after_attempt(3),
+ stop=stop_after_attempt(_MAX_RETRIES),
retry=retry_if_not_exception_type((CostLimitExceededError, RuntimeError)),
)
def query(self, history: list[dict[str, str]]) -> str:
@@ -373,7 +375,7 @@ class AnthropicModel(BaseModel):
@retry(
wait=wait_random_exponential(min=1, max=15),
reraise=True,
- stop=stop_after_attempt(3),
+ stop=stop_after_attempt(_MAX_RETRIES),
retry=retry_if_not_exception_type((CostLimitExceededError, RuntimeError)),
)
def query(self, history: list[dict[str, str]]) -> str:
@@ -457,7 +459,7 @@ class BedrockModel(BaseModel):
@retry(
wait=wait_random_exponential(min=1, max=15),
reraise=True,
- stop=stop_after_attempt(3),
+ stop=stop_after_attempt(_MAX_RETRIES),
retry=retry_if_not_exception_type((CostLimitExceededError, RuntimeError)),
)
def query(self, history: list[dict[str, str]]) -> str:
@@ -609,7 +611,7 @@ class OllamaModel(BaseModel):
@retry(
wait=wait_random_exponential(min=1, max=15),
reraise=True,
- stop=stop_after_attempt(3),
+ stop=stop_after_attempt(_MAX_RETRIES),
retry=retry_if_not_exception_type((CostLimitExceededError, RuntimeError)),
)
def query(self, history: list[dict[str, str]]) -> str:
@@ -702,7 +704,7 @@ class TogetherModel(BaseModel):
@retry(
wait=wait_random_exponential(min=1, max=15),
reraise=True,
- stop=stop_after_attempt(3),
+ stop=stop_after_attempt(_MAX_RETRIES),
retry=retry_if_not_exception_type((CostLimitExceededError, RuntimeError)),
)
def query(self, history: list[dict[str, str]]) -> str: